diff --git a/public/badges/award.php b/public/badges/award.php index 7b71559c2b2..50fabb26e8d 100644 --- a/public/badges/award.php +++ b/public/badges/award.php @@ -82,6 +82,16 @@ if (!$badge->is_active()) { die(); } +if (!empty($role)) { + if (!user_has_role_assignment($USER->id, $role, $context->id) && !$isadmin) { + // User does not have the role passed by the parameter. + echo $OUTPUT->header(); + echo $OUTPUT->notification(get_string('wrongrole', 'badges')); + echo $OUTPUT->footer(); + die(); + } +} + $returnurl = new moodle_url('recipients.php', array('id' => $badge->id)); $returnlink = html_writer::link($returnurl, $strrecipients); $actionbar = new \core_badges\output\standard_action_bar( diff --git a/public/lang/en/badges.php b/public/lang/en/badges.php index 2e56d574e7c..987dfcea9e6 100644 --- a/public/lang/en/badges.php +++ b/public/lang/en/badges.php @@ -596,6 +596,7 @@ $string['viewbadge'] = 'View issued badge'; $string['visible'] = 'Visible'; $string['version'] = 'Version'; $string['warnexpired'] = ' (This badge has expired!)'; +$string['wrongrole'] = 'The role you want to use is not assigned to you.'; $string['year'] = 'Year(s)'; // Deprecated since Moodle 4.5.