Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions src/apps/api/tests/test_submissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions src/apps/api/views/submissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 28 additions & 1 deletion src/static/riot/competitions/detail/leaderboards.tag
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,32 @@

</tr>
</thead>
<tbody>
<!-- Show when particpant is not registered -->
<tbody if="{participant_status === null}">
<tr class="center aligned ui yellow message">
<td colspan="100%">
<em>You are not a participant of this competition. Please register in My Submissions tab to view the leaderboard.</em>
</td>
</tr>
</tbody>
<!-- Show when particpant registration is pending -->
<tbody if="{participant_status === 'pending'}">
<tr class="center aligned ui yellow message">
<td colspan="100%">
<em>Your request to participate in this competition is waiting for an approval from the competition organizer.</em>
</td>
</tr>
</tbody>
<!-- Show when particpant registration is denied -->
<tbody if="{participant_status === 'denied'}">
<tr class="center aligned ui red message">
<td colspan="100%">
<em>Your request to participate in this competition is denied. Please contact the competition organizer for more details.</em>
</td>
</tr>
</tbody>
<!-- Show when particpant registration is approved -->
<tbody if="{participant_status === 'approved'}">
<tr if="{_.isEmpty(selected_leaderboard.submissions)}" class="center aligned">
<td colspan="100%">
<em>No submissions have been added to this leaderboard yet!</em>
Expand Down Expand Up @@ -71,6 +96,7 @@
</tbody>
</table>


<script>
let self = this
self.selected_leaderboard = {}
Expand Down Expand Up @@ -201,6 +227,7 @@

CODALAB.events.on('competition_loaded', (competition) => {
self.competition_id = competition.id
self.participant_status = competition.participant_status
self.opts.is_admin ? self.show_download = "visible": self.show_download = "hidden"
self.enable_detailed_results = competition.enable_detailed_results
self.show_detailed_results_in_leaderboard = competition.show_detailed_results_in_leaderboard
Expand Down