Skip to content

Commit

Permalink
MDL-41945 mod_assign: Check if submission has been modified
Browse files Browse the repository at this point in the history
This patch adds a check that stops a user submitting an assignment
if someone else has modified it in the meantime.
  • Loading branch information
cameorn1730 committed Jul 4, 2016
1 parent ac8d6cf commit 16b36d3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
2 changes: 2 additions & 0 deletions mod/assign/lang/en/assign.php
Expand Up @@ -140,6 +140,8 @@
$string['duedate_help'] = 'This is when the assignment is due. Submissions will still be allowed after this date but any assignments submitted after this date are marked as late. To prevent submissions after a certain date - set the assignment cut off date.';
$string['duedateno'] = 'No due date';
$string['submissionempty'] = 'Nothing was submitted';
$string['submissionmodified'] = 'You have existing submission data. Please leave this page and try again.';
$string['submissionmodifiedgroup'] = 'The submission has been modified by somebody else. Please leave this page and try again.';
$string['duedatereached'] = 'The due date for this assignment has now passed';
$string['duedatevalidation'] = 'Due date must be after the allow submissions from date.';
$string['editattemptfeedback'] = 'Edit the grade and feedback for attempt number {$a}.';
Expand Down
11 changes: 11 additions & 0 deletions mod/assign/locallib.php
Expand Up @@ -6403,6 +6403,17 @@ public function save_submission(stdClass $data, & $notices) {
} else {
$submission = $this->get_user_submission($userid, true);
}

// Check that no one has modified the submission since we started looking at it.
if (isset($data->lastmodified) && ($submission->timemodified > $data->lastmodified)) {
// Another user has submitted something. Notify the current user.
if ($submission->status !== ASSIGN_SUBMISSION_STATUS_NEW) {
$notices[] = $instance->teamsubmission ? get_string('submissionmodifiedgroup', 'mod_assign')
: get_string('submissionmodified', 'mod_assign');
return false;
}
}

if ($instance->submissiondrafts) {
$submission->status = ASSIGN_SUBMISSION_STATUS_DRAFT;
} else {
Expand Down
14 changes: 12 additions & 2 deletions mod/assign/submission_form.php
Expand Up @@ -41,12 +41,22 @@ class mod_assign_submission_form extends moodleform {
* Define this form - called by the parent constructor
*/
public function definition() {
global $USER;
$mform = $this->_form;

list($assign, $data) = $this->_customdata;

$assign->add_submission_form_elements($mform, $data);
$instance = $assign->get_instance();
if ($instance->teamsubmission) {
$submission = $assign->get_group_submission($USER->id, 0, true);
} else {
$submission = $assign->get_user_submission($USER->id, true);
}
if ($submission) {
$mform->addElement('hidden', 'lastmodified', $submission->timemodified);
$mform->setType('lastmodified', PARAM_INT);
}

$assign->add_submission_form_elements($mform, $data);
$this->add_action_buttons(true, get_string('savechanges', 'assign'));
if ($data) {
$this->set_data($data);
Expand Down

0 comments on commit 16b36d3

Please sign in to comment.