Compare commits

...

3 Commits

Author SHA1 Message Date
NarayanBavisetti
5dce9e0434 chore: unarchived issue message corrected 2023-11-01 18:16:44 +05:30
NarayanBavisetti
2a3872077c fix: optimised code 2023-11-01 17:18:11 +05:30
NarayanBavisetti
2b764163bf chore: added validation for archived issue 2023-11-01 17:12:44 +05:30
3 changed files with 44 additions and 49 deletions

View File

@ -235,10 +235,7 @@ class IssueViewSet(BaseViewSet):
status=status.HTTP_200_OK, status=status.HTTP_200_OK,
) )
return Response( return Response(issues, status=status.HTTP_200_OK)
issues, status=status.HTTP_200_OK
)
def create(self, request, slug, project_id): def create(self, request, slug, project_id):
project = Project.objects.get(pk=project_id) project = Project.objects.get(pk=project_id)
@ -443,9 +440,7 @@ class UserWorkSpaceIssues(BaseAPIView):
status=status.HTTP_200_OK, status=status.HTTP_200_OK,
) )
return Response( return Response(issues, status=status.HTTP_200_OK)
issues, status=status.HTTP_200_OK
)
class WorkSpaceIssuesEndpoint(BaseAPIView): class WorkSpaceIssuesEndpoint(BaseAPIView):
@ -623,13 +618,12 @@ class IssueUserDisplayPropertyEndpoint(BaseAPIView):
serializer = IssuePropertySerializer(issue_property) serializer = IssuePropertySerializer(issue_property)
return Response(serializer.data, status=status.HTTP_201_CREATED) return Response(serializer.data, status=status.HTTP_201_CREATED)
def get(self, request, slug, project_id): def get(self, request, slug, project_id):
issue_property, _ = IssueProperty.objects.get_or_create( issue_property, _ = IssueProperty.objects.get_or_create(
user=request.user, project_id=project_id user=request.user, project_id=project_id
) )
serializer = IssuePropertySerializer(issue_property) serializer = IssuePropertySerializer(issue_property)
return Response(serializer.data, status=status.HTTP_200_OK) return Response(serializer.data, status=status.HTTP_200_OK)
class LabelViewSet(BaseViewSet): class LabelViewSet(BaseViewSet):
@ -1092,17 +1086,19 @@ class IssueArchiveViewSet(BaseViewSet):
archived_at__isnull=False, archived_at__isnull=False,
pk=pk, pk=pk,
) )
issue.archived_at = None
issue.save()
issue_activity.delay( issue_activity.delay(
type="issue.activity.updated", type="issue.activity.updated",
requested_data=json.dumps({"archived_at": None}), requested_data=json.dumps({"archived_at": None}),
actor_id=str(request.user.id), actor_id=str(request.user.id),
issue_id=str(issue.id), issue_id=str(issue.id),
project_id=str(project_id), project_id=str(project_id),
current_instance=None, current_instance=json.dumps(
IssueSerializer(issue).data, cls=DjangoJSONEncoder
),
epoch=int(timezone.now().timestamp()), epoch=int(timezone.now().timestamp()),
) )
issue.archived_at = None
issue.save()
return Response(IssueSerializer(issue).data, status=status.HTTP_200_OK) return Response(IssueSerializer(issue).data, status=status.HTTP_200_OK)
@ -2160,9 +2156,7 @@ class IssueDraftViewSet(BaseViewSet):
status=status.HTTP_200_OK, status=status.HTTP_200_OK,
) )
return Response( return Response(issues, status=status.HTTP_200_OK)
issues, status=status.HTTP_200_OK
)
def create(self, request, slug, project_id): def create(self, request, slug, project_id):
project = Project.objects.get(pk=project_id) project = Project.objects.get(pk=project_id)

View File

@ -418,36 +418,37 @@ def track_archive_at(
issue_activities, issue_activities,
epoch, epoch,
): ):
if requested_data.get("archived_at") is None: if current_instance.get("archived_at") != requested_data.get("archived_at"):
issue_activities.append( if requested_data.get("archived_at") is None:
IssueActivity( issue_activities.append(
issue_id=issue_id, IssueActivity(
project_id=project_id, issue_id=issue_id,
workspace_id=workspace_id, project_id=project_id,
comment=f"has restored the issue", workspace_id=workspace_id,
verb="updated", comment="has restored the issue",
actor_id=actor_id, verb="updated",
field="archived_at", actor_id=actor_id,
old_value="archive", field="archived_at",
new_value="restore", old_value="archive",
epoch=epoch, new_value="restore",
epoch=epoch,
)
) )
) else:
else: issue_activities.append(
issue_activities.append( IssueActivity(
IssueActivity( issue_id=issue_id,
issue_id=issue_id, project_id=project_id,
project_id=project_id, workspace_id=workspace_id,
workspace_id=workspace_id, comment="Plane has archived the issue",
comment=f"Plane has archived the issue", verb="updated",
verb="updated", actor_id=actor_id,
actor_id=actor_id, field="archived_at",
field="archived_at", old_value=None,
old_value=None, new_value="archive",
new_value="archive", epoch=epoch,
epoch=epoch, )
) )
)
def track_closed_to( def track_closed_to(

View File

@ -71,14 +71,14 @@ def archive_old_issues():
Issue.objects.bulk_update( Issue.objects.bulk_update(
issues_to_update, ["archived_at"], batch_size=100 issues_to_update, ["archived_at"], batch_size=100
) )
[ _ = [
issue_activity.delay( issue_activity.delay(
type="issue.activity.updated", type="issue.activity.updated",
requested_data=json.dumps({"archived_at": str(archive_at)}), requested_data=json.dumps({"archived_at": str(archive_at)}),
actor_id=str(project.created_by_id), actor_id=str(project.created_by_id),
issue_id=issue.id, issue_id=issue.id,
project_id=project_id, project_id=project_id,
current_instance=None, current_instance=json.dumps({"archived_at": None}),
subscriber=False, subscriber=False,
epoch=int(timezone.now().timestamp()) epoch=int(timezone.now().timestamp())
) )