chore: api fixes

This commit is contained in:
NarayanBavisetti 2023-11-22 15:31:29 +05:30
parent 065fee9420
commit 174bf70cce
12 changed files with 63 additions and 50 deletions

View File

@ -308,5 +308,5 @@ class IssueActivitySerializer(BaseSerializer):
model = IssueActivity model = IssueActivity
exclude = [ exclude = [
"created_by", "created_by",
"udpated_by", "updated_by",
] ]

View File

@ -23,7 +23,7 @@ urlpatterns = [
name="cycle-issues", name="cycle-issues",
), ),
path( path(
"workspaces/<str:slug>/projects/<uuid:project_id>/cycles/<uuid:cycle_id>/cycle-issues/<uuid:pk>/", "workspaces/<str:slug>/projects/<uuid:project_id>/cycles/<uuid:cycle_id>/cycle-issues/<uuid:issue_id>/",
CycleIssueAPIEndpoint.as_view(), CycleIssueAPIEndpoint.as_view(),
name="cycle-issues", name="cycle-issues",
), ),

View File

@ -20,22 +20,22 @@ urlpatterns = [
name="issue", name="issue",
), ),
path( path(
"workspaces/<str:slug>/projects/<uuid:project_id>/issue-labels/", "workspaces/<str:slug>/projects/<uuid:project_id>/labels/",
LabelAPIEndpoint.as_view(), LabelAPIEndpoint.as_view(),
name="label", name="label",
), ),
path( path(
"workspaces/<str:slug>/projects/<uuid:project_id>/issue-labels/<uuid:pk>/", "workspaces/<str:slug>/projects/<uuid:project_id>/labels/<uuid:pk>/",
LabelAPIEndpoint.as_view(), LabelAPIEndpoint.as_view(),
name="label", name="label",
), ),
path( path(
"workspaces/<str:slug>/projects/<uuid:project_id>/issues/<uuid:issue_id>/issue-links/", "workspaces/<str:slug>/projects/<uuid:project_id>/issues/<uuid:issue_id>/links/",
IssueLinkAPIEndpoint.as_view(), IssueLinkAPIEndpoint.as_view(),
name="link", name="link",
), ),
path( path(
"workspaces/<str:slug>/projects/<uuid:project_id>/issues/<uuid:issue_id>/issue-links/<uuid:pk>/", "workspaces/<str:slug>/projects/<uuid:project_id>/issues/<uuid:issue_id>/links/<uuid:pk>/",
IssueLinkAPIEndpoint.as_view(), IssueLinkAPIEndpoint.as_view(),
name="link", name="link",
), ),
@ -50,12 +50,12 @@ urlpatterns = [
name="comment", name="comment",
), ),
path( path(
"workspaces/<str:slug>/projects/<uuid:project_id>/issues/<uuid:issue_id>/activites/", "workspaces/<str:slug>/projects/<uuid:project_id>/issues/<uuid:issue_id>/activities/",
IssueActivityAPIEndpoint.as_view(), IssueActivityAPIEndpoint.as_view(),
name="activity", name="activity",
), ),
path( path(
"workspaces/<str:slug>/projects/<uuid:project_id>/issues/<uuid:issue_id>/activites/<uuid:pk>/", "workspaces/<str:slug>/projects/<uuid:project_id>/issues/<uuid:issue_id>/activities/<uuid:pk>/",
IssueActivityAPIEndpoint.as_view(), IssueActivityAPIEndpoint.as_view(),
name="activity", name="activity",
), ),

View File

@ -19,7 +19,7 @@ urlpatterns = [
name="module-issues", name="module-issues",
), ),
path( path(
"workspaces/<str:slug>/projects/<uuid:project_id>/modules/<uuid:module_id>/module-issues/<uuid:pk>/", "workspaces/<str:slug>/projects/<uuid:project_id>/modules/<uuid:module_id>/module-issues/<uuid:issue_id>/",
ModuleIssueAPIEndpoint.as_view(), ModuleIssueAPIEndpoint.as_view(),
name="module-issues", name="module-issues",
), ),

View File

@ -8,4 +8,9 @@ urlpatterns = [
StateAPIEndpoint.as_view(), StateAPIEndpoint.as_view(),
name="states", name="states",
), ),
path(
"workspaces/<str:slug>/projects/<uuid:project_id>/states/<uuid:state_id>/",
StateAPIEndpoint.as_view(),
name="states",
),
] ]

