From 5b2bc7460eba025cb3bb6a79ee512a9692bdc33d Mon Sep 17 00:00:00 2001 From: Ram Ramrakhya Date: Mon, 9 Aug 2021 04:14:53 +0530 Subject: [PATCH] Frontend+Backend: Add feature to cancel submissions(#3456) * Add submission cancel feature * Rebase changes * Remove unused code * Fix reviews * Fix review Co-authored-by: Rishabh Jain --- apps/jobs/views.py | 37 ++++++++++++++++-- frontend/src/js/controllers/challengeCtrl.js | 39 ++++++++++++++++++- .../web/challenge/cancel-submission.html | 16 ++++++++ .../views/web/challenge/my-submission.html | 3 ++ .../update-submission-visibility.html | 2 +- scripts/workers/submission_worker.py | 8 ++++ 6 files changed, 99 insertions(+), 6 deletions(-) create mode 100644 frontend/src/views/web/challenge/cancel-submission.html diff --git a/apps/jobs/views.py b/apps/jobs/views.py index 29b4850da0..cef16b95d9 100644 --- a/apps/jobs/views.py +++ b/apps/jobs/views.py @@ -50,6 +50,7 @@ get_challenge_model, get_challenge_phase_model, get_challenge_phase_split_model, + get_participant_model, ) from hosts.models import ChallengeHost from hosts.utils import is_user_a_host_of_challenge @@ -2824,7 +2825,35 @@ def update_submission_meta(request, challenge_pk, submission_pk): serializer.errors, status=status.HTTP_400_BAD_REQUEST ) else: - response_data = { - "error": "Sorry, you are not authorized to make this request" - } - return Response(response_data, status=status.HTTP_403_FORBIDDEN) + participant_team_pk = get_participant_team_id_of_user_for_a_challenge( + request.user, challenge_pk + ) + + participant_team = get_participant_model(participant_team_pk) + + try: + submission = Submission.objects.get( + id=submission_pk, + participant_team=participant_team, + ) + except Submission.DoesNotExist: + response_data = { + "error": "Submission {} does not exist".format(submission_pk) + } + return Response(response_data, status=status.HTTP_404_NOT_FOUND) + + serializer = SubmissionSerializer( + submission, + data=request.data, + context={"request": request}, + partial=True, + ) + + if serializer.is_valid(): + serializer.save() + response_data = serializer.data + return Response(response_data, status=status.HTTP_200_OK) + else: + return Response( + serializer.errors, status=status.HTTP_400_BAD_REQUEST + ) diff --git a/frontend/src/js/controllers/challengeCtrl.js b/frontend/src/js/controllers/challengeCtrl.js index ff58821393..8fbce15eb1 100644 --- a/frontend/src/js/controllers/challengeCtrl.js +++ b/frontend/src/js/controllers/challengeCtrl.js @@ -2030,7 +2030,44 @@ } }; - vm.hideVisibilityDialog = function() { + vm.cancelSubmission = function(submissionId) { + parameters.url = "jobs/challenges/" + vm.challengeId + "/submissions/" + submissionId + "/update_submission_meta/"; + parameters.method = 'PATCH'; + parameters.data = { + "status": "cancelled", + }; + parameters.callback = { + onSuccess: function(response) { + var status = response.status; + if (status === 200) { + $mdDialog.hide(); + $rootScope.notify("success", "Submission cancelled successfully!"); + } + }, + onError: function(response) { + $mdDialog.hide(); + var error = response.data; + $rootScope.notify("error", error); + } + }; + + utilities.sendRequest(parameters); + }; + + vm.showCancelSubmissionDialog = function(submissionId, status) { + if (status != "submitted") { + $rootScope.notify("error", "Only unproccessed submissions can be cancelled"); + return; + } + vm.submissionId = submissionId; + $mdDialog.show({ + scope: $scope, + preserveScope: true, + templateUrl: 'dist/views/web/challenge/cancel-submission.html' + }); + }; + + vm.hideDialog = function() { $mdDialog.hide(); }; diff --git a/frontend/src/views/web/challenge/cancel-submission.html b/frontend/src/views/web/challenge/cancel-submission.html new file mode 100644 index 0000000000..5b6370963a --- /dev/null +++ b/frontend/src/views/web/challenge/cancel-submission.html @@ -0,0 +1,16 @@ +
+
+
+
+
+
Are you sure you want to cancel submission?
+ + +
+
+
+
+
diff --git a/frontend/src/views/web/challenge/my-submission.html b/frontend/src/views/web/challenge/my-submission.html index 54e56bf517..e89e34fb30 100644 --- a/frontend/src/views/web/challenge/my-submission.html +++ b/frontend/src/views/web/challenge/my-submission.html @@ -70,6 +70,7 @@
My Participated Team: {{challenge.participated_team_name}}
Baseline Edit + Cancel @@ -133,6 +134,8 @@
My Participated Team: {{challenge.participated_team_name}}
+ diff --git a/frontend/src/views/web/challenge/update-submission-visibility.html b/frontend/src/views/web/challenge/update-submission-visibility.html index 76efbdcd68..e2ee9b34af 100644 --- a/frontend/src/views/web/challenge/update-submission-visibility.html +++ b/frontend/src/views/web/challenge/update-submission-visibility.html @@ -6,7 +6,7 @@
Are you sure you want to override your current public submission?
diff --git a/scripts/workers/submission_worker.py b/scripts/workers/submission_worker.py index be22b23a8b..f3992d101a 100644 --- a/scripts/workers/submission_worker.py +++ b/scripts/workers/submission_worker.py @@ -348,6 +348,14 @@ def extract_submission_data(submission_id): # for message corresponding to which submission entry # does not exist return None + # Ignore submissions with status cancelled + if submission.status == Submission.CANCELLED: + logger.info( + "{} Submission {} was cancelled by the user".format( + SUBMISSION_LOGS_PREFIX, submission_id + ) + ) + return None if submission.challenge_phase.challenge.is_static_dataset_code_upload: input_file = submission.submission_input_file