* 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>
422 lines
17 KiB
Python
422 lines
17 KiB
Python
# Python imports
|
|
import json
|
|
import uuid
|
|
|
|
# Module imports
|
|
from plane.db.models import (
|
|
IssueMention,
|
|
IssueSubscriber,
|
|
Project,
|
|
User,
|
|
IssueAssignee,
|
|
Issue,
|
|
Notification,
|
|
IssueComment,
|
|
IssueActivity
|
|
)
|
|
|
|
# Third Party imports
|
|
from celery import shared_task
|
|
from bs4 import BeautifulSoup
|
|
|
|
|
|
|
|
# =========== Issue Description Html Parsing and Notification Functions ======================
|
|
|
|
def update_mentions_for_issue(issue, project, new_mentions, removed_mention):
|
|
aggregated_issue_mentions = []
|
|
|
|
for mention_id in new_mentions:
|
|
aggregated_issue_mentions.append(
|
|
IssueMention(
|
|
mention_id=mention_id,
|
|
issue=issue,
|
|
project=project,
|
|
workspace_id=project.workspace_id
|
|
)
|
|
)
|
|
|
|
IssueMention.objects.bulk_create(
|
|
aggregated_issue_mentions, batch_size=100)
|
|
IssueMention.objects.filter(
|
|
issue=issue, mention__in=removed_mention).delete()
|
|
|
|
|
|
def get_new_mentions(requested_instance, current_instance):
|
|
# requested_data is the newer instance of the current issue
|
|
# current_instance is the older instance of the current issue, saved in the database
|
|
|
|
# extract mentions from both the instance of data
|
|
mentions_older = extract_mentions(current_instance)
|
|
|
|
mentions_newer = extract_mentions(requested_instance)
|
|
|
|
# Getting Set Difference from mentions_newer
|
|
new_mentions = [
|
|
mention for mention in mentions_newer if mention not in mentions_older]
|
|
|
|
return new_mentions
|
|
|
|
# Get Removed Mention
|
|
|
|
|
|
def get_removed_mentions(requested_instance, current_instance):
|
|
# requested_data is the newer instance of the current issue
|
|
# current_instance is the older instance of the current issue, saved in the database
|
|
|
|
# extract mentions from both the instance of data
|
|
mentions_older = extract_mentions(current_instance)
|
|
mentions_newer = extract_mentions(requested_instance)
|
|
|
|
# Getting Set Difference from mentions_newer
|
|
removed_mentions = [
|
|
mention for mention in mentions_older if mention not in mentions_newer]
|
|
|
|
return removed_mentions
|
|
|
|
# Adds mentions as subscribers
|
|
|
|
|
|
def extract_mentions_as_subscribers(project_id, issue_id, mentions):
|
|
# mentions is an array of User IDs representing the FILTERED set of mentioned users
|
|
|
|
bulk_mention_subscribers = []
|
|
|
|
for mention_id in mentions:
|
|
# If the particular mention has not already been subscribed to the issue, he must be sent the mentioned notification
|
|
if not IssueSubscriber.objects.filter(
|
|
issue_id=issue_id,
|
|
subscriber_id=mention_id,
|
|
project_id=project_id,
|
|
).exists() and not IssueAssignee.objects.filter(
|
|
project_id=project_id, issue_id=issue_id,
|
|
assignee_id=mention_id
|
|
).exists() and not Issue.objects.filter(
|
|
project_id=project_id, pk=issue_id, created_by_id=mention_id
|
|
).exists():
|
|
|
|
project = Project.objects.get(pk=project_id)
|
|
|
|
bulk_mention_subscribers.append(IssueSubscriber(
|
|
workspace_id=project.workspace_id,
|
|
project_id=project_id,
|
|
issue_id=issue_id,
|
|
subscriber_id=mention_id,
|
|
))
|
|
return bulk_mention_subscribers
|
|
|
|
# Parse Issue Description & extracts mentions
|
|
def extract_mentions(issue_instance):
|
|
try:
|
|
# issue_instance has to be a dictionary passed, containing the description_html and other set of activity data.
|
|
mentions = []
|
|
# Convert string to dictionary
|
|
data = json.loads(issue_instance)
|
|
html = data.get("description_html")
|
|
soup = BeautifulSoup(html, 'html.parser')
|
|
mention_tags = soup.find_all(
|
|
'mention-component', attrs={'target': 'users'})
|
|
|
|
mentions = [mention_tag['id'] for mention_tag in mention_tags]
|
|
|
|
return list(set(mentions))
|
|
except Exception as e:
|
|
return []
|
|
|
|
|
|
# =========== Comment Parsing and Notification Functions ======================
|
|
def extract_comment_mentions(comment_value):
|
|
try:
|
|
mentions = []
|
|
soup = BeautifulSoup(comment_value, 'html.parser')
|
|
mentions_tags = soup.find_all(
|
|
'mention-component', attrs={'target': 'users'}
|
|
)
|
|
for mention_tag in mentions_tags:
|
|
mentions.append(mention_tag['id'])
|
|
return list(set(mentions))
|
|
except Exception as e:
|
|
return []
|
|
|
|
def get_new_comment_mentions(new_value, old_value):
|
|
|
|
mentions_newer = extract_comment_mentions(new_value)
|
|
if old_value is None:
|
|
return mentions_newer
|
|
|
|
mentions_older = extract_comment_mentions(old_value)
|
|
# Getting Set Difference from mentions_newer
|
|
new_mentions = [
|
|
mention for mention in mentions_newer if mention not in mentions_older]
|
|
|
|
return new_mentions
|
|
|
|
|
|
def createMentionNotification(project, notification_comment, issue, actor_id, mention_id, issue_id, activity):
|
|
return Notification(
|
|
workspace=project.workspace,
|
|
sender="in_app:issue_activities:mentioned",
|
|
triggered_by_id=actor_id,
|
|
receiver_id=mention_id,
|
|
entity_identifier=issue_id,
|
|
entity_name="issue",
|
|
project=project,
|
|
message=notification_comment,
|
|
data={
|
|
"issue": {
|
|
"id": str(issue_id),
|
|
"name": str(issue.name),
|
|
"identifier": str(issue.project.identifier),
|
|
"sequence_id": issue.sequence_id,
|
|
"state_name": issue.state.name,
|
|
"state_group": issue.state.group,
|
|
},
|
|
"issue_activity": {
|
|
"id": str(activity.get("id")),
|
|
"verb": str(activity.get("verb")),
|
|
"field": str(activity.get("field")),
|
|
"actor": str(activity.get("actor_id")),
|
|
"new_value": str(activity.get("new_value")),
|
|
"old_value": str(activity.get("old_value")),
|
|
}
|
|
},
|
|
)
|
|
|
|
|
|
@shared_task
|
|
def notifications(type, issue_id, project_id, actor_id, subscriber, issue_activities_created, requested_data, current_instance):
|
|
issue_activities_created = (
|
|
json.loads(
|
|
issue_activities_created) if issue_activities_created is not None else None
|
|
)
|
|
if type not in [
|
|
"issue.activity.deleted",
|
|
"cycle.activity.created",
|
|
"cycle.activity.deleted",
|
|
"module.activity.created",
|
|
"module.activity.deleted",
|
|
"issue_reaction.activity.created",
|
|
"issue_reaction.activity.deleted",
|
|
"comment_reaction.activity.created",
|
|
"comment_reaction.activity.deleted",
|
|
"issue_vote.activity.created",
|
|
"issue_vote.activity.deleted",
|
|
"issue_draft.activity.created",
|
|
"issue_draft.activity.updated",
|
|
"issue_draft.activity.deleted",
|
|
]:
|
|
# Create Notifications
|
|
bulk_notifications = []
|
|
|
|
"""
|
|
Mention Tasks
|
|
1. Perform Diffing and Extract the mentions, that mention notification needs to be sent
|
|
2. From the latest set of mentions, extract the users which are not a subscribers & make them subscribers
|
|
"""
|
|
|
|
# Get new mentions from the newer instance
|
|
new_mentions = get_new_mentions(
|
|
requested_instance=requested_data, current_instance=current_instance)
|
|
removed_mention = get_removed_mentions(
|
|
requested_instance=requested_data, current_instance=current_instance)
|
|
|
|
comment_mentions = []
|
|
all_comment_mentions = []
|
|
|
|
# Get New Subscribers from the mentions of the newer instance
|
|
requested_mentions = extract_mentions(
|
|
issue_instance=requested_data)
|
|
mention_subscribers = extract_mentions_as_subscribers(
|
|
project_id=project_id, issue_id=issue_id, mentions=requested_mentions)
|
|
|
|
for issue_activity in issue_activities_created:
|
|
issue_comment = issue_activity.get("issue_comment")
|
|
issue_comment_new_value = issue_activity.get("new_value")
|
|
issue_comment_old_value = issue_activity.get("old_value")
|
|
if issue_comment is not None:
|
|
# TODO: Maybe save the comment mentions, so that in future, we can filter out the issues based on comment mentions as well.
|
|
|
|
all_comment_mentions = all_comment_mentions + extract_comment_mentions(issue_comment_new_value)
|
|
|
|
new_comment_mentions = get_new_comment_mentions(old_value=issue_comment_old_value, new_value=issue_comment_new_value)
|
|
comment_mentions = comment_mentions + new_comment_mentions
|
|
|
|
comment_mention_subscribers = extract_mentions_as_subscribers( project_id=project_id, issue_id=issue_id, mentions=all_comment_mentions)
|
|
"""
|
|
We will not send subscription activity notification to the below mentioned user sets
|
|
- Those who have been newly mentioned in the issue description, we will send mention notification to them.
|
|
- When the activity is a comment_created and there exist a mention in the comment, then we have to send the "mention_in_comment" notification
|
|
- When the activity is a comment_updated and there exist a mention change, then also we have to send the "mention_in_comment" notification
|
|
"""
|
|
|
|
issue_assignees = list(
|
|
IssueAssignee.objects.filter(
|
|
project_id=project_id, issue_id=issue_id)
|
|
.exclude(assignee_id__in=list(new_mentions + comment_mentions))
|
|
.values_list("assignee", flat=True)
|
|
)
|
|
|
|
issue_subscribers = list(
|
|
IssueSubscriber.objects.filter(
|
|
project_id=project_id, issue_id=issue_id)
|
|
.exclude(subscriber_id__in=list(new_mentions + comment_mentions + [actor_id]))
|
|
.values_list("subscriber", flat=True)
|
|
)
|
|
|
|
issue = Issue.objects.filter(pk=issue_id).first()
|
|
|
|
if (issue.created_by_id is not None and str(issue.created_by_id) != str(actor_id)):
|
|
issue_subscribers = issue_subscribers + [issue.created_by_id]
|
|
|
|
if subscriber:
|
|
# add the user to issue subscriber
|
|
try:
|
|
if str(issue.created_by_id) != str(actor_id) and uuid.UUID(actor_id) not in issue_assignees:
|
|
_ = IssueSubscriber.objects.get_or_create(
|
|
project_id=project_id, issue_id=issue_id, subscriber_id=actor_id
|
|
)
|
|
except Exception as e:
|
|
pass
|
|
|
|
project = Project.objects.get(pk=project_id)
|
|
|
|
issue_subscribers = list(set(issue_subscribers + issue_assignees) - {uuid.UUID(actor_id)})
|
|
|
|
for subscriber in issue_subscribers:
|
|
if subscriber in issue_subscribers:
|
|
sender = "in_app:issue_activities:subscribed"
|
|
if issue.created_by_id is not None and subscriber == issue.created_by_id:
|
|
sender = "in_app:issue_activities:created"
|
|
if subscriber in issue_assignees:
|
|
sender = "in_app:issue_activities:assigned"
|
|
|
|
for issue_activity in issue_activities_created:
|
|
# Do not send notification for description update
|
|
if issue_activity.get("field") == "description":
|
|
continue;
|
|
issue_comment = issue_activity.get("issue_comment")
|
|
if issue_comment is not None:
|
|
issue_comment = IssueComment.objects.get(
|
|
id=issue_comment, issue_id=issue_id, project_id=project_id, workspace_id=project.workspace_id)
|
|
|
|
bulk_notifications.append(
|
|
Notification(
|
|
workspace=project.workspace,
|
|
sender=sender,
|
|
triggered_by_id=actor_id,
|
|
receiver_id=subscriber,
|
|
entity_identifier=issue_id,
|
|
entity_name="issue",
|
|
project=project,
|
|
title=issue_activity.get("comment"),
|
|
data={
|
|
"issue": {
|
|
"id": str(issue_id),
|
|
"name": str(issue.name),
|
|
"identifier": str(issue.project.identifier),
|
|
"sequence_id": issue.sequence_id,
|
|
"state_name": issue.state.name,
|
|
"state_group": issue.state.group,
|
|
},
|
|
"issue_activity": {
|
|
"id": str(issue_activity.get("id")),
|
|
"verb": str(issue_activity.get("verb")),
|
|
"field": str(issue_activity.get("field")),
|
|
"actor": str(issue_activity.get("actor_id")),
|
|
"new_value": str(issue_activity.get("new_value")),
|
|
"old_value": str(issue_activity.get("old_value")),
|
|
"issue_comment": str(
|
|
issue_comment.comment_stripped
|
|
if issue_activity.get("issue_comment") is not None
|
|
else ""
|
|
),
|
|
},
|
|
},
|
|
)
|
|
)
|
|
|
|
# Add Mentioned as Issue Subscribers
|
|
IssueSubscriber.objects.bulk_create(
|
|
mention_subscribers + comment_mention_subscribers, batch_size=100)
|
|
|
|
last_activity = (
|
|
IssueActivity.objects.filter(issue_id=issue_id)
|
|
.order_by("-created_at")
|
|
.first()
|
|
)
|
|
|
|
actor = User.objects.get(pk=actor_id)
|
|
|
|
for mention_id in comment_mentions:
|
|
if (mention_id != actor_id):
|
|
for issue_activity in issue_activities_created:
|
|
notification = createMentionNotification(
|
|
project=project,
|
|
issue=issue,
|
|
notification_comment=f"{actor.display_name} has mentioned you in a comment in issue {issue.name}",
|
|
actor_id=actor_id,
|
|
mention_id=mention_id,
|
|
issue_id=issue_id,
|
|
activity=issue_activity
|
|
)
|
|
bulk_notifications.append(notification)
|
|
|
|
|
|
for mention_id in new_mentions:
|
|
if (mention_id != actor_id):
|
|
if (
|
|
last_activity is not None
|
|
and last_activity.field == "description"
|
|
and actor_id == str(last_activity.actor_id)
|
|
):
|
|
bulk_notifications.append(
|
|
Notification(
|
|
workspace=project.workspace,
|
|
sender="in_app:issue_activities:mentioned",
|
|
triggered_by_id=actor_id,
|
|
receiver_id=mention_id,
|
|
entity_identifier=issue_id,
|
|
entity_name="issue",
|
|
project=project,
|
|
message=f"You have been mentioned in the issue {issue.name}",
|
|
data={
|
|
"issue": {
|
|
"id": str(issue_id),
|
|
"name": str(issue.name),
|
|
"identifier": str(issue.project.identifier),
|
|
"sequence_id": issue.sequence_id,
|
|
"state_name": issue.state.name,
|
|
"state_group": issue.state.group,
|
|
},
|
|
"issue_activity": {
|
|
"id": str(last_activity.id),
|
|
"verb": str(last_activity.verb),
|
|
"field": str(last_activity.field),
|
|
"actor": str(last_activity.actor_id),
|
|
"new_value": str(last_activity.new_value),
|
|
"old_value": str(last_activity.old_value),
|
|
},
|
|
},
|
|
)
|
|
)
|
|
else:
|
|
for issue_activity in issue_activities_created:
|
|
notification = createMentionNotification(
|
|
project=project,
|
|
issue=issue,
|
|
notification_comment=f"You have been mentioned in the issue {issue.name}",
|
|
actor_id=actor_id,
|
|
mention_id=mention_id,
|
|
issue_id=issue_id,
|
|
activity=issue_activity
|
|
)
|
|
bulk_notifications.append(notification)
|
|
|
|
# save new mentions for the particular issue and remove the mentions that has been deleted from the description
|
|
update_mentions_for_issue(issue=issue, project=project, new_mentions=new_mentions,
|
|
removed_mention=removed_mention)
|
|
|
|
# Bulk create notifications
|
|
Notification.objects.bulk_create(bulk_notifications, batch_size=100)
|
|
|
|
|