-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[WEB-2043] chore: updated permissions for delete operation #5231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -47,6 +47,7 @@ | |||||||||||||||||||||||||
| Label, | ||||||||||||||||||||||||||
| User, | ||||||||||||||||||||||||||
| Project, | ||||||||||||||||||||||||||
| ProjectMember, | ||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||
| from plane.utils.analytics_plot import burndown_plot | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
|
@@ -1039,14 +1040,28 @@ def retrieve(self, request, slug, project_id, pk): | |||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| def destroy(self, request, slug, project_id, pk): | ||||||||||||||||||||||||||
| cycle = Cycle.objects.get( | ||||||||||||||||||||||||||
| workspace__slug=slug, project_id=project_id, pk=pk | ||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||
|
Comment on lines
+1043
to
+1045
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure proper exception handling for Using - cycle = Cycle.objects.get(
+ try:
+ cycle = Cycle.objects.get(
+ workspace__slug=slug, project_id=project_id, pk=pk
+ )
+ except Cycle.DoesNotExist:
+ return Response(
+ {"error": "Cycle not found"},
+ status=status.HTTP_404_NOT_FOUND,
+ )Committable suggestion
Suggested change
|
||||||||||||||||||||||||||
| if cycle.owned_by_id != request.user.id and not ( | ||||||||||||||||||||||||||
| ProjectMember.objects.filter( | ||||||||||||||||||||||||||
| workspace__slug=slug, | ||||||||||||||||||||||||||
| member=request.user, | ||||||||||||||||||||||||||
| role=20, | ||||||||||||||||||||||||||
| project_id=project_id, | ||||||||||||||||||||||||||
| is_active=True, | ||||||||||||||||||||||||||
| ).exists() | ||||||||||||||||||||||||||
| ): | ||||||||||||||||||||||||||
| return Response( | ||||||||||||||||||||||||||
| {"error": "Only admin or owner can delete the cycle"}, | ||||||||||||||||||||||||||
| status=status.HTTP_403_FORBIDDEN, | ||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| cycle_issues = list( | ||||||||||||||||||||||||||
| CycleIssue.objects.filter( | ||||||||||||||||||||||||||
| cycle_id=self.kwargs.get("pk") | ||||||||||||||||||||||||||
| ).values_list("issue", flat=True) | ||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||
| cycle = Cycle.objects.get( | ||||||||||||||||||||||||||
| workspace__slug=slug, project_id=project_id, pk=pk | ||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| issue_activity.delay( | ||||||||||||||||||||||||||
| type="cycle.activity.deleted", | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensure the issue exists before proceeding with deletion.
Add a check to ensure the issue exists before proceeding with the deletion logic to avoid potential errors.
Committable suggestion