diff --git a/src/apps/api/tests/test_submissions.py b/src/apps/api/tests/test_submissions.py index e91a64ecb..2ad0553a2 100644 --- a/src/apps/api/tests/test_submissions.py +++ b/src/apps/api/tests/test_submissions.py @@ -26,9 +26,17 @@ def setUp(self): # Extra dummy user to test permissions, they shouldn't have access to many things self.other_user = UserFactory(username='other_user', password='other') - # Make a participant and submission into competition - self.participant = UserFactory(username='participant', password='other') - CompetitionParticipantFactory(user=self.participant, competition=self.comp) + # Make participants + self.participant = UserFactory(username='participant_approved', password='other') + self.pending_participant = UserFactory(username='participant_pending', password='other') + self.denied_participant = UserFactory(username='participant_denied', password='other') + + # Add user as participants in a competition with different statuses + CompetitionParticipantFactory(user=self.participant, competition=self.comp, status=CompetitionParticipant.APPROVED) + CompetitionParticipantFactory(user=self.pending_participant, competition=self.comp, status=CompetitionParticipant.PENDING) + CompetitionParticipantFactory(user=self.denied_participant, competition=self.comp, status=CompetitionParticipant.DENIED) + + # add submission with owner = approved participant self.existing_submission = SubmissionFactory( phase=self.phase, owner=self.participant, @@ -232,11 +240,21 @@ def test_who_can_see_detailed_result_when_visualization_is_true(self): resp = self.client.get(url) assert resp.status_code == 200 - # Actual user can see their submission detail result + # approved user can see submission detail result self.client.force_login(self.participant) resp = self.client.get(url) assert resp.status_code == 200 + # pending user cannot see submission detail result + self.client.force_login(self.pending_participant) + resp = self.client.get(url) + assert resp.status_code == 403 + + # denied user cannot see submission detail result + self.client.force_login(self.denied_participant) + resp = self.client.get(url) + assert resp.status_code == 403 + # Regular user cannot see submission detail result self.client.force_login(self.other_user) resp = self.client.get(url) diff --git a/src/apps/api/views/submissions.py b/src/apps/api/views/submissions.py index fccaeefd4..e52034493 100644 --- a/src/apps/api/views/submissions.py +++ b/src/apps/api/views/submissions.py @@ -325,14 +325,14 @@ def get_detail_result(self, request, pk): submission = Submission.objects.get(pk=pk) # Check if competition show visualization is true if submission.phase.competition.enable_detailed_results: - # get submission's competition participants - participants = submission.phase.competition.participants.all() - participant_usernames = [participant.user.username for participant in participants] + # get submission's competition approved participants + approved_participants = submission.phase.competition.participants.filter(status=CompetitionParticipant.APPROVED) + participant_usernames = [participant.user.username for participant in approved_participants] # check if in this competition # user is collaborator # or - # user is participant + # user is approved participant # or # user is creator # or diff --git a/src/static/riot/competitions/detail/leaderboards.tag b/src/static/riot/competitions/detail/leaderboards.tag index 95b4fc793..7ddef46ea 100644 --- a/src/static/riot/competitions/detail/leaderboards.tag +++ b/src/static/riot/competitions/detail/leaderboards.tag @@ -41,7 +41,32 @@ - + + + + + You are not a participant of this competition. Please register in My Submissions tab to view the leaderboard. + + + + + + + + Your request to participate in this competition is waiting for an approval from the competition organizer. + + + + + + + + Your request to participate in this competition is denied. Please contact the competition organizer for more details. + + + + + No submissions have been added to this leaderboard yet! @@ -71,6 +96,7 @@ +