From 2f7ffb34c052d58e7a99f806e35a0e6959de13b9 Mon Sep 17 00:00:00 2001 From: Ram Ramrakhya Date: Fri, 3 Sep 2021 00:59:18 -0400 Subject: [PATCH] Backend+Frontend: Fetch public leaderboard when user is not authenticated(#3590) --- apps/jobs/views.py | 12 ++++----- frontend/src/js/controllers/challengeCtrl.js | 28 ++++++-------------- 2 files changed, 14 insertions(+), 26 deletions(-) diff --git a/apps/jobs/views.py b/apps/jobs/views.py index 94caacd3ad..68e4f8d1bc 100644 --- a/apps/jobs/views.py +++ b/apps/jobs/views.py @@ -493,7 +493,7 @@ def change_submission_data_and_visibility( @swagger_auto_schema( - methods=["get", "post"], + methods=["get"], manual_parameters=[ openapi.Parameter( name="challenge_phase_split_id", @@ -563,7 +563,7 @@ def change_submission_data_and_visibility( ) }, ) -@api_view(["GET", "POST"]) +@api_view(["GET"]) @throttle_classes([AnonRateThrottle]) def leaderboard(request, challenge_phase_split_id): """ @@ -581,7 +581,7 @@ def leaderboard(request, challenge_phase_split_id): challenge_phase_split_id ) challenge_obj = challenge_phase_split.challenge_phase.challenge - order_by = request.data.get("order_by") + order_by = request.GET.get("order_by") ( response_data, http_status_code, @@ -604,7 +604,7 @@ def leaderboard(request, challenge_phase_split_id): @swagger_auto_schema( - methods=["get", "post"], + methods=["get"], manual_parameters=[ openapi.Parameter( name="challenge_phase_split_pk", @@ -730,7 +730,7 @@ def leaderboard(request, challenge_phase_split_id): ), }, ) -@api_view(["GET", "POST"]) +@api_view(["GET"]) @throttle_classes([AnonRateThrottle]) @permission_classes((permissions.IsAuthenticated, HasVerifiedEmail)) @authentication_classes((JWTAuthentication, ExpiringTokenAuthentication)) @@ -794,7 +794,7 @@ def get_all_entries_on_public_leaderboard(request, challenge_phase_split_pk): "error": "Sorry, you are not authorized to make this request!" } return Response(response_data, status=status.HTTP_400_BAD_REQUEST) - order_by = request.data.get("order_by") + order_by = request.GET.get("order_by") ( response_data, http_status_code, diff --git a/frontend/src/js/controllers/challengeCtrl.js b/frontend/src/js/controllers/challengeCtrl.js index c3b01856fa..1aa4e14af4 100644 --- a/frontend/src/js/controllers/challengeCtrl.js +++ b/frontend/src/js/controllers/challengeCtrl.js @@ -913,11 +913,8 @@ vm.startLeaderboard = function() { vm.stopLeaderboard(); vm.poller = $interval(function() { - parameters.url = "jobs/" + "challenge_phase_split/" + vm.phaseSplitId + "/leaderboard/?page_size=1000"; - parameters.method = 'POST'; - parameters.data = { - "order_by": vm.orderLeaderboardBy - }; + parameters.url = "jobs/" + "challenge_phase_split/" + vm.phaseSplitId + "/leaderboard/?page_size=1000&order_by=" + vm.orderLeaderboardBy; + parameters.method = 'GET'; parameters.callback = { onSuccess: function(response) { var details = response.data; @@ -973,11 +970,8 @@ // Show leaderboard vm.leaderboard = {}; - parameters.url = "jobs/" + "challenge_phase_split/" + vm.phaseSplitId + "/leaderboard/?page_size=1000"; - parameters.method = 'POST'; - parameters.data = { - "order_by": vm.orderLeaderboardBy - }; + parameters.url = "jobs/" + "challenge_phase_split/" + vm.phaseSplitId + "/leaderboard/?page_size=1000&order_by=" + vm.orderLeaderboardBy; + parameters.method = 'GET'; parameters.callback = { onSuccess: function(response) { var details = response.data; @@ -1397,11 +1391,8 @@ vm.refreshLeaderboard = function() { vm.startLoader("Loading Leaderboard Items"); vm.leaderboard = {}; - parameters.url = "jobs/" + "challenge_phase_split/" + vm.phaseSplitId + "/leaderboard/?page_size=1000"; - parameters.method = 'POST'; - parameters.data = { - "order_by": vm.orderLeaderboardBy - }; + parameters.url = "jobs/" + "challenge_phase_split/" + vm.phaseSplitId + "/leaderboard/?page_size=1000&order_by=" + vm.orderLeaderboardBy; + parameters.method = 'GET'; parameters.callback = { onSuccess: function(response) { var details = response.data; @@ -1460,11 +1451,8 @@ // Show leaderboard vm.leaderboard = {}; - parameters.url = "jobs/" + "phase_split/" + vm.phaseSplitId + "/public_leaderboard_all_entries/?page_size=1000"; - parameters.method = 'POST'; - parameters.data = { - "order_by": vm.orderLeaderboardBy - }; + parameters.url = "jobs/" + "phase_split/" + vm.phaseSplitId + "/public_leaderboard_all_entries/?page_size=1000&order_by=" + vm.orderLeaderboardBy; + parameters.method = 'GET'; parameters.callback = { onSuccess: function(response) { var details = response.data;