diff --git a/badges/award.php b/badges/award.php index b503ac19234..f67b2ae8953 100644 --- a/badges/award.php +++ b/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($PAGE, $badge->type, false, false, $returnurl); diff --git a/lang/en/badges.php b/lang/en/badges.php index ebb109dd8e9..a98ce66e76f 100644 --- a/lang/en/badges.php +++ b/lang/en/badges.php @@ -579,6 +579,7 @@ $string['visible'] = 'Visible'; $string['version'] = 'Version'; $string['version_help'] = 'The version field may be used to keep track of the badge\'s development. If specified, the version is displayed on the badge page.'; $string['warnexpired'] = ' (This badge has expired!)'; +$string['wrongrole'] = 'The role you want to use is not assigned to you.'; $string['year'] = 'Year(s)'; $string['includeauthdetails'] = "Include authentication details with the backpack";