View File

@ -291,7 +291,7 @@ class CycleAPIEndpoint(WebhookMixin, BaseAPIView):
} }
), ),
actor_id=str(request.user.id), actor_id=str(request.user.id),
issue_id=str(pk), issue_id=None,
project_id=str(project_id), project_id=str(project_id),
current_instance=None, current_instance=None,
epoch=int(timezone.now().timestamp()), epoch=int(timezone.now().timestamp()),
@ -476,9 +476,9 @@ class CycleIssueAPIEndpoint(WebhookMixin, BaseAPIView):
status=status.HTTP_200_OK, status=status.HTTP_200_OK,
) )
def delete(self, request, slug, project_id, cycle_id, pk): def delete(self, request, slug, project_id, cycle_id, issue_id):
cycle_issue = CycleIssue.objects.get( cycle_issue = CycleIssue.objects.get(
pk=pk, workspace__slug=slug, project_id=project_id, cycle_id=cycle_id issue_id=issue_id, workspace__slug=slug, project_id=project_id, cycle_id=cycle_id
) )
issue_id = cycle_issue.issue_id issue_id = cycle_issue.issue_id
cycle_issue.delete() cycle_issue.delete()
@ -491,7 +491,7 @@ class CycleIssueAPIEndpoint(WebhookMixin, BaseAPIView):
} }
), ),
actor_id=str(self.request.user.id), actor_id=str(self.request.user.id),
issue_id=str(self.kwargs.get("pk", None)), issue_id=str(issue_id),
project_id=str(self.kwargs.get("project_id", None)), project_id=str(self.kwargs.get("project_id", None)),
current_instance=None, current_instance=None,
epoch=int(timezone.now().timestamp()), epoch=int(timezone.now().timestamp()),

View File

@ -352,11 +352,11 @@ class IssueLinkAPIEndpoint(BaseAPIView):
.distinct() .distinct()
) )
def get(self, request, slug, project_id, pk=None): def get(self, request, slug, project_id, issue_id, pk=None):
if pk is None: if pk is None:
labels = self.get_queryset() issue_links = self.get_queryset()
serializer = IssueLinkSerializer( serializer = IssueLinkSerializer(
labels, issue_links,
fields=self.fields, fields=self.fields,
expand=self.expand, expand=self.expand,
) )
@ -370,10 +370,9 @@ class IssueLinkAPIEndpoint(BaseAPIView):
expand=self.expand, expand=self.expand,
).data, ).data,
) )
else: issue_link = self.get_queryset().get(pk=pk)
label = self.get_queryset().get(pk=pk)
serializer = IssueLinkSerializer( serializer = IssueLinkSerializer(
label, issue_link,
fields=self.fields, fields=self.fields,
expand=self.expand, expand=self.expand,
) )
@ -590,7 +589,7 @@ class IssueActivityAPIEndpoint(BaseAPIView):
serializer = IssueActivitySerializer(issue_activities) serializer = IssueActivitySerializer(issue_activities)
return Response(serializer.data, status=status.HTTP_200_OK) return Response(serializer.data, status=status.HTTP_200_OK)
self.paginate( return self.paginate(
request=request, request=request,
queryset=(issue_activities), queryset=(issue_activities),
on_results=lambda issue_activity: IssueActivitySerializer( on_results=lambda issue_activity: IssueActivitySerializer(

View File

@ -130,6 +130,14 @@ class ModuleAPIEndpoint(WebhookMixin, BaseAPIView):
return Response(serializer.data, status=status.HTTP_201_CREATED) return Response(serializer.data, status=status.HTTP_201_CREATED)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def patch(self, request, slug, project_id, pk):
module = Module.objects.get(pk=pk, project_id=project_id, workspace__slug=slug)
serializer = ModuleSerializer(module, data=request.data)
if serializer.is_valid():
serializer.save()
return Response(serializer.data, status=status.HTTP_201_CREATED)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def get(self, request, slug, project_id, pk=None): def get(self, request, slug, project_id, pk=None):
if pk: if pk:
queryset = self.get_queryset().get(pk=pk) queryset = self.get_queryset().get(pk=pk)
@ -168,7 +176,7 @@ class ModuleAPIEndpoint(WebhookMixin, BaseAPIView):
} }
), ),
actor_id=str(request.user.id), actor_id=str(request.user.id),
issue_id=str(pk), issue_id=None,
project_id=str(project_id), project_id=str(project_id),
current_instance=None, current_instance=None,
epoch=int(timezone.now().timestamp()), epoch=int(timezone.now().timestamp()),
@ -323,7 +331,7 @@ class ModuleIssueAPIEndpoint(WebhookMixin, BaseAPIView):
# Capture Issue Activity # Capture Issue Activity
issue_activity.delay( issue_activity.delay(
type="module.activity.created", type="module.activity.created",
requested_data=json.dumps({"modules_list": issues}), requested_data=json.dumps({"modules_list": str(issues)}),
actor_id=str(self.request.user.id), actor_id=str(self.request.user.id),
issue_id=None, issue_id=None,
project_id=str(self.kwargs.get("project_id", None)), project_id=str(self.kwargs.get("project_id", None)),
@ -343,9 +351,9 @@ class ModuleIssueAPIEndpoint(WebhookMixin, BaseAPIView):
status=status.HTTP_200_OK, status=status.HTTP_200_OK,
) )
def delete(self, request, slug, project_id, module_id, pk): def delete(self, request, slug, project_id, module_id, issue_id):
module_issue = ModuleIssue.objects.get( module_issue = ModuleIssue.objects.get(
workspace__slug=slug, project_id=project_id, module_id=module_id, pk=pk workspace__slug=slug, project_id=project_id, module_id=module_id, issue_id=issue_id
) )
module_issue.delete() module_issue.delete()
issue_activity.delay( issue_activity.delay(
@ -357,7 +365,7 @@ class ModuleIssueAPIEndpoint(WebhookMixin, BaseAPIView):
} }
), ),
actor_id=str(request.user.id), actor_id=str(request.user.id),
issue_id=str(pk), issue_id=str(issue_id),
project_id=str(project_id), project_id=str(project_id),
current_instance=None, current_instance=None,
epoch=int(timezone.now().timestamp()), epoch=int(timezone.now().timestamp()),

