From caca2bb548b664c45af7b5cf0bd6f4a8b34d0f74 Mon Sep 17 00:00:00 2001 From: Bavisetti Narayan <72156168+NarayanBavisetti@users.noreply.github.com> Date: Thu, 2 Nov 2023 19:32:44 +0530 Subject: [PATCH] chore: bug fixes (#2609) * chore: sub issue activity task * fix: mentions and issue comment * chore: added string for issue * chore: changed sub issue id --- apiserver/plane/api/views/issue.py | 14 ++++++++ .../plane/bgtasks/issue_activites_task.py | 32 +++++++++---------- apiserver/plane/bgtasks/notification_task.py | 19 ++++++++--- 3 files changed, 45 insertions(+), 20 deletions(-) diff --git a/apiserver/plane/api/views/issue.py b/apiserver/plane/api/views/issue.py index 2443e0752..ff7f52691 100644 --- a/apiserver/plane/api/views/issue.py +++ b/apiserver/plane/api/views/issue.py @@ -773,6 +773,20 @@ class SubIssuesEndpoint(BaseAPIView): updated_sub_issues = Issue.issue_objects.filter(id__in=sub_issue_ids) + # Track the issue + _ = [ + issue_activity.delay( + type="issue.activity.updated", + requested_data=json.dumps({"parent": str(issue_id)}), + actor_id=str(request.user.id), + issue_id=str(sub_issue_id), + project_id=str(project_id), + current_instance=json.dumps({"parent": str(sub_issue_id)}), + epoch=int(timezone.now().timestamp()), + ) + for sub_issue_id in sub_issue_ids + ] + return Response( IssueFlatSerializer(updated_sub_issues, many=True).data, status=status.HTTP_200_OK, diff --git a/apiserver/plane/bgtasks/issue_activites_task.py b/apiserver/plane/bgtasks/issue_activites_task.py index bfdb4b498..f0a20eeec 100644 --- a/apiserver/plane/bgtasks/issue_activites_task.py +++ b/apiserver/plane/bgtasks/issue_activites_task.py @@ -131,7 +131,7 @@ def track_parent( else "", field="parent", project_id=project_id, - workspace=workspace_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, @@ -334,9 +334,7 @@ def track_assignees( issue_activities, epoch, ): - requested_assignees = set( - [str(asg) for asg in requested_data.get("assignees", [])] - ) + 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 @@ -363,17 +361,19 @@ def track_assignees( for dropped_assignee in dropped_assginees: assignee = User.objects.get(pk=dropped_assignee) issue_activities.append( - 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, + 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, + ) ) @@ -1536,7 +1536,7 @@ def issue_activity( cls=DjangoJSONEncoder, ), requested_data=requested_data, - current_instance=current_instance + current_instance=current_instance, ) return diff --git a/apiserver/plane/bgtasks/notification_task.py b/apiserver/plane/bgtasks/notification_task.py index c95e941ef..4380f4ee9 100644 --- a/apiserver/plane/bgtasks/notification_task.py +++ b/apiserver/plane/bgtasks/notification_task.py @@ -5,7 +5,16 @@ import json from django.utils import timezone # Module imports -from plane.db.models import IssueMention, IssueSubscriber, Project, User, IssueAssignee, Issue, Notification +from plane.db.models import ( + IssueMention, + IssueSubscriber, + Project, + User, + IssueAssignee, + Issue, + Notification, + IssueComment, +) # Third Party imports from celery import shared_task @@ -165,6 +174,9 @@ def notifications(type, issue_id, project_id, actor_id, subscriber, issue_activi for subscriber in list(set(issue_subscribers)): for issue_activity in issue_activities_created: + 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, @@ -192,8 +204,7 @@ def notifications(type, issue_id, project_id, actor_id, subscriber, issue_activi "new_value": str(issue_activity.get("new_value")), "old_value": str(issue_activity.get("old_value")), "issue_comment": str( - issue_activity.get( - "issue_comment").comment_stripped + issue_comment.comment_stripped if issue_activity.get("issue_comment") is not None else "" ), @@ -257,7 +268,7 @@ def notifications(type, issue_id, project_id, actor_id, subscriber, issue_activi IssueMention.objects.bulk_create( aggregated_issue_mentions, batch_size=100) IssueMention.objects.filter( - issue=issue.id, mention__in=removed_mention).delete() + issue=issue, mention__in=removed_mention).delete() # Bulk create notifications Notification.objects.bulk_create(bulk_notifications, batch_size=100)