Skip to content

Commit

Permalink
Frontend+Backend: Add feature to cancel submissions(#3456)
Browse files Browse the repository at this point in the history
* Add submission cancel feature

* Rebase changes

* Remove unused code

* Fix reviews

* Fix review

Co-authored-by: Rishabh Jain <[email protected]>
  • Loading branch information
Ram81 and RishabhJain2018 authored Aug 8, 2021
1 parent 27d0dd1 commit c509e38
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 6 deletions.
37 changes: 33 additions & 4 deletions apps/jobs/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
)
39 changes: 38 additions & 1 deletion frontend/src/js/controllers/challengeCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};

Expand Down
16 changes: 16 additions & 0 deletions frontend/src/views/web/challenge/cancel-submission.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<section class="text-center rm-overflow-y">
<div class="row">
<div class="col s12 m12">
<div class="update-submission-visibility-card">
<form name="cancelSubmissionForm" ng-submit="challenge.cancelSubmission(challenge.submissionId)">
<div class="pass-title">Are you sure you want to cancel submission?</div>

<ul class="inline-list pointer">
<li><a class="dark-link" type="button" ng-click="challenge.hideDialog()"><strong>Cancel </strong></a></li>
<li><button class="btn ev-btn-dark waves-effect waves-dark grad-btn grad-btn-dark fs-14" type="submit" value="Submit">Submit </button></li>
</ul>
</form>
</div>
</div>
</div>
</section>
3 changes: 3 additions & 0 deletions frontend/src/views/web/challenge/my-submission.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ <h6>My Participated Team: {{challenge.participated_team_name}}</h6>
<th class="fs-18 w-300" data-field="isBaseline" ng-if="challenge.isChallengeHost">Baseline
</th>
<th class="fs-18 w-300">Edit</th>
<th class="fs-18 w-300">Cancel</th>
</thead>
<tbody>
<tr ng-repeat="key in challenge.submissionResult.results" class="result-val fs-16 w-300">
Expand Down Expand Up @@ -133,6 +134,8 @@ <h6>My Participated Team: {{challenge.participated_team_name}}</h6>
</td>
<td><a class="pointer" ng-click="challenge.showMdDialog($event, key.id)"><i
class="fa fa-pencil" aria-hidden="true"></i></a></td>
<td><a class="times" ng-click="challenge.showCancelSubmissionDialog(key.id, key.status)"><i
class="fa fa-times" aria-hidden="true"></i></a></td>
</tr>
</tbody>
</table>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<div class="pass-title">Are you sure you want to override your current public submission?</div>

<ul class="inline-list pointer">
<li><a class="dark-link" type="button" ng-click="challenge.hideVisibilityDialog()"><strong>Cancel </strong></a></li>
<li><a class="dark-link" type="button" ng-click="challenge.hideDialog()"><strong>Cancel </strong></a></li>
<li><button class="btn ev-btn-dark waves-effect waves-dark grad-btn grad-btn-dark fs-14" type="submit" value="Submit">Submit </button></li>
</ul>
</form>
Expand Down
8 changes: 8 additions & 0 deletions scripts/workers/submission_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c509e38

Please sign in to comment.