Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MDL-40471 badges: Fixes around badge capabilities and navigation

  • Loading branch information...
commit 05f840e8a44ddbb2cf1a550a2186bdcc62f8ab46 1 parent 039b551
@ybozhko ybozhko authored samhemelryk committed
View
2  admin/settings/badges.php
@@ -32,6 +32,7 @@
'moodle/badges:createbadge',
'moodle/badges:manageglobalsettings',
'moodle/badges:awardbadge',
+ 'moodle/badges:configurecriteria',
'moodle/badges:configuremessages',
'moodle/badges:configuredetails',
'moodle/badges:deletebadge'), $systemcontext))) {
@@ -74,6 +75,7 @@
'moodle/badges:viewawarded',
'moodle/badges:createbadge',
'moodle/badges:awardbadge',
+ 'moodle/badges:configurecriteria',
'moodle/badges:configuremessages',
'moodle/badges:configuredetails',
'moodle/badges:deletebadge'
View
6 badges/action.php
@@ -95,7 +95,11 @@
require_capability('moodle/badges:createbadge', $context);
$cloneid = $badge->make_clone();
- redirect(new moodle_url('/badges/edit.php', array('id' => $cloneid, 'action' => 'details')));
+ // If a user can edit badge details, they will be redirected to the edit page.
+ if (has_capability('moodle/badges:configuredetails', $context)) {
+ redirect(new moodle_url('/badges/edit.php', array('id' => $cloneid, 'action' => 'details')));
+ }
+ redirect(new moodle_url('/badges/overview.php', array('id' => $cloneid)));
}
if ($activate) {
View
3  badges/criteria.php
@@ -40,6 +40,8 @@
$context = $badge->get_context();
$navurl = new moodle_url('/badges/index.php', array('type' => $badge->type));
+require_capability('moodle/badges:configurecriteria', $context);
+
if ($badge->type == BADGE_TYPE_COURSE) {
if (empty($CFG->badges_allowcoursebadges)) {
print_error('coursebadgesdisabled', 'badges');
@@ -66,7 +68,6 @@
if ((($update == BADGE_CRITERIA_AGGREGATION_ALL) || ($update == BADGE_CRITERIA_AGGREGATION_ANY))) {
require_sesskey();
- require_capability('moodle/badges:configurecriteria', $context);
$obj = new stdClass();
$obj->id = $badge->criteria[BADGE_CRITERIA_TYPE_OVERALL]->id;
$obj->method = $update;
View
6 badges/edit.php
@@ -41,7 +41,11 @@
$context = $badge->get_context();
$navurl = new moodle_url('/badges/index.php', array('type' => $badge->type));
-require_capability('moodle/badges:configuredetails', $context);
+if ($action == 'message') {
+ require_capability('moodle/badges:configuremessages', $context);
+} else {
+ require_capability('moodle/badges:configuredetails', $context);
+}
if ($badge->type == BADGE_TYPE_COURSE) {
if (empty($CFG->badges_allowcoursebadges)) {
View
6 badges/newbadge.php
@@ -99,7 +99,11 @@
$newbadge = new badge($newid);
badges_process_badge_image($newbadge, $form->save_temp_file('image'));
- redirect(new moodle_url('/badges/criteria.php', array('id' => $newid)));
+ // If a user can configure badge criteria, they will be redirected to the criteria page.
+ if (has_capability('moodle/badges:configurecriteria', $PAGE->context)) {
+ redirect(new moodle_url('/badges/criteria.php', array('id' => $newid)));
+ }
+ redirect(new moodle_url('/badges/overview.php', array('id' => $newid)));
}
echo $OUTPUT->header();
View
45 lib/badgeslib.php
@@ -895,38 +895,29 @@ function badges_add_course_navigation(navigation_node $coursenode, stdClass $cou
$coursecontext = context_course::instance($course->id);
$isfrontpage = (!$coursecontext || $course->id == $SITE->id);
+ $canmanage = has_any_capability(array('moodle/badges:viewawarded',
+ 'moodle/badges:createbadge',
+ 'moodle/badges:awardbadge',
+ 'moodle/badges:configurecriteria',
+ 'moodle/badges:configuremessages',
+ 'moodle/badges:configuredetails',
+ 'moodle/badges:deletebadge'), $coursecontext);
- if (!empty($CFG->enablebadges) && !empty($CFG->badges_allowcoursebadges) && !$isfrontpage) {
- if (has_capability('moodle/badges:configuredetails', $coursecontext)) {
- $coursenode->add(get_string('coursebadges', 'badges'), null,
- navigation_node::TYPE_CONTAINER, null, 'coursebadges',
- new pix_icon('i/badge', get_string('coursebadges', 'badges')));
+ if (!empty($CFG->enablebadges) && !empty($CFG->badges_allowcoursebadges) && !$isfrontpage && $canmanage) {
+ $coursenode->add(get_string('coursebadges', 'badges'), null,
+ navigation_node::TYPE_CONTAINER, null, 'coursebadges',
+ new pix_icon('i/badge', get_string('coursebadges', 'badges')));
- if (has_capability('moodle/badges:viewawarded', $coursecontext)) {
- $url = new moodle_url('/badges/index.php',
- array('type' => BADGE_TYPE_COURSE, 'id' => $course->id));
+ $url = new moodle_url('/badges/index.php', array('type' => BADGE_TYPE_COURSE, 'id' => $course->id));
- $coursenode->get('coursebadges')->add(get_string('managebadges', 'badges'), $url,
- navigation_node::TYPE_SETTING, null, 'coursebadges');
- }
-
- if (has_capability('moodle/badges:createbadge', $coursecontext)) {
- $url = new moodle_url('/badges/newbadge.php',
- array('type' => BADGE_TYPE_COURSE, 'id' => $course->id));
-
- $coursenode->get('coursebadges')->add(get_string('newbadge', 'badges'), $url,
- navigation_node::TYPE_SETTING, null, 'newbadge');
- }
- } else if (has_capability('moodle/badges:awardbadge', $coursecontext)) {
- $coursenode->add(get_string('coursebadges', 'badges'), null,
- navigation_node::TYPE_CONTAINER, null, 'coursebadges',
- new pix_icon('i/badge', get_string('coursebadges', 'badges')));
+ $coursenode->get('coursebadges')->add(get_string('managebadges', 'badges'), $url,
+ navigation_node::TYPE_SETTING, null, 'coursebadges');
- $url = new moodle_url('/badges/index.php',
- array('type' => BADGE_TYPE_COURSE, 'id' => $course->id));
+ if (has_capability('moodle/badges:createbadge', $coursecontext)) {
+ $url = new moodle_url('/badges/newbadge.php', array('type' => BADGE_TYPE_COURSE, 'id' => $course->id));
- $coursenode->get('coursebadges')->add(get_string('managebadges', 'badges'), $url,
- navigation_node::TYPE_SETTING, null, 'coursebadges');
+ $coursenode->get('coursebadges')->add(get_string('newbadge', 'badges'), $url,
+ navigation_node::TYPE_SETTING, null, 'newbadge');
}
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.