View File

@ -23,10 +23,8 @@ class StateAPIEndpoint(BaseAPIView):
] ]
def get_queryset(self): def get_queryset(self):
return self.filter_queryset( return (
super() State.objects.filter(workspace__slug=self.kwargs.get("slug"))
.get_queryset()
.filter(workspace__slug=self.kwargs.get("slug"))
.filter(project_id=self.kwargs.get("project_id")) .filter(project_id=self.kwargs.get("project_id"))
.filter(project__project_projectmember__member=self.request.user) .filter(project__project_projectmember__member=self.request.user)
.filter(~Q(name="Triage")) .filter(~Q(name="Triage"))
@ -42,9 +40,9 @@ class StateAPIEndpoint(BaseAPIView):
return Response(serializer.data, status=status.HTTP_200_OK) return Response(serializer.data, status=status.HTTP_200_OK)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def get(self, request, slug, project_id, pk=None): def get(self, request, slug, project_id, state_id=None):
if pk: if state_id:
serializer = StateSerializer(self.get_queryset().get(pk=pk)) serializer = StateSerializer(self.get_queryset().get(pk=state_id))
return Response(serializer.data, status=status.HTTP_200_OK) return Response(serializer.data, status=status.HTTP_200_OK)
return self.paginate( return self.paginate(
request=request, request=request,
@ -57,10 +55,10 @@ class StateAPIEndpoint(BaseAPIView):
).data, ).data,
) )
def delete(self, request, slug, project_id, pk): def delete(self, request, slug, project_id, state_id):
state = State.objects.get( state = State.objects.get(
~Q(name="Triage"), ~Q(name="Triage"),
pk=pk, pk=state_id,
project_id=project_id, project_id=project_id,
workspace__slug=slug, workspace__slug=slug,
) )
@ -69,7 +67,7 @@ class StateAPIEndpoint(BaseAPIView):
return Response({"error": "Default state cannot be deleted"}, status=False) return Response({"error": "Default state cannot be deleted"}, status=False)
# Check for any issues in the state # Check for any issues in the state
issue_exist = Issue.issue_objects.filter(state=pk).exists() issue_exist = Issue.issue_objects.filter(state=state_id).exists()
if issue_exist: if issue_exist:
return Response( return Response(
@ -80,8 +78,8 @@ class StateAPIEndpoint(BaseAPIView):
state.delete() state.delete()
return Response(status=status.HTTP_204_NO_CONTENT) return Response(status=status.HTTP_204_NO_CONTENT)
def patch(self, request, slug, project_id, pk=None): def patch(self, request, slug, project_id, state_id=None):
state = State.objects.filter(workspace__slug=slug, project_id=project_id, pk=pk) state = State.objects.filter(workspace__slug=slug, project_id=project_id, pk=state_id)
serializer = StateSerializer(state, data=request.data, partial=True) serializer = StateSerializer(state, data=request.data, partial=True)
if serializer.is_valid(): if serializer.is_valid():
serializer.save() serializer.save()

View File

@ -46,19 +46,22 @@ class WebhookMixin:
def finalize_response(self, request, response, *args, **kwargs): def finalize_response(self, request, response, *args, **kwargs):
response = super().finalize_response(request, response, *args, **kwargs) response = super().finalize_response(request, response, *args, **kwargs)
if ( if (
self.webhook_event self.webhook_event
and self.request.method in ["POST", "PATCH", "DELETE"] and self.request.method in ["POST", "PATCH"]
and response.status_code in [200, 201, 204] and response.status_code in [200, 201, 204]
): ):
# Get the id
object_id = (
response.data.get("id") if isinstance(response.data, dict) else None
)
send_webhook.delay( send_webhook.delay(
event=self.webhook_event, event=self.webhook_event,
event_data=json.dumps(response.data, cls=DjangoJSONEncoder), event_id=object_id,
action=self.request.method, action=self.request.method,
slug=self.workspace_slug, slug=self.workspace_slug,
) )
return response return response

View File

@ -688,7 +688,6 @@ class CycleIssueViewSet(WebhookMixin, BaseViewSet):
pk=pk, workspace__slug=slug, project_id=project_id, cycle_id=cycle_id pk=pk, workspace__slug=slug, project_id=project_id, cycle_id=cycle_id
) )
issue_id = cycle_issue.issue_id issue_id = cycle_issue.issue_id
cycle_issue.delete()
issue_activity.delay( issue_activity.delay(
type="cycle.activity.deleted", type="cycle.activity.deleted",
requested_data=json.dumps( requested_data=json.dumps(
@ -698,11 +697,12 @@ class CycleIssueViewSet(WebhookMixin, BaseViewSet):
} }
), ),
actor_id=str(self.request.user.id), actor_id=str(self.request.user.id),
issue_id=str(self.kwargs.get("pk", None)), issue_id=str(cycle_issue.issue_id),
project_id=str(self.kwargs.get("project_id", None)), project_id=str(self.kwargs.get("project_id", None)),
current_instance=None, current_instance=None,
epoch=int(timezone.now().timestamp()), epoch=int(timezone.now().timestamp()),
) )
cycle_issue.delete()
return Response(status=status.HTTP_204_NO_CONTENT) return Response(status=status.HTTP_204_NO_CONTENT)

View File

@ -461,7 +461,6 @@ class ModuleIssueViewSet(BaseViewSet):
module_issue = ModuleIssue.objects.get( module_issue = ModuleIssue.objects.get(
workspace__slug=slug, project_id=project_id, module_id=module_id, pk=pk workspace__slug=slug, project_id=project_id, module_id=module_id, pk=pk
) )
module_issue.delete()
issue_activity.delay( issue_activity.delay(
type="module.activity.deleted", type="module.activity.deleted",
requested_data=json.dumps( requested_data=json.dumps(
@ -471,11 +470,12 @@ class ModuleIssueViewSet(BaseViewSet):
} }
), ),
actor_id=str(request.user.id), actor_id=str(request.user.id),
issue_id=str(pk), issue_id=str(module_issue.issue_id),
project_id=str(project_id), project_id=str(project_id),
current_instance=None, current_instance=None,
epoch=int(timezone.now().timestamp()), epoch=int(timezone.now().timestamp()),
) )
module_issue.delete()
return Response(status=status.HTTP_204_NO_CONTENT) return Response(status=status.HTTP_204_NO_CONTENT)