MDL-41945 mod_assign: Check if submission has been modified
This patch adds a check that stops a user submitting an assignment if someone else has modified it in the meantime.
This commit is contained in:
@@ -133,6 +133,8 @@ $string['duedate'] = 'Due date';
|
||||
$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}.';
|
||||
|
||||
@@ -5927,6 +5927,17 @@ class assign {
|
||||
} 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 {
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user