Merge branch 'MDL-40471_master' of https://github.com/totara/openbadges
authorSam Hemelryk <sam@moodle.com>
Tue, 10 Sep 2013 20:42:37 +0000 (08:42 +1200)
committerSam Hemelryk <sam@moodle.com>
Tue, 10 Sep 2013 20:42:37 +0000 (08:42 +1200)
admin/settings/badges.php
badges/action.php
badges/criteria.php
badges/edit.php
badges/newbadge.php
lib/badgeslib.php

index 10994fc..276582c 100644 (file)
@@ -32,6 +32,7 @@ if (($hassiteconfig || has_any_capability(array(
             '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 @@ if (($hassiteconfig || 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'
index ae38fa7..f6f9524 100644 (file)
@@ -95,7 +95,11 @@ if ($copy) {
     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) {
index 9bfd389..7a1e0e4 100644 (file)
@@ -40,6 +40,8 @@ $badge = new badge($badgeid);
 $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 @@ $emsg = optional_param('emsg', '', PARAM_TEXT);
 
 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;
index 1c91562..b0a4783 100644 (file)
@@ -41,7 +41,11 @@ $badge = new badge($badgeid);
 $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)) {
index 91c316c..756ef91 100644 (file)
@@ -98,7 +98,11 @@ if ($form->is_cancelled()) {
 
     $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();
index 061ecd3..598a88e 100644 (file)
@@ -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');
         }
     }
 }