diff --git a/src/apps/api/views/tasks.py b/src/apps/api/views/tasks.py index 2c1642448..71bfb59bd 100644 --- a/src/apps/api/views/tasks.py +++ b/src/apps/api/views/tasks.py @@ -84,9 +84,26 @@ def get_serializer_context(self): return context def update(self, request, *args, **kwargs): + + # Get task task = self.get_object() + + # Raise error if user is not the creator of the task or not a super user if request.user != task.created_by and not request.user.is_superuser: raise PermissionDenied("Cannot update a task that is not yours") + + # If the key is not in the request data, set the corresponding field to None + # No condition for scoring program because a task must have a scoring program + if "ingestion_program" not in request.data: + task.ingestion_program = None + if "input_data" not in request.data: + task.input_data = None + if "reference_data" not in request.data: + task.reference_data = None + + # Save the task to apply the changes + task.save() + return super().update(request, *args, **kwargs) def destroy(self, request, *args, **kwargs): diff --git a/src/static/riot/tasks/management.tag b/src/static/riot/tasks/management.tag index 78c0f793d..37510275e 100644 --- a/src/static/riot/tasks/management.tag +++ b/src/static/riot/tasks/management.tag @@ -274,7 +274,7 @@ @@ -283,7 +283,7 @@ @@ -294,7 +294,7 @@ @@ -303,7 +303,7 @@ @@ -540,7 +540,7 @@ } self.edit_form_updated = () => { - self.edit_modal_is_valid = $(self.refs.edit_name).val() && $(self.refs.edit_description).val() && self.form_datasets.scoring_program + self.edit_modal_is_valid = $(self.refs.edit_name).val() && $(self.refs.edit_description).val() self.update() } @@ -555,17 +555,42 @@ self.edit_modal_is_valid = false } self.update_task = () => { + // Get filled data from the edit fom let data = get_form_data($(self.refs.edit_form)) + + // Show error when there is no scoring program in the task + if(data.edit_scoring_program == ""){ + toastr.error('Scoring program is required in a task!') + return + } // replace property names in the data object data.name = data.edit_name; data.description = data.edit_description; + // If ingestion program is not removed, add the new ingestion program from form_datasets to data + if(data.edit_ingestion_program != ""){ + data.ingestion_program = self.form_datasets.ingestion_program + } + // If input data is not removed, add the new input data from form_datasets to data + if(data.edit_input_data != ""){ + data.input_data = self.form_datasets.input_data + } + // If reference data is not removed, add the new reference data from form_datasets to data + if(data.edit_reference_data != ""){ + data.reference_data = self.form_datasets.reference_data + } + // add the new scoring from form_datasets to data + data.scoring_program = self.form_datasets.scoring_program + // delete the old property names delete data.edit_name delete data.edit_description + delete data.edit_ingestion_program + delete data.edit_scoring_program + delete data.edit_input_data + delete data.edit_reference_data - _.assign(data, self.form_datasets) task_id = self.selected_task.id CODALAB.api.update_task(task_id, data) .done((response) => {