* query params from router as computed * chore: setup workspace store and sub-stores * chore: update router query store * chore: update store types * fix: pages store changes * change observables and retain object reference * fix build errors * chore: changed the structure of workspace, project, cycle, module and pages * fix: pages fixes * fix: merge conflicts resolved * chore: fixed workspace list * chore: update workspace store accroding to the new response * fix: adding page details to store * fix: adding new contexts and providers * dev: issues store and filters in new store * dev: optimised the issue fetching in issue base store * chore: project views id mapped * update lodash set to directly run inside runInaction since it mutates the object * fix: context changes * code refactor kanban for better mainatinability * optimize Kanban for performance * chore: implemented hooks for all the created stores * chore: removed bridge id * css change and refactor * chore: update cycle store structure * chore: implement the new label root store * chore: removed object structure * chore: implement project view hook * Kanban new store implementation for project issues * fix project root for kanban * feat: workspace and project members endpoint (#3092) * fix: merge conflicts resolved * issue properties optimization * chore: user stores * chore: create new store context and update hooks * chore: setup inbox store and implement router store * chore: initialize and implement project estimate store * chore: initialize global view store * kanban and list view optimization * chore: use new cycle and module store. (#3172) * chore: use new cycle and module store. * chore: minor improvements. * Revert "chore: merge develop" This reverts commit 9d2e0e29e7370b55b48fc2fee4fd126093a6cc48, reversing changes made to 9595493c42be3ea0ddd17b23a0b124555075c062. * chore: implement useGlobalView hook * refactor: projects & inbox store instances (#3179) * refactor: projects & inbox store instances * fix: formatting * fix: action usage * chore: implement useProjectState hook. (#3185) * dev: issue, cycle store optimiation * fix build for code * dev: removed dummy variables * dev: issue store * fix: adding todos * chore: removing legacy store * dev: issues store types and typos * chore: cycle module user properties * fix legacy store deletion issues * chore: change POST to PATCH * fix issues rendering for project root * chore: removed workspace details in workpsaceinvite * chore: created models for display properties * chore: setup member store and implement it everywhere * refactor: module store (#3202) * refactor: cycle store (#3192) * refator: cycle store * some more improvements. * chore: implement useLabel hook. (#3190) * refactor: inbox & project related stores. (#3193) * refactor: inbox -> filter, issues, inoxes & project -> publish, projects store * refactor: workspace-project-id name * fix kanban dropdown overlapping issue * fix kanban layout minor re rendering * chore: implement useMember store everywhere * chore: create and implement editor mention store * chore: removed the issue view user property * chore: created at id changed * dev: segway intgegration (#3132) * feat: implemented rabbitmq * dev: initialize segway with queue setup * dev: import refactors * dev: create communication with the segway server * dev: create new workers * dev: create celery node queue for consuming messages from django * dev: node to celery connection * dev: setup segway and django connection * dev: refactor the structure and add database integration to the app * dev: add external id and source added --------- Co-authored-by: NarayanBavisetti <narayan3119@gmail.com> * dev: github importer (#3205) * dev: initiate github import * dev: github importer all issues import * dev: github comments and links for the imported issues * dev: update controller to use logger and spread the resultData in getAllEntities * dev: removed console log * dev: update code structure and sync functions * dev: updated retry logic when exception * dev: add imported data as well * dev: update logger and repo fetch * dev: update jira integration to new structure * dev: update migrations * dev: update the reason field * chore: workspace object id removed * chore: view's creation fixed * refactor: mobx store improvements. (#3213) * fix: state and label errors * chore: remove legacy code * fix: branch build fix (#3214) * branch build fix for release-* in case of space,backend,proxy * fixes * chore: update store names and types * fix - file size limit not work on plane.settings.production (#3160) * fix - file size limit not work on plane.settings.production * fix - file size limit not work on plane.settings.production * fix - file size limit not work on plane.settings.production, move to common.py --------- Co-authored-by: luanduongtel4vn <hoangluan@tel4vn.com> Co-authored-by: sriram veeraghanta <veeraghanta.sriram@gmail.com> * style: instance admin email settings ui & ux update. (#3186) * refactor: use-user-auth hook (#3215) * refactor: use-user-auth hook * fix: user store currentUserLoader * refactor: project-view & application related stores (#3207) * refactor: project-view & application related stores * rename: projectViews -> projectViewIds * fix: project-view favourite state in store * chore: remove unnecessary hooks and contexts (#3217) * chore: update issue assignee property component * chore: bug fixes & improvement (#3218) * chore: draft issue validation added to prevent saving empty or whitespace title * chore: resolve scrolling issue in page empty state * chore: kanban layout quick add issue improvement * fix: bugs & improvements (#3189) * fix: workspace invitation modal form values reset * fix: profile sidebar avatar letter * [refactor] Editor code refactoring (#3194) * removed relative imports from editor core * Update issue widget file paths and imports to use kebab case instead of camel case, to align with coding conventions and improve consistency. * Update Tiptap core and extensions versions to 2.1.13 and Tiptap React version to 2.1.13. Update Tiptap table imports to use the new location in package @tiptap/pm/tables. Update AlertLabel component to use the new type definition for LucideIcon. * updated lock file * removed default exports from editor/core * fixed injecting css into the core package itself * seperated css code to have single source of origin wrt to the package * removed default imports from document editor * all instances using index as key while mapping fixed * Update Lite Text Editor package.json to remove @plane/editor-types as a dependency. Update Lite Text Editor index.ts to update the import of IMentionSuggestion and IMentionHighlight from @plane/editor-types to @plane/editor-core. Update Lite Text Editor ui/index.tsx to update the import of UploadImage, DeleteImage, IMentionSuggestion, and RestoreImage from @plane/editor-types to @plane/editor-core. Update Lite Text Editor ui/menus/fixed-menu/index.tsx to update the import of UploadImage from @plane/editor-types to @plane/editor-core. Update turbo.json to remove @plane/editor-types#build as a dependency for @plane/lite-text-editor#build, @plane/rich-text-editor#build, and @plane/document-editor#build. * Remove deprecated import and adjust tippy.js usage in the slash-commands.tsx file of the editor extensions package. * Update dependencies in `rich-text-editor/package.json`, remove `@plane/editor-types` and add `@plane/editor-core` in `rich-text-editor/src/index.ts`, and update imports in `rich-text-editor/src/ui/extensions/index.tsx` and `rich-text-editor/src/ui/index.tsx` to use `@plane/editor-core` instead of `@plane/editor-types`. * Update package.json dependencies and add new types for image deletion, upload, restore, mention highlight, mention suggestion, and slash command item. * Update import statements in various files to use the new package "@plane/editor-core" instead of "@plane/editor-types". * fixed document editor to follow conventions * Refactor imports in the Rich Text Editor package to use relative paths instead of absolute paths. - Updated imports in `index.ts`, `ui/index.tsx`, and `ui/menus/bubble-menu/index.tsx` to use relative paths. - Updated `tsconfig.json` to include the `baseUrl` compiler option and adjust the `include` and `exclude` paths. * Refactor Lite Text Editor code to use relative import paths instead of absolute import paths. * Added LucideIconType to the exports in index.ts for use in other files. Created a new file lucide-icon.ts which contains the type LucideIconType. Updated the icon type in HeadingOneItem in menu-items/index.tsx to use LucideIconType. Updated the Icon type in AlertLabel in alert-label.tsx to use LucideIconType. Updated the Icon type in VerticalDropdownItemProps in vertical-dropdown-menu.tsx to use LucideIconType. Updated the Icon type in BubbleMenuItem in fixed-menu/index.tsx to use LucideIconType. Deleted the file tooltip.tsx since it is no longer used. Updated the Icon type in BubbleMenuItem in bubble-menu/index.tsx to use LucideIconType. * ♻️ refactor: simplify rendering logic in slash-commands.tsx The rendering logic in the file "slash-commands.tsx" has been simplified. Previously, the code used inline positioning for the popup, but it has now been removed. Instead of appending the popup to the document body, it is now appended to the element with the ID "tiptap-container". The "flip" option has also been removed. These changes have improved the readability and maintainability of the code. * fixed build errors caused due to core's internal imports * regression: fixed pages not saving issue and not duplicating with proper content issue * build: Update @tiptap dependencies Updated the @tiptap dependencies in the package.json files of `document-editor`, `extensions`, and `rich-text-editor` packages to version 2.1.13. * 🚑 fix: Correct appendTo selector in slash-commands.tsx Update the `appendTo` function call in `slash-commands.tsx` to use the correct selector `#editor-container` instead of `#tiptap-container`. This ensures that the component is appended to the appropriate container in the editor extension. Note: The commit message assumes that the change is a fix for an issue or error. If it's not a fix, please provide more context so that an appropriate commit type can be determined. * style: email placeholder changed across the platform (#3206) * style: email placeholder changed across the platform * fix: placeholder text * dev: updated new filter endpoints and restructured issue and issue filters store * implement issues and replace useMobxStore * remove all store legacy references * dev: updated the orderby and subgroupby filters data * dev:added projectId in issue filters for consistency * fix more build errors * dev: updated profile issues * dev: removed store legacy * dev: active cycle issues in the cycle issue store * fix additional build errors and memoize issueActions in each layout component * change store enums * remove all useMobxStore references * fix more build errors * dev: reverted workspace invitation * fix: build errors and warnings * fix: optimistic update for instant operations (#3221) * fix: update functions failed case * fix: typo * chore: revert back to optimistic update approach for all `update related actions` (#3219) * fix: merge conflicts resolved * chore: update memberMap logic in components * add assignees to kanban groups and properties * dev: migration fixes * final bit of optimization on list view * change all TODOs that are to be done before this release to FIXME * change base Kanban TODOs that are to be done before this release to FIXME * dev: add fields and expand for app serializers * dev: issue detail store * dev: update issue serializer to return object ids * fix: Instance key added in settings and converted issues list api to arry instead of dict * fix: removing segway files * dev: control expand through query parameters * revert: github importer * Revert "dev: segway intgegration (#3132)" This reverts commit 1cc18a09156d1790d114061dbac8c901e0f2754c. * dev: remove migrations for segway * dev: issue structure change and created workspacebasemodel * dev: issue detail serializer * fix: changed workspace dict * dev: updated new issue structure * chore: build fix * dev: issue detail store refactor * dev: created list endpoint for issue-relation * dev: added issue attachments in issue detail store * dev: added issue activity computed * fix: build error * chore: peek overview modal context added * chore: build error fix * dev: added sub_issues in issue details store * dev: added complete issue serializer for sub issues * dev: resolved type errors in issue root store * dev: changed the issue relation structure * chore: new global dropdowns * chore: build error fix * chore: cycle and module selection if disabled * dev: removed unnecessary code from the workspace root * chore: build error fix * chore: issue relation remove endpoint * fix: build error * dev: typos and implemented issue relation store * fix: yarn lock updated * style: update the UI of all the dropdowns * fix: state store fixes * fix: key issue * fix: state store console logs removed * refactor: member dropdowns * fix: moving types to packages * fix: dropdown arrow positioning * dev: removed logs * style: label dropdown * chore: restrict description notifications * chore: description changes * chore: update spreadsheet layout dropdowns * fix: build errors * chore: duplicate key change * fix: ui bugs * chore: relation activity change * chore: comment activity changes * chore: blocking issue removal * chore: added project_id for relation * chore: issue relation store and component * chore: issue redirection issue in the issue realtion in detail page * chore: created activity changed * chore: issue links new store implementation on the issue detail * chore: issue relation deletion acitivity changed * chore: issue attachments new store implementation on the issue detail * chore: workspace level issues * fix: build errors --------- Co-authored-by: rahulramesha <rahulramesham@gmail.com> Co-authored-by: gurusainath <gurusainath007@gmail.com> Co-authored-by: sriram veeraghanta <veeraghanta.sriram@gmail.com> Co-authored-by: NarayanBavisetti <narayan3119@gmail.com> Co-authored-by: Bavisetti Narayan <72156168+NarayanBavisetti@users.noreply.github.com> Co-authored-by: Prateek Shourya <prateekshourya29@gmail.com> Co-authored-by: Lakhan Baheti <94619783+1akhanBaheti@users.noreply.github.com> Co-authored-by: Nikhil <118773738+pablohashescobar@users.noreply.github.com> Co-authored-by: Manish Gupta <59428681+mguptahub@users.noreply.github.com> Co-authored-by: Hoang Luan <luandnh98@gmail.com> Co-authored-by: luanduongtel4vn <hoangluan@tel4vn.com> Co-authored-by: Anmol Singh Bhatia <121005188+anmolsinghbhatia@users.noreply.github.com> Co-authored-by: M. Palanikannan <73993394+Palanikannan1437@users.noreply.github.com> Co-authored-by: pablohashescobar <nikhilschacko@gmail.com> Co-authored-by: Anmol Singh Bhatia <anmolsinghbhatia@plane.so>
1586 lines
48 KiB
Python
1586 lines
48 KiB
Python
# Python imports
|
|
import json
|
|
import requests
|
|
|
|
# Django imports
|
|
from django.conf import settings
|
|
from django.core.serializers.json import DjangoJSONEncoder
|
|
from django.utils import timezone
|
|
|
|
# Third Party imports
|
|
from celery import shared_task
|
|
from sentry_sdk import capture_exception
|
|
|
|
# Module imports
|
|
from plane.db.models import (
|
|
User,
|
|
Issue,
|
|
Project,
|
|
Label,
|
|
IssueActivity,
|
|
State,
|
|
Cycle,
|
|
Module,
|
|
IssueReaction,
|
|
CommentReaction,
|
|
IssueComment,
|
|
)
|
|
from plane.app.serializers import IssueActivitySerializer
|
|
from plane.bgtasks.notification_task import notifications
|
|
|
|
|
|
# Track Changes in name
|
|
def track_name(
|
|
requested_data,
|
|
current_instance,
|
|
issue_id,
|
|
project_id,
|
|
workspace_id,
|
|
actor_id,
|
|
issue_activities,
|
|
epoch,
|
|
):
|
|
if current_instance.get("name") != requested_data.get("name"):
|
|
issue_activities.append(
|
|
IssueActivity(
|
|
issue_id=issue_id,
|
|
actor_id=actor_id,
|
|
verb="updated",
|
|
old_value=current_instance.get("name"),
|
|
new_value=requested_data.get("name"),
|
|
field="name",
|
|
project_id=project_id,
|
|
workspace_id=workspace_id,
|
|
comment=f"updated the name to",
|
|
epoch=epoch,
|
|
)
|
|
)
|
|
|
|
|
|
# Track issue description
|
|
def track_description(
|
|
requested_data,
|
|
current_instance,
|
|
issue_id,
|
|
project_id,
|
|
workspace_id,
|
|
actor_id,
|
|
issue_activities,
|
|
epoch,
|
|
):
|
|
if current_instance.get("description_html") != requested_data.get(
|
|
"description_html"
|
|
):
|
|
last_activity = (
|
|
IssueActivity.objects.filter(issue_id=issue_id)
|
|
.order_by("-created_at")
|
|
.first()
|
|
)
|
|
if (
|
|
last_activity is not None
|
|
and last_activity.field == "description"
|
|
and actor_id == str(last_activity.actor_id)
|
|
):
|
|
last_activity.created_at = timezone.now()
|
|
last_activity.save(update_fields=["created_at"])
|
|
else:
|
|
issue_activities.append(
|
|
IssueActivity(
|
|
issue_id=issue_id,
|
|
actor_id=actor_id,
|
|
verb="updated",
|
|
old_value=current_instance.get("description_html"),
|
|
new_value=requested_data.get("description_html"),
|
|
field="description",
|
|
project_id=project_id,
|
|
workspace_id=workspace_id,
|
|
comment=f"updated the description to",
|
|
epoch=epoch,
|
|
)
|
|
)
|
|
|
|
|
|
# Track changes in parent issue
|
|
def track_parent(
|
|
requested_data,
|
|
current_instance,
|
|
issue_id,
|
|
project_id,
|
|
workspace_id,
|
|
actor_id,
|
|
issue_activities,
|
|
epoch,
|
|
):
|
|
if current_instance.get("parent") != requested_data.get("parent"):
|
|
old_parent = (
|
|
Issue.objects.filter(pk=current_instance.get("parent")).first()
|
|
if current_instance.get("parent") is not None
|
|
else None
|
|
)
|
|
new_parent = (
|
|
Issue.objects.filter(pk=requested_data.get("parent")).first()
|
|
if requested_data.get("parent") is not None
|
|
else None
|
|
)
|
|
|
|
issue_activities.append(
|
|
IssueActivity(
|
|
issue_id=issue_id,
|
|
actor_id=actor_id,
|
|
verb="updated",
|
|
old_value=f"{old_parent.project.identifier}-{old_parent.sequence_id}"
|
|
if old_parent is not None
|
|
else "",
|
|
new_value=f"{new_parent.project.identifier}-{new_parent.sequence_id}"
|
|
if new_parent is not None
|
|
else "",
|
|
field="parent",
|
|
project_id=project_id,
|
|
workspace_id=workspace_id,
|
|
comment=f"updated the parent issue to",
|
|
old_identifier=old_parent.id if old_parent is not None else None,
|
|
new_identifier=new_parent.id if new_parent is not None else None,
|
|
epoch=epoch,
|
|
)
|
|
)
|
|
|
|
|
|
# Track changes in priority
|
|
def track_priority(
|
|
requested_data,
|
|
current_instance,
|
|
issue_id,
|
|
project_id,
|
|
workspace_id,
|
|
actor_id,
|
|
issue_activities,
|
|
epoch,
|
|
):
|
|
if current_instance.get("priority") != requested_data.get("priority"):
|
|
issue_activities.append(
|
|
IssueActivity(
|
|
issue_id=issue_id,
|
|
actor_id=actor_id,
|
|
verb="updated",
|
|
old_value=current_instance.get("priority"),
|
|
new_value=requested_data.get("priority"),
|
|
field="priority",
|
|
project_id=project_id,
|
|
workspace_id=workspace_id,
|
|
comment=f"updated the priority to",
|
|
epoch=epoch,
|
|
)
|
|
)
|
|
|
|
|
|
# Track changes in state of the issue
|
|
def track_state(
|
|
requested_data,
|
|
current_instance,
|
|
issue_id,
|
|
project_id,
|
|
workspace_id,
|
|
actor_id,
|
|
issue_activities,
|
|
epoch,
|
|
):
|
|
if current_instance.get("state") != requested_data.get("state"):
|
|
new_state = State.objects.get(pk=requested_data.get("state", None))
|
|
old_state = State.objects.get(pk=current_instance.get("state", None))
|
|
|
|
issue_activities.append(
|
|
IssueActivity(
|
|
issue_id=issue_id,
|
|
actor_id=actor_id,
|
|
verb="updated",
|
|
old_value=old_state.name,
|
|
new_value=new_state.name,
|
|
field="state",
|
|
project_id=project_id,
|
|
workspace_id=workspace_id,
|
|
comment=f"updated the state to",
|
|
old_identifier=old_state.id,
|
|
new_identifier=new_state.id,
|
|
epoch=epoch,
|
|
)
|
|
)
|
|
|
|
|
|
# Track changes in issue target date
|
|
def track_target_date(
|
|
requested_data,
|
|
current_instance,
|
|
issue_id,
|
|
project_id,
|
|
workspace_id,
|
|
actor_id,
|
|
issue_activities,
|
|
epoch,
|
|
):
|
|
if current_instance.get("target_date") != requested_data.get("target_date"):
|
|
issue_activities.append(
|
|
IssueActivity(
|
|
issue_id=issue_id,
|
|
actor_id=actor_id,
|
|
verb="updated",
|
|
old_value=current_instance.get("target_date")
|
|
if current_instance.get("target_date") is not None
|
|
else "",
|
|
new_value=requested_data.get("target_date")
|
|
if requested_data.get("target_date") is not None
|
|
else "",
|
|
field="target_date",
|
|
project_id=project_id,
|
|
workspace_id=workspace_id,
|
|
comment=f"updated the target date to",
|
|
epoch=epoch,
|
|
)
|
|
)
|
|
|
|
|
|
# Track changes in issue start date
|
|
def track_start_date(
|
|
requested_data,
|
|
current_instance,
|
|
issue_id,
|
|
project_id,
|
|
workspace_id,
|
|
actor_id,
|
|
issue_activities,
|
|
epoch,
|
|
):
|
|
if current_instance.get("start_date") != requested_data.get("start_date"):
|
|
issue_activities.append(
|
|
IssueActivity(
|
|
issue_id=issue_id,
|
|
actor_id=actor_id,
|
|
verb="updated",
|
|
old_value=current_instance.get("start_date")
|
|
if current_instance.get("start_date") is not None
|
|
else "",
|
|
new_value=requested_data.get("start_date")
|
|
if requested_data.get("start_date") is not None
|
|
else "",
|
|
field="start_date",
|
|
project_id=project_id,
|
|
workspace_id=workspace_id,
|
|
comment=f"updated the start date to ",
|
|
epoch=epoch,
|
|
)
|
|
)
|
|
|
|
|
|
# Track changes in issue labels
|
|
def track_labels(
|
|
requested_data,
|
|
current_instance,
|
|
issue_id,
|
|
project_id,
|
|
workspace_id,
|
|
actor_id,
|
|
issue_activities,
|
|
epoch,
|
|
):
|
|
requested_labels = set([str(lab) for lab in requested_data.get("labels", [])])
|
|
current_labels = set([str(lab) for lab in current_instance.get("labels", [])])
|
|
|
|
added_labels = requested_labels - current_labels
|
|
dropped_labels = current_labels - requested_labels
|
|
|
|
# Set of newly added labels
|
|
for added_label in added_labels:
|
|
label = Label.objects.get(pk=added_label)
|
|
issue_activities.append(
|
|
IssueActivity(
|
|
issue_id=issue_id,
|
|
actor_id=actor_id,
|
|
project_id=project_id,
|
|
workspace_id=workspace_id,
|
|
verb="updated",
|
|
field="labels",
|
|
comment="added label ",
|
|
old_value="",
|
|
new_value=label.name,
|
|
new_identifier=label.id,
|
|
old_identifier=None,
|
|
epoch=epoch,
|
|
)
|
|
)
|
|
|
|
# Set of dropped labels
|
|
for dropped_label in dropped_labels:
|
|
label = Label.objects.get(pk=dropped_label)
|
|
issue_activities.append(
|
|
IssueActivity(
|
|
issue_id=issue_id,
|
|
actor_id=actor_id,
|
|
verb="updated",
|
|
old_value=label.name,
|
|
new_value="",
|
|
field="labels",
|
|
project_id=project_id,
|
|
workspace_id=workspace_id,
|
|
comment=f"removed label ",
|
|
old_identifier=label.id,
|
|
new_identifier=None,
|
|
epoch=epoch,
|
|
)
|
|
)
|
|
|
|
|
|
# Track changes in issue assignees
|
|
def track_assignees(
|
|
requested_data,
|
|
current_instance,
|
|
issue_id,
|
|
project_id,
|
|
workspace_id,
|
|
actor_id,
|
|
issue_activities,
|
|
epoch,
|
|
):
|
|
requested_assignees = set([str(asg) for asg in requested_data.get("assignees", [])])
|
|
current_assignees = set([str(asg) for asg in current_instance.get("assignees", [])])
|
|
|
|
added_assignees = requested_assignees - current_assignees
|
|
dropped_assginees = current_assignees - requested_assignees
|
|
|
|
for added_asignee in added_assignees:
|
|
assignee = User.objects.get(pk=added_asignee)
|
|
issue_activities.append(
|
|
IssueActivity(
|
|
issue_id=issue_id,
|
|
actor_id=actor_id,
|
|
verb="updated",
|
|
old_value="",
|
|
new_value=assignee.display_name,
|
|
field="assignees",
|
|
project_id=project_id,
|
|
workspace_id=workspace_id,
|
|
comment=f"added assignee ",
|
|
new_identifier=assignee.id,
|
|
epoch=epoch,
|
|
)
|
|
)
|
|
|
|
for dropped_assignee in dropped_assginees:
|
|
assignee = User.objects.get(pk=dropped_assignee)
|
|
issue_activities.append(
|
|
IssueActivity(
|
|
issue_id=issue_id,
|
|
actor_id=actor_id,
|
|
verb="updated",
|
|
old_value=assignee.display_name,
|
|
new_value="",
|
|
field="assignees",
|
|
project_id=project_id,
|
|
workspace_id=workspace_id,
|
|
comment=f"removed assignee ",
|
|
old_identifier=assignee.id,
|
|
epoch=epoch,
|
|
)
|
|
)
|
|
|
|
|
|
def track_estimate_points(
|
|
requested_data,
|
|
current_instance,
|
|
issue_id,
|
|
project_id,
|
|
workspace_id,
|
|
actor_id,
|
|
issue_activities,
|
|
epoch,
|
|
):
|
|
if current_instance.get("estimate_point") != requested_data.get("estimate_point"):
|
|
issue_activities.append(
|
|
IssueActivity(
|
|
issue_id=issue_id,
|
|
actor_id=actor_id,
|
|
verb="updated",
|
|
old_value=current_instance.get("estimate_point")
|
|
if current_instance.get("estimate_point") is not None
|
|
else "",
|
|
new_value=requested_data.get("estimate_point")
|
|
if requested_data.get("estimate_point") is not None
|
|
else "",
|
|
field="estimate_point",
|
|
project_id=project_id,
|
|
workspace_id=workspace_id,
|
|
comment=f"updated the estimate point to ",
|
|
epoch=epoch,
|
|
)
|
|
)
|
|
|
|
|
|
def track_archive_at(
|
|
requested_data,
|
|
current_instance,
|
|
issue_id,
|
|
project_id,
|
|
workspace_id,
|
|
actor_id,
|
|
issue_activities,
|
|
epoch,
|
|
):
|
|
if current_instance.get("archived_at") != requested_data.get("archived_at"):
|
|
if requested_data.get("archived_at") is None:
|
|
issue_activities.append(
|
|
IssueActivity(
|
|
issue_id=issue_id,
|
|
project_id=project_id,
|
|
workspace_id=workspace_id,
|
|
comment="has restored the issue",
|
|
verb="updated",
|
|
actor_id=actor_id,
|
|
field="archived_at",
|
|
old_value="archive",
|
|
new_value="restore",
|
|
epoch=epoch,
|
|
)
|
|
)
|
|
else:
|
|
issue_activities.append(
|
|
IssueActivity(
|
|
issue_id=issue_id,
|
|
project_id=project_id,
|
|
workspace_id=workspace_id,
|
|
comment="Plane has archived the issue",
|
|
verb="updated",
|
|
actor_id=actor_id,
|
|
field="archived_at",
|
|
old_value=None,
|
|
new_value="archive",
|
|
epoch=epoch,
|
|
)
|
|
)
|
|
|
|
|
|
def track_closed_to(
|
|
requested_data,
|
|
current_instance,
|
|
issue_id,
|
|
project_id,
|
|
workspace_id,
|
|
actor_id,
|
|
issue_activities,
|
|
epoch,
|
|
):
|
|
if requested_data.get("closed_to") is not None:
|
|
updated_state = State.objects.get(
|
|
pk=requested_data.get("closed_to"), project_id=project_id
|
|
)
|
|
issue_activities.append(
|
|
IssueActivity(
|
|
issue_id=issue_id,
|
|
actor_id=actor_id,
|
|
verb="updated",
|
|
old_value=None,
|
|
new_value=updated_state.name,
|
|
field="state",
|
|
project_id=project_id,
|
|
workspace_id=workspace_id,
|
|
comment=f"Plane updated the state to ",
|
|
old_identifier=None,
|
|
new_identifier=updated_state.id,
|
|
epoch=epoch,
|
|
)
|
|
)
|
|
|
|
|
|
def create_issue_activity(
|
|
requested_data,
|
|
current_instance,
|
|
issue_id,
|
|
project_id,
|
|
workspace_id,
|
|
actor_id,
|
|
issue_activities,
|
|
epoch,
|
|
):
|
|
issue_activities.append(
|
|
IssueActivity(
|
|
issue_id=issue_id,
|
|
project_id=project_id,
|
|
workspace_id=workspace_id,
|
|
comment=f"created the issue",
|
|
verb="created",
|
|
actor_id=actor_id,
|
|
epoch=epoch,
|
|
)
|
|
)
|
|
|
|
|
|
def update_issue_activity(
|
|
requested_data,
|
|
current_instance,
|
|
issue_id,
|
|
project_id,
|
|
workspace_id,
|
|
actor_id,
|
|
issue_activities,
|
|
epoch,
|
|
):
|
|
ISSUE_ACTIVITY_MAPPER = {
|
|
"name": track_name,
|
|
"parent": track_parent,
|
|
"priority": track_priority,
|
|
"state": track_state,
|
|
"description_html": track_description,
|
|
"target_date": track_target_date,
|
|
"start_date": track_start_date,
|
|
"labels": track_labels,
|
|
"assignees": track_assignees,
|
|
"estimate_point": track_estimate_points,
|
|
"archived_at": track_archive_at,
|
|
"closed_to": track_closed_to,
|
|
}
|
|
|
|
requested_data = json.loads(requested_data) if requested_data is not None else None
|
|
current_instance = (
|
|
json.loads(current_instance) if current_instance is not None else None
|
|
)
|
|
|
|
for key in requested_data:
|
|
func = ISSUE_ACTIVITY_MAPPER.get(key)
|
|
if func is not None:
|
|
func(
|
|
requested_data=requested_data,
|
|
current_instance=current_instance,
|
|
issue_id=issue_id,
|
|
project_id=project_id,
|
|
workspace_id=workspace_id,
|
|
actor_id=actor_id,
|
|
issue_activities=issue_activities,
|
|
epoch=epoch,
|
|
)
|
|
|
|
|
|
def delete_issue_activity(
|
|
requested_data,
|
|
current_instance,
|
|
issue_id,
|
|
project_id,
|
|
workspace_id,
|
|
actor_id,
|
|
issue_activities,
|
|
epoch,
|
|
):
|
|
issue_activities.append(
|
|
IssueActivity(
|
|
project_id=project_id,
|
|
workspace_id=workspace_id,
|
|
comment=f"deleted the issue",
|
|
verb="deleted",
|
|
actor_id=actor_id,
|
|
field="issue",
|
|
epoch=epoch,
|
|
)
|
|
)
|
|
|
|
|
|
def create_comment_activity(
|
|
requested_data,
|
|
current_instance,
|
|
issue_id,
|
|
project_id,
|
|
workspace_id,
|
|
actor_id,
|
|
issue_activities,
|
|
epoch,
|
|
):
|
|
requested_data = json.loads(requested_data) if requested_data is not None else None
|
|
current_instance = (
|
|
json.loads(current_instance) if current_instance is not None else None
|
|
)
|
|
|
|
issue_activities.append(
|
|
IssueActivity(
|
|
issue_id=issue_id,
|
|
project_id=project_id,
|
|
workspace_id=workspace_id,
|
|
comment=f"created a comment",
|
|
verb="created",
|
|
actor_id=actor_id,
|
|
field="comment",
|
|
new_value=requested_data.get("comment_html", ""),
|
|
new_identifier=requested_data.get("id", None),
|
|
issue_comment_id=requested_data.get("id", None),
|
|
epoch=epoch,
|
|
)
|
|
)
|
|
|
|
|
|
def update_comment_activity(
|
|
requested_data,
|
|
current_instance,
|
|
issue_id,
|
|
project_id,
|
|
workspace_id,
|
|
actor_id,
|
|
issue_activities,
|
|
epoch,
|
|
):
|
|
requested_data = json.loads(requested_data) if requested_data is not None else None
|
|
current_instance = (
|
|
json.loads(current_instance) if current_instance is not None else None
|
|
)
|
|
|
|
if current_instance.get("comment_html") != requested_data.get("comment_html"):
|
|
issue_activities.append(
|
|
IssueActivity(
|
|
issue_id=issue_id,
|
|
project_id=project_id,
|
|
workspace_id=workspace_id,
|
|
comment=f"updated a comment",
|
|
verb="updated",
|
|
actor_id=actor_id,
|
|
field="comment",
|
|
old_value=current_instance.get("comment_html", ""),
|
|
old_identifier=current_instance.get("id"),
|
|
new_value=requested_data.get("comment_html", ""),
|
|
new_identifier=current_instance.get("id", None),
|
|
issue_comment_id=current_instance.get("id", None),
|
|
epoch=epoch,
|
|
)
|
|
)
|
|
|
|
|
|
def delete_comment_activity(
|
|
requested_data,
|
|
current_instance,
|
|
issue_id,
|
|
project_id,
|
|
workspace_id,
|
|
actor_id,
|
|
issue_activities,
|
|
epoch,
|
|
):
|
|
issue_activities.append(
|
|
IssueActivity(
|
|
issue_id=issue_id,
|
|
project_id=project_id,
|
|
workspace_id=workspace_id,
|
|
comment=f"deleted the comment",
|
|
verb="deleted",
|
|
actor_id=actor_id,
|
|
field="comment",
|
|
epoch=epoch,
|
|
)
|
|
)
|
|
|
|
|
|
def create_cycle_issue_activity(
|
|
requested_data,
|
|
current_instance,
|
|
issue_id,
|
|
project_id,
|
|
workspace_id,
|
|
actor_id,
|
|
issue_activities,
|
|
epoch,
|
|
):
|
|
requested_data = json.loads(requested_data) if requested_data is not None else None
|
|
current_instance = (
|
|
json.loads(current_instance) if current_instance is not None else None
|
|
)
|
|
|
|
# Updated Records:
|
|
updated_records = current_instance.get("updated_cycle_issues", [])
|
|
created_records = json.loads(current_instance.get("created_cycle_issues", []))
|
|
|
|
for updated_record in updated_records:
|
|
old_cycle = Cycle.objects.filter(
|
|
pk=updated_record.get("old_cycle_id", None)
|
|
).first()
|
|
new_cycle = Cycle.objects.filter(
|
|
pk=updated_record.get("new_cycle_id", None)
|
|
).first()
|
|
issue = Issue.objects.filter(pk=updated_record.get("issue_id")).first()
|
|
if issue:
|
|
issue.updated_at = timezone.now()
|
|
issue.save(update_fields=["updated_at"])
|
|
|
|
issue_activities.append(
|
|
IssueActivity(
|
|
issue_id=updated_record.get("issue_id"),
|
|
actor_id=actor_id,
|
|
verb="updated",
|
|
old_value=old_cycle.name,
|
|
new_value=new_cycle.name,
|
|
field="cycles",
|
|
project_id=project_id,
|
|
workspace_id=workspace_id,
|
|
comment=f"updated cycle from {old_cycle.name} to {new_cycle.name}",
|
|
old_identifier=old_cycle.id,
|
|
new_identifier=new_cycle.id,
|
|
epoch=epoch,
|
|
)
|
|
)
|
|
|
|
for created_record in created_records:
|
|
cycle = Cycle.objects.filter(
|
|
pk=created_record.get("fields").get("cycle")
|
|
).first()
|
|
issue = Issue.objects.filter(
|
|
pk=created_record.get("fields").get("issue")
|
|
).first()
|
|
if issue:
|
|
issue.updated_at = timezone.now()
|
|
issue.save(update_fields=["updated_at"])
|
|
|
|
issue_activities.append(
|
|
IssueActivity(
|
|
issue_id=created_record.get("fields").get("issue"),
|
|
actor_id=actor_id,
|
|
verb="created",
|
|
old_value="",
|
|
new_value=cycle.name,
|
|
field="cycles",
|
|
project_id=project_id,
|
|
workspace_id=workspace_id,
|
|
comment=f"added cycle {cycle.name}",
|
|
new_identifier=cycle.id,
|
|
epoch=epoch,
|
|
)
|
|
)
|
|
|
|
|
|
def delete_cycle_issue_activity(
|
|
requested_data,
|
|
current_instance,
|
|
issue_id,
|
|
project_id,
|
|
workspace_id,
|
|
actor_id,
|
|
issue_activities,
|
|
epoch,
|
|
):
|
|
requested_data = json.loads(requested_data) if requested_data is not None else None
|
|
current_instance = (
|
|
json.loads(current_instance) if current_instance is not None else None
|
|
)
|
|
|
|
cycle_id = requested_data.get("cycle_id", "")
|
|
cycle_name = requested_data.get("cycle_name", "")
|
|
cycle = Cycle.objects.filter(pk=cycle_id).first()
|
|
issues = requested_data.get("issues")
|
|
|
|
for issue in issues:
|
|
current_issue = Issue.objects.filter(pk=issue).first()
|
|
if issue:
|
|
current_issue.updated_at = timezone.now()
|
|
current_issue.save(update_fields=["updated_at"])
|
|
issue_activities.append(
|
|
IssueActivity(
|
|
issue_id=issue,
|
|
actor_id=actor_id,
|
|
verb="deleted",
|
|
old_value=cycle.name if cycle is not None else cycle_name,
|
|
new_value="",
|
|
field="cycles",
|
|
project_id=project_id,
|
|
workspace_id=workspace_id,
|
|
comment=f"removed this issue from {cycle.name if cycle is not None else cycle_name}",
|
|
old_identifier=cycle_id if cycle_id is not None else None,
|
|
epoch=epoch,
|
|
)
|
|
)
|
|
|
|
|
|
def create_module_issue_activity(
|
|
requested_data,
|
|
current_instance,
|
|
issue_id,
|
|
project_id,
|
|
workspace_id,
|
|
actor_id,
|
|
issue_activities,
|
|
epoch,
|
|
):
|
|
requested_data = json.loads(requested_data) if requested_data is not None else None
|
|
current_instance = (
|
|
json.loads(current_instance) if current_instance is not None else None
|
|
)
|
|
|
|
# Updated Records:
|
|
updated_records = current_instance.get("updated_module_issues", [])
|
|
created_records = json.loads(current_instance.get("created_module_issues", []))
|
|
|
|
for updated_record in updated_records:
|
|
old_module = Module.objects.filter(
|
|
pk=updated_record.get("old_module_id", None)
|
|
).first()
|
|
new_module = Module.objects.filter(
|
|
pk=updated_record.get("new_module_id", None)
|
|
).first()
|
|
issue = Issue.objects.filter(pk=updated_record.get("issue_id")).first()
|
|
if issue:
|
|
issue.updated_at = timezone.now()
|
|
issue.save(update_fields=["updated_at"])
|
|
|
|
issue_activities.append(
|
|
IssueActivity(
|
|
issue_id=updated_record.get("issue_id"),
|
|
actor_id=actor_id,
|
|
verb="updated",
|
|
old_value=old_module.name,
|
|
new_value=new_module.name,
|
|
field="modules",
|
|
project_id=project_id,
|
|
workspace_id=workspace_id,
|
|
comment=f"updated module to ",
|
|
old_identifier=old_module.id,
|
|
new_identifier=new_module.id,
|
|
epoch=epoch,
|
|
)
|
|
)
|
|
|
|
for created_record in created_records:
|
|
module = Module.objects.filter(
|
|
pk=created_record.get("fields").get("module")
|
|
).first()
|
|
issue = Issue.objects.filter(
|
|
pk=created_record.get("fields").get("issue")
|
|
).first()
|
|
if issue:
|
|
issue.updated_at = timezone.now()
|
|
issue.save(update_fields=["updated_at"])
|
|
issue_activities.append(
|
|
IssueActivity(
|
|
issue_id=created_record.get("fields").get("issue"),
|
|
actor_id=actor_id,
|
|
verb="created",
|
|
old_value="",
|
|
new_value=module.name,
|
|
field="modules",
|
|
project_id=project_id,
|
|
workspace_id=workspace_id,
|
|
comment=f"added module {module.name}",
|
|
new_identifier=module.id,
|
|
epoch=epoch,
|
|
)
|
|
)
|
|
|
|
|
|
def delete_module_issue_activity(
|
|
requested_data,
|
|
current_instance,
|
|
issue_id,
|
|
project_id,
|
|
workspace_id,
|
|
actor_id,
|
|
issue_activities,
|
|
epoch,
|
|
):
|
|
requested_data = json.loads(requested_data) if requested_data is not None else None
|
|
current_instance = (
|
|
json.loads(current_instance) if current_instance is not None else None
|
|
)
|
|
|
|
module_id = requested_data.get("module_id", "")
|
|
module_name = requested_data.get("module_name", "")
|
|
module = Module.objects.filter(pk=module_id).first()
|
|
issues = requested_data.get("issues")
|
|
|
|
for issue in issues:
|
|
current_issue = Issue.objects.filter(pk=issue).first()
|
|
if issue:
|
|
current_issue.updated_at = timezone.now()
|
|
current_issue.save(update_fields=["updated_at"])
|
|
issue_activities.append(
|
|
IssueActivity(
|
|
issue_id=issue,
|
|
actor_id=actor_id,
|
|
verb="deleted",
|
|
old_value=module.name if module is not None else module_name,
|
|
new_value="",
|
|
field="modules",
|
|
project_id=project_id,
|
|
workspace_id=workspace_id,
|
|
comment=f"removed this issue from {module.name if module is not None else module_name}",
|
|
old_identifier=module_id if module_id is not None else None,
|
|
epoch=epoch,
|
|
)
|
|
)
|
|
|
|
|
|
def create_link_activity(
|
|
requested_data,
|
|
current_instance,
|
|
issue_id,
|
|
project_id,
|
|
actor_id,
|
|
workspace_id,
|
|
issue_activities,
|
|
epoch,
|
|
):
|
|
requested_data = json.loads(requested_data) if requested_data is not None else None
|
|
current_instance = (
|
|
json.loads(current_instance) if current_instance is not None else None
|
|
)
|
|
|
|
issue_activities.append(
|
|
IssueActivity(
|
|
issue_id=issue_id,
|
|
project_id=project_id,
|
|
workspace_id=workspace_id,
|
|
comment=f"created a link",
|
|
verb="created",
|
|
actor_id=actor_id,
|
|
field="link",
|
|
new_value=requested_data.get("url", ""),
|
|
new_identifier=requested_data.get("id", None),
|
|
epoch=epoch,
|
|
)
|
|
)
|
|
|
|
|
|
def update_link_activity(
|
|
requested_data,
|
|
current_instance,
|
|
issue_id,
|
|
project_id,
|
|
workspace_id,
|
|
actor_id,
|
|
issue_activities,
|
|
epoch,
|
|
):
|
|
requested_data = json.loads(requested_data) if requested_data is not None else None
|
|
current_instance = (
|
|
json.loads(current_instance) if current_instance is not None else None
|
|
)
|
|
|
|
if current_instance.get("url") != requested_data.get("url"):
|
|
issue_activities.append(
|
|
IssueActivity(
|
|
issue_id=issue_id,
|
|
project_id=project_id,
|
|
workspace_id=workspace_id,
|
|
comment=f"updated a link",
|
|
verb="updated",
|
|
actor_id=actor_id,
|
|
field="link",
|
|
old_value=current_instance.get("url", ""),
|
|
old_identifier=current_instance.get("id"),
|
|
new_value=requested_data.get("url", ""),
|
|
new_identifier=current_instance.get("id", None),
|
|
epoch=epoch,
|
|
)
|
|
)
|
|
|
|
|
|
def delete_link_activity(
|
|
requested_data,
|
|
current_instance,
|
|
issue_id,
|
|
project_id,
|
|
workspace_id,
|
|
actor_id,
|
|
issue_activities,
|
|
epoch,
|
|
):
|
|
current_instance = (
|
|
json.loads(current_instance) if current_instance is not None else None
|
|
)
|
|
|
|
issue_activities.append(
|
|
IssueActivity(
|
|
issue_id=issue_id,
|
|
project_id=project_id,
|
|
workspace_id=workspace_id,
|
|
comment=f"deleted the link",
|
|
verb="deleted",
|
|
actor_id=actor_id,
|
|
field="link",
|
|
old_value=current_instance.get("url", ""),
|
|
new_value="",
|
|
epoch=epoch,
|
|
)
|
|
)
|
|
|
|
|
|
def create_attachment_activity(
|
|
requested_data,
|
|
current_instance,
|
|
issue_id,
|
|
project_id,
|
|
actor_id,
|
|
workspace_id,
|
|
issue_activities,
|
|
epoch,
|
|
):
|
|
requested_data = json.loads(requested_data) if requested_data is not None else None
|
|
current_instance = (
|
|
json.loads(current_instance) if current_instance is not None else None
|
|
)
|
|
|
|
issue_activities.append(
|
|
IssueActivity(
|
|
issue_id=issue_id,
|
|
project_id=project_id,
|
|
workspace_id=workspace_id,
|
|
comment=f"created an attachment",
|
|
verb="created",
|
|
actor_id=actor_id,
|
|
field="attachment",
|
|
new_value=current_instance.get("asset", ""),
|
|
new_identifier=current_instance.get("id", None),
|
|
epoch=epoch,
|
|
)
|
|
)
|
|
|
|
|
|
def delete_attachment_activity(
|
|
requested_data,
|
|
current_instance,
|
|
issue_id,
|
|
project_id,
|
|
workspace_id,
|
|
actor_id,
|
|
issue_activities,
|
|
epoch,
|
|
):
|
|
issue_activities.append(
|
|
IssueActivity(
|
|
issue_id=issue_id,
|
|
project_id=project_id,
|
|
workspace_id=workspace_id,
|
|
comment=f"deleted the attachment",
|
|
verb="deleted",
|
|
actor_id=actor_id,
|
|
field="attachment",
|
|
epoch=epoch,
|
|
)
|
|
)
|
|
|
|
|
|
def create_issue_reaction_activity(
|
|
requested_data,
|
|
current_instance,
|
|
issue_id,
|
|
project_id,
|
|
workspace_id,
|
|
actor_id,
|
|
issue_activities,
|
|
epoch,
|
|
):
|
|
requested_data = json.loads(requested_data) if requested_data is not None else None
|
|
if requested_data and requested_data.get("reaction") is not None:
|
|
issue_reaction = (
|
|
IssueReaction.objects.filter(
|
|
reaction=requested_data.get("reaction"),
|
|
project_id=project_id,
|
|
actor_id=actor_id,
|
|
)
|
|
.values_list("id", flat=True)
|
|
.first()
|
|
)
|
|
if issue_reaction is not None:
|
|
issue_activities.append(
|
|
IssueActivity(
|
|
issue_id=issue_id,
|
|
actor_id=actor_id,
|
|
verb="created",
|
|
old_value=None,
|
|
new_value=requested_data.get("reaction"),
|
|
field="reaction",
|
|
project_id=project_id,
|
|
workspace_id=workspace_id,
|
|
comment="added the reaction",
|
|
old_identifier=None,
|
|
new_identifier=issue_reaction,
|
|
epoch=epoch,
|
|
)
|
|
)
|
|
|
|
|
|
def delete_issue_reaction_activity(
|
|
requested_data,
|
|
current_instance,
|
|
issue_id,
|
|
project_id,
|
|
workspace_id,
|
|
actor_id,
|
|
issue_activities,
|
|
epoch,
|
|
):
|
|
current_instance = (
|
|
json.loads(current_instance) if current_instance is not None else None
|
|
)
|
|
if current_instance and current_instance.get("reaction") is not None:
|
|
issue_activities.append(
|
|
IssueActivity(
|
|
issue_id=issue_id,
|
|
actor_id=actor_id,
|
|
verb="deleted",
|
|
old_value=current_instance.get("reaction"),
|
|
new_value=None,
|
|
field="reaction",
|
|
project_id=project_id,
|
|
workspace_id=workspace_id,
|
|
comment="removed the reaction",
|
|
old_identifier=current_instance.get("identifier"),
|
|
new_identifier=None,
|
|
epoch=epoch,
|
|
)
|
|
)
|
|
|
|
|
|
def create_comment_reaction_activity(
|
|
requested_data,
|
|
current_instance,
|
|
issue_id,
|
|
project_id,
|
|
workspace_id,
|
|
actor_id,
|
|
issue_activities,
|
|
epoch,
|
|
):
|
|
requested_data = json.loads(requested_data) if requested_data is not None else None
|
|
if requested_data and requested_data.get("reaction") is not None:
|
|
comment_reaction_id, comment_id = (
|
|
CommentReaction.objects.filter(
|
|
reaction=requested_data.get("reaction"),
|
|
project_id=project_id,
|
|
actor_id=actor_id,
|
|
)
|
|
.values_list("id", "comment__id")
|
|
.first()
|
|
)
|
|
comment = IssueComment.objects.get(pk=comment_id, project_id=project_id)
|
|
if (
|
|
comment is not None
|
|
and comment_reaction_id is not None
|
|
and comment_id is not None
|
|
):
|
|
issue_activities.append(
|
|
IssueActivity(
|
|
issue_id=comment.issue_id,
|
|
actor_id=actor_id,
|
|
verb="created",
|
|
old_value=None,
|
|
new_value=requested_data.get("reaction"),
|
|
field="reaction",
|
|
project_id=project_id,
|
|
workspace_id=workspace_id,
|
|
comment="added the reaction",
|
|
old_identifier=None,
|
|
new_identifier=comment_reaction_id,
|
|
epoch=epoch,
|
|
)
|
|
)
|
|
|
|
|
|
def delete_comment_reaction_activity(
|
|
requested_data,
|
|
current_instance,
|
|
issue_id,
|
|
project_id,
|
|
workspace_id,
|
|
actor_id,
|
|
issue_activities,
|
|
epoch,
|
|
):
|
|
current_instance = (
|
|
json.loads(current_instance) if current_instance is not None else None
|
|
)
|
|
if current_instance and current_instance.get("reaction") is not None:
|
|
issue_id = (
|
|
IssueComment.objects.filter(
|
|
pk=current_instance.get("comment_id"), project_id=project_id
|
|
)
|
|
.values_list("issue_id", flat=True)
|
|
.first()
|
|
)
|
|
if issue_id is not None:
|
|
issue_activities.append(
|
|
IssueActivity(
|
|
issue_id=issue_id,
|
|
actor_id=actor_id,
|
|
verb="deleted",
|
|
old_value=current_instance.get("reaction"),
|
|
new_value=None,
|
|
field="reaction",
|
|
project_id=project_id,
|
|
workspace_id=workspace_id,
|
|
comment="removed the reaction",
|
|
old_identifier=current_instance.get("identifier"),
|
|
new_identifier=None,
|
|
epoch=epoch,
|
|
)
|
|
)
|
|
|
|
|
|
def create_issue_vote_activity(
|
|
requested_data,
|
|
current_instance,
|
|
issue_id,
|
|
project_id,
|
|
workspace_id,
|
|
actor_id,
|
|
issue_activities,
|
|
epoch,
|
|
):
|
|
requested_data = json.loads(requested_data) if requested_data is not None else None
|
|
if requested_data and requested_data.get("vote") is not None:
|
|
issue_activities.append(
|
|
IssueActivity(
|
|
issue_id=issue_id,
|
|
actor_id=actor_id,
|
|
verb="created",
|
|
old_value=None,
|
|
new_value=requested_data.get("vote"),
|
|
field="vote",
|
|
project_id=project_id,
|
|
workspace_id=workspace_id,
|
|
comment="added the vote",
|
|
old_identifier=None,
|
|
new_identifier=None,
|
|
epoch=epoch,
|
|
)
|
|
)
|
|
|
|
|
|
def delete_issue_vote_activity(
|
|
requested_data,
|
|
current_instance,
|
|
issue_id,
|
|
project_id,
|
|
workspace_id,
|
|
actor_id,
|
|
issue_activities,
|
|
epoch,
|
|
):
|
|
current_instance = (
|
|
json.loads(current_instance) if current_instance is not None else None
|
|
)
|
|
if current_instance and current_instance.get("vote") is not None:
|
|
issue_activities.append(
|
|
IssueActivity(
|
|
issue_id=issue_id,
|
|
actor_id=actor_id,
|
|
verb="deleted",
|
|
old_value=current_instance.get("vote"),
|
|
new_value=None,
|
|
field="vote",
|
|
project_id=project_id,
|
|
workspace_id=workspace_id,
|
|
comment="removed the vote",
|
|
old_identifier=current_instance.get("identifier"),
|
|
new_identifier=None,
|
|
epoch=epoch,
|
|
)
|
|
)
|
|
|
|
|
|
def create_issue_relation_activity(
|
|
requested_data,
|
|
current_instance,
|
|
issue_id,
|
|
project_id,
|
|
workspace_id,
|
|
actor_id,
|
|
issue_activities,
|
|
epoch,
|
|
):
|
|
requested_data = json.loads(requested_data) if requested_data is not None else None
|
|
current_instance = (
|
|
json.loads(current_instance) if current_instance is not None else None
|
|
)
|
|
if current_instance is None and requested_data.get("issues") is not None:
|
|
for related_issue in requested_data.get("issues"):
|
|
issue = Issue.objects.get(pk=related_issue)
|
|
issue_activities.append(
|
|
IssueActivity(
|
|
issue_id=issue_id,
|
|
actor_id=actor_id,
|
|
verb="created",
|
|
old_value="",
|
|
new_value=f"{issue.project.identifier}-{issue.sequence_id}",
|
|
field=requested_data.get("relation_type"),
|
|
project_id=project_id,
|
|
workspace_id=workspace_id,
|
|
comment=f"added {requested_data.get('relation_type')} relation",
|
|
old_identifier=related_issue,
|
|
)
|
|
)
|
|
issue = Issue.objects.get(pk=issue_id)
|
|
issue_activities.append(
|
|
IssueActivity(
|
|
issue_id=related_issue,
|
|
actor_id=actor_id,
|
|
verb="created",
|
|
old_value="",
|
|
new_value=f"{issue.project.identifier}-{issue.sequence_id}",
|
|
field="blocking"
|
|
if requested_data.get("relation_type") == "blocked_by"
|
|
else (
|
|
"blocked_by"
|
|
if requested_data.get("relation_type") == "blocking"
|
|
else requested_data.get("relation_type")
|
|
),
|
|
project_id=project_id,
|
|
workspace_id=workspace_id,
|
|
comment=f'added {"blocking" if requested_data.get("relation_type") == "blocked_by" else ("blocked_by" if requested_data.get("relation_type") == "blocking" else requested_data.get("relation_type")),} relation',
|
|
old_identifier=issue_id,
|
|
epoch=epoch,
|
|
)
|
|
)
|
|
|
|
|
|
def delete_issue_relation_activity(
|
|
requested_data,
|
|
current_instance,
|
|
issue_id,
|
|
project_id,
|
|
workspace_id,
|
|
actor_id,
|
|
issue_activities,
|
|
epoch,
|
|
):
|
|
requested_data = json.loads(requested_data) if requested_data is not None else None
|
|
current_instance = (
|
|
json.loads(current_instance) if current_instance is not None else None
|
|
)
|
|
issue = Issue.objects.get(pk=requested_data.get("related_issue"))
|
|
issue_activities.append(
|
|
IssueActivity(
|
|
issue_id=issue_id,
|
|
actor_id=actor_id,
|
|
verb="deleted",
|
|
old_value=f"{issue.project.identifier}-{issue.sequence_id}",
|
|
new_value="",
|
|
field=requested_data.get("relation_type"),
|
|
project_id=project_id,
|
|
workspace_id=workspace_id,
|
|
comment=f"deleted {requested_data.get('relation_type')} relation",
|
|
old_identifier=requested_data.get("related_issue"),
|
|
epoch=epoch,
|
|
)
|
|
)
|
|
issue = Issue.objects.get(pk=issue_id)
|
|
issue_activities.append(
|
|
IssueActivity(
|
|
issue_id=requested_data.get("related_issue"),
|
|
actor_id=actor_id,
|
|
verb="deleted",
|
|
old_value=f"{issue.project.identifier}-{issue.sequence_id}",
|
|
new_value="",
|
|
field="blocking"
|
|
if requested_data.get("relation_type") == "blocked_by"
|
|
else (
|
|
"blocked_by"
|
|
if requested_data.get("relation_type") == "blocking"
|
|
else requested_data.get("relation_type")
|
|
),
|
|
project_id=project_id,
|
|
workspace_id=workspace_id,
|
|
comment=f'deleted {requested_data.get("relation_type")} relation',
|
|
old_identifier=requested_data.get("related_issue"),
|
|
epoch=epoch,
|
|
)
|
|
)
|
|
|
|
def create_draft_issue_activity(
|
|
requested_data,
|
|
current_instance,
|
|
issue_id,
|
|
project_id,
|
|
workspace_id,
|
|
actor_id,
|
|
issue_activities,
|
|
epoch,
|
|
):
|
|
issue_activities.append(
|
|
IssueActivity(
|
|
issue_id=issue_id,
|
|
project_id=project_id,
|
|
workspace_id=workspace_id,
|
|
comment=f"drafted the issue",
|
|
field="draft",
|
|
verb="created",
|
|
actor_id=actor_id,
|
|
epoch=epoch,
|
|
)
|
|
)
|
|
|
|
|
|
def update_draft_issue_activity(
|
|
requested_data,
|
|
current_instance,
|
|
issue_id,
|
|
project_id,
|
|
workspace_id,
|
|
actor_id,
|
|
issue_activities,
|
|
epoch,
|
|
):
|
|
requested_data = json.loads(requested_data) if requested_data is not None else None
|
|
current_instance = (
|
|
json.loads(current_instance) if current_instance is not None else None
|
|
)
|
|
if (
|
|
requested_data.get("is_draft") is not None
|
|
and requested_data.get("is_draft") == False
|
|
):
|
|
issue_activities.append(
|
|
IssueActivity(
|
|
issue_id=issue_id,
|
|
project_id=project_id,
|
|
workspace_id=workspace_id,
|
|
comment=f"created the issue",
|
|
verb="updated",
|
|
actor_id=actor_id,
|
|
epoch=epoch,
|
|
)
|
|
)
|
|
else:
|
|
issue_activities.append(
|
|
IssueActivity(
|
|
issue_id=issue_id,
|
|
project_id=project_id,
|
|
workspace_id=workspace_id,
|
|
comment=f"updated the draft issue",
|
|
field="draft",
|
|
verb="updated",
|
|
actor_id=actor_id,
|
|
epoch=epoch,
|
|
)
|
|
)
|
|
|
|
|
|
def delete_draft_issue_activity(
|
|
requested_data,
|
|
current_instance,
|
|
issue_id,
|
|
project_id,
|
|
workspace_id,
|
|
actor_id,
|
|
issue_activities,
|
|
epoch,
|
|
):
|
|
issue_activities.append(
|
|
IssueActivity(
|
|
project_id=project_id,
|
|
workspace_id=workspace_id,
|
|
comment=f"deleted the draft issue",
|
|
field="draft",
|
|
verb="deleted",
|
|
actor_id=actor_id,
|
|
epoch=epoch,
|
|
)
|
|
)
|
|
|
|
|
|
# Receive message from room group
|
|
@shared_task
|
|
def issue_activity(
|
|
type,
|
|
requested_data,
|
|
current_instance,
|
|
issue_id,
|
|
actor_id,
|
|
project_id,
|
|
epoch,
|
|
subscriber=True,
|
|
):
|
|
try:
|
|
issue_activities = []
|
|
|
|
project = Project.objects.get(pk=project_id)
|
|
workspace_id = project.workspace_id
|
|
|
|
if issue_id is not None:
|
|
issue = Issue.objects.filter(pk=issue_id).first()
|
|
if issue:
|
|
try:
|
|
issue.updated_at = timezone.now()
|
|
issue.save(update_fields=["updated_at"])
|
|
except Exception as e:
|
|
pass
|
|
|
|
ACTIVITY_MAPPER = {
|
|
"issue.activity.created": create_issue_activity,
|
|
"issue.activity.updated": update_issue_activity,
|
|
"issue.activity.deleted": delete_issue_activity,
|
|
"comment.activity.created": create_comment_activity,
|
|
"comment.activity.updated": update_comment_activity,
|
|
"comment.activity.deleted": delete_comment_activity,
|
|
"cycle.activity.created": create_cycle_issue_activity,
|
|
"cycle.activity.deleted": delete_cycle_issue_activity,
|
|
"module.activity.created": create_module_issue_activity,
|
|
"module.activity.deleted": delete_module_issue_activity,
|
|
"link.activity.created": create_link_activity,
|
|
"link.activity.updated": update_link_activity,
|
|
"link.activity.deleted": delete_link_activity,
|
|
"attachment.activity.created": create_attachment_activity,
|
|
"attachment.activity.deleted": delete_attachment_activity,
|
|
"issue_relation.activity.created": create_issue_relation_activity,
|
|
"issue_relation.activity.deleted": delete_issue_relation_activity,
|
|
"issue_reaction.activity.created": create_issue_reaction_activity,
|
|
"issue_reaction.activity.deleted": delete_issue_reaction_activity,
|
|
"comment_reaction.activity.created": create_comment_reaction_activity,
|
|
"comment_reaction.activity.deleted": delete_comment_reaction_activity,
|
|
"issue_vote.activity.created": create_issue_vote_activity,
|
|
"issue_vote.activity.deleted": delete_issue_vote_activity,
|
|
"issue_draft.activity.created": create_draft_issue_activity,
|
|
"issue_draft.activity.updated": update_draft_issue_activity,
|
|
"issue_draft.activity.deleted": delete_draft_issue_activity,
|
|
}
|
|
|
|
func = ACTIVITY_MAPPER.get(type)
|
|
if func is not None:
|
|
func(
|
|
requested_data=requested_data,
|
|
current_instance=current_instance,
|
|
issue_id=issue_id,
|
|
project_id=project_id,
|
|
workspace_id=workspace_id,
|
|
actor_id=actor_id,
|
|
issue_activities=issue_activities,
|
|
epoch=epoch,
|
|
)
|
|
|
|
# Save all the values to database
|
|
issue_activities_created = IssueActivity.objects.bulk_create(issue_activities)
|
|
# Post the updates to segway for integrations and webhooks
|
|
if len(issue_activities_created):
|
|
# Don't send activities if the actor is a bot
|
|
try:
|
|
if settings.PROXY_BASE_URL:
|
|
for issue_activity in issue_activities_created:
|
|
headers = {"Content-Type": "application/json"}
|
|
issue_activity_json = json.dumps(
|
|
IssueActivitySerializer(issue_activity).data,
|
|
cls=DjangoJSONEncoder,
|
|
)
|
|
_ = requests.post(
|
|
f"{settings.PROXY_BASE_URL}/hooks/workspaces/{str(issue_activity.workspace_id)}/projects/{str(issue_activity.project_id)}/issues/{str(issue_activity.issue_id)}/issue-activity-hooks/",
|
|
json=issue_activity_json,
|
|
headers=headers,
|
|
)
|
|
except Exception as e:
|
|
capture_exception(e)
|
|
|
|
notifications.delay(
|
|
type=type,
|
|
issue_id=issue_id,
|
|
actor_id=actor_id,
|
|
project_id=project_id,
|
|
subscriber=subscriber,
|
|
issue_activities_created=json.dumps(
|
|
IssueActivitySerializer(issue_activities_created, many=True).data,
|
|
cls=DjangoJSONEncoder,
|
|
),
|
|
requested_data=requested_data,
|
|
current_instance=current_instance,
|
|
)
|
|
|
|
return
|
|
except Exception as e:
|
|
# Print logs if in DEBUG mode
|
|
if settings.DEBUG:
|
|
print(e)
|
|
capture_exception(e)
|
|
return
|