MDL-59239 mod_workshop: Move submission event trigger
authorJuan Leyva <juanleyvadelgado@gmail.com>
Fri, 8 Sep 2017 10:15:45 +0000 (12:15 +0200)
committerEloy Lafuente (stronk7) <stronk7@moodle.org>
Tue, 3 Oct 2017 17:26:40 +0000 (19:26 +0200)
The submission viewed event was being triggered at the beginning of the
script (before doing all the validation/safety checks).
I’ve moved the triggering to a better place so the event it is only
triggered when is verified that the user has permissions to view
the submission.

mod/workshop/submission.php

index 5acbd59..8985e04 100644 (file)
@@ -51,8 +51,6 @@ if ($edit) {
 
 if ($id) { // submission is specified
     $submission = $workshop->get_submission_by_id($id);
-    // Trigger submission viewed event.
-    $workshop->set_submission_viewed($submission);
 
 } else { // no submission specified
     if (!$submission = $workshop->get_submission_by_author($USER->id)) {
@@ -124,6 +122,11 @@ if ($submission->id and ($ownsubmission or $canviewall or $isreviewer)) {
     print_error('nopermissions', 'error', $workshop->view_url(), 'view or create submission');
 }
 
+if ($submission->id) {
+    // Trigger submission viewed event.
+    $workshop->set_submission_viewed($submission);
+}
+
 if ($assess and $submission->id and !$isreviewer and $canallocate and $workshop->assessing_allowed($USER->id)) {
     require_sesskey();
     $assessmentid = $workshop->add_allocation($submission, $USER->id);