MDL-47190 Ensure badges cannot be awarded without a role
authorYuliya Bozhko <yuliya.bozhko@totaralms.com>
Mon, 27 Oct 2014 18:47:05 +0000 (07:47 +1300)
committerSam Hemelryk <sam@moodle.com>
Mon, 3 Nov 2014 21:16:45 +0000 (10:16 +1300)
Signed-off-by: Yuliya Bozhko <yuliya.bozhko@totaralms.com>
badges/award.php
badges/criteria/award_criteria_manual.php

index e288fe2..f60bf39 100644 (file)
@@ -81,6 +81,14 @@ $output = $PAGE->get_renderer('core', 'badges');
 // Roles that can award this badge.
 $acceptedroles = array_keys($badge->criteria[BADGE_CRITERIA_TYPE_MANUAL]->params);
 
+if (empty($acceptedroles)) {
+    echo $OUTPUT->header();
+    $return = html_writer::link(new moodle_url('recipients.php', array('id' => $badge->id)), $strrecipients);
+    echo $OUTPUT->notification(get_string('notacceptedrole', 'badges', $return));
+    echo $OUTPUT->footer();
+    die();
+}
+
 if (count($acceptedroles) > 1) {
     // If there is more than one role that can award a badge, prompt user to make a selection.
     // If it is an admin, include all accepted roles, otherwise only the ones that current user has in this context.
index 616ba97..fd0ad2e 100644 (file)
@@ -150,6 +150,11 @@ class award_criteria_manual extends award_criteria {
     public function review($userid, $filtered = false) {
         global $DB;
 
+        // Roles should always have a parameter.
+        if (empty($this->params)) {
+            return false;
+        }
+
         // Users were already filtered by criteria completion.
         if ($filtered) {
             return true;