Skip to content

Commit f1c9ddd

Browse files
committed
missing condition added, new test added for missing condition
1 parent 7b68de9 commit f1c9ddd

2 files changed

Lines changed: 13 additions & 7 deletions

File tree

src/apps/api/tests/test_submissions.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,14 @@ def test_super_user_can_delete_submission_you_created(self):
129129
assert resp.status_code == 204
130130
assert not Submission.objects.filter(pk=self.existing_submission.pk).exists()
131131

132+
def test_super_user_can_delete_leaderboard_submission_you_created(self):
133+
url = reverse('submission-detail', args=(self.leaderboard_submission.pk,))
134+
135+
self.client.force_login(self.superuser)
136+
resp = self.client.delete(url)
137+
assert resp.status_code == 204
138+
assert not Submission.objects.filter(pk=self.leaderboard_submission.pk).exists()
139+
132140
def test_cannot_delete_leaderboard_submission_you_created(self):
133141
url = reverse('submission-detail', args=(self.leaderboard_submission.pk,))
134142

src/apps/api/views/submissions.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -199,23 +199,21 @@ def create(self, request, *args, **kwargs):
199199

200200
def destroy(self, request, *args, **kwargs):
201201
"""
202-
- If a user is owner of a submission and submission is not on the leaderboard, user can delete the submission using the delete API
203-
- If a user is either super user or admin of the competition of the submission, user can delete the submission
204202
- If user is neither owner nor admin, user cannot delete the submission
203+
- If a user is not admin and is owner of a submission and submission is on the leaderboard, user cannot delete the submission
204+
- In rest of the cases i.e. user is admin/super user or user is owner of the submisison and submission is not on the leaderboard, user can delete the submisison
205205
"""
206206
submission = self.get_object()
207207

208208
is_owner = request.user == submission.owner
209209
is_super_user_or_competition_admin = self.has_admin_permission(request.user, submission)
210210

211-
# If user is neither owner nor super user/admin
212-
# return permission denied
211+
# If user is neither owner nor super user/admin return permission denied
213212
if not is_owner and not is_super_user_or_competition_admin:
214213
raise PermissionDenied("You do not have permission to delete this submission!")
215214

216-
# If user is owner but submission is on the leaderboard
217-
# return permission denied
218-
if is_owner and submission.leaderboard:
215+
# If user is not admin, is owner and submission is on the leaderboard return permission denied
216+
if not is_super_user_or_competition_admin and is_owner and submission.leaderboard:
219217
raise PermissionDenied("You cannot delete a leaderboard submission!")
220218

221219
# Otherwise, delete the submission

0 commit comments

Comments
 (0)