From e9321a66e7750768c5bd50352315f4897acc61bb Mon Sep 17 00:00:00 2001 From: Bavisetti Narayan <72156168+NarayanBavisetti@users.noreply.github.com> Date: Wed, 1 Nov 2023 17:20:55 +0530 Subject: [PATCH] chore: added validation for archived issue (#2593) * chore: added validation for archived issue * fix: optimised code --- apiserver/plane/api/views/issue.py | 28 ++++----- .../plane/bgtasks/issue_activites_task.py | 57 ++++++++++--------- .../plane/bgtasks/issue_automation_task.py | 4 +- 3 files changed, 42 insertions(+), 47 deletions(-) diff --git a/apiserver/plane/api/views/issue.py b/apiserver/plane/api/views/issue.py index 99f2de2c2..ae785578f 100644 --- a/apiserver/plane/api/views/issue.py +++ b/apiserver/plane/api/views/issue.py @@ -235,10 +235,7 @@ class IssueViewSet(BaseViewSet): status=status.HTTP_200_OK, ) - return Response( - issues, status=status.HTTP_200_OK - ) - + return Response(issues, status=status.HTTP_200_OK) def create(self, request, slug, project_id): project = Project.objects.get(pk=project_id) @@ -443,9 +440,7 @@ class UserWorkSpaceIssues(BaseAPIView): status=status.HTTP_200_OK, ) - return Response( - issues, status=status.HTTP_200_OK - ) + return Response(issues, status=status.HTTP_200_OK) class WorkSpaceIssuesEndpoint(BaseAPIView): @@ -623,13 +618,12 @@ class IssueUserDisplayPropertyEndpoint(BaseAPIView): serializer = IssuePropertySerializer(issue_property) return Response(serializer.data, status=status.HTTP_201_CREATED) - def get(self, request, slug, project_id): - issue_property, _ = IssueProperty.objects.get_or_create( - user=request.user, project_id=project_id - ) - serializer = IssuePropertySerializer(issue_property) - return Response(serializer.data, status=status.HTTP_200_OK) + issue_property, _ = IssueProperty.objects.get_or_create( + user=request.user, project_id=project_id + ) + serializer = IssuePropertySerializer(issue_property) + return Response(serializer.data, status=status.HTTP_200_OK) class LabelViewSet(BaseViewSet): @@ -1100,7 +1094,9 @@ class IssueArchiveViewSet(BaseViewSet): actor_id=str(request.user.id), issue_id=str(issue.id), project_id=str(project_id), - current_instance=None, + current_instance=json.dumps( + IssueSerializer(issue).data, cls=DjangoJSONEncoder + ), epoch=int(timezone.now().timestamp()), ) @@ -2160,9 +2156,7 @@ class IssueDraftViewSet(BaseViewSet): status=status.HTTP_200_OK, ) - return Response( - issues, status=status.HTTP_200_OK - ) + return Response(issues, status=status.HTTP_200_OK) def create(self, request, slug, project_id): project = Project.objects.get(pk=project_id) diff --git a/apiserver/plane/bgtasks/issue_activites_task.py b/apiserver/plane/bgtasks/issue_activites_task.py index 03e9d09e9..b1277cb3d 100644 --- a/apiserver/plane/bgtasks/issue_activites_task.py +++ b/apiserver/plane/bgtasks/issue_activites_task.py @@ -418,36 +418,37 @@ def track_archive_at( issue_activities, epoch, ): - 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=f"has restored the issue", - verb="updated", - actor_id=actor_id, - field="archived_at", - old_value="archive", - new_value="restore", - epoch=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=f"Plane has archived the issue", - verb="updated", - actor_id=actor_id, - field="archived_at", - old_value=None, - new_value="archive", - 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( diff --git a/apiserver/plane/bgtasks/issue_automation_task.py b/apiserver/plane/bgtasks/issue_automation_task.py index 68c64403a..b2f7476a5 100644 --- a/apiserver/plane/bgtasks/issue_automation_task.py +++ b/apiserver/plane/bgtasks/issue_automation_task.py @@ -71,14 +71,14 @@ def archive_old_issues(): Issue.objects.bulk_update( issues_to_update, ["archived_at"], batch_size=100 ) - [ + _ = [ issue_activity.delay( type="issue.activity.updated", requested_data=json.dumps({"archived_at": str(archive_at)}), actor_id=str(project.created_by_id), issue_id=issue.id, project_id=project_id, - current_instance=None, + current_instance=json.dumps({"archived_at": None}), subscriber=False, epoch=int(timezone.now().timestamp()) )