From 282c169549370a36664f62c9c42e29de4a0b1759 Mon Sep 17 00:00:00 2001 From: jmg324 Date: Fri, 18 May 2007 11:57:46 +0000 Subject: [PATCH] MDL-9802 added my:manageblocks capability so admins can define whether users can add/remove blocks from myMoodle page --- lang/en_utf8/role.php | 1 + lib/blocklib.php | 9 ++++++++- lib/db/access.php | 11 ++++++++++- lib/db/upgrade.php | 12 ++++++++++++ my/pagelib.php | 4 ++-- version.php | 2 +- 6 files changed, 34 insertions(+), 5 deletions(-) diff --git a/lang/en_utf8/role.php b/lang/en_utf8/role.php index d812005053..d470f12739 100644 --- a/lang/en_utf8/role.php +++ b/lang/en_utf8/role.php @@ -79,6 +79,7 @@ $string['listallroles'] = 'List all roles'; $string['manageroles'] = 'Manage roles'; $string['metaassignerror'] = 'Can not assign this role to user \"$a\" because Manage metacourse capability is needed.'; $string['metaunassignerror'] = 'Role of user \"$a\" was automatically reassigned, please unassign the role in child courses instead.'; +$string['my:manageblocks'] = 'Manage myMoodle page blocks'; $string['nocapabilitiesincontext'] = 'No capabilities available in this context'; $string['notset'] = 'Not set'; $string['overrideroles'] = 'Override roles'; diff --git a/lib/blocklib.php b/lib/blocklib.php index e4501c1803..ca39d05de1 100644 --- a/lib/blocklib.php +++ b/lib/blocklib.php @@ -336,7 +336,14 @@ function blocks_print_group(&$page, &$pageblocks, $position) { } // End foreach - if ($page->blocks_default_position() == $position && $page->user_is_editing() && has_capability('moodle/site:manageblocks', get_context_instance(CONTEXT_COURSE, $COURSE->id))) { + // Check if + // we are on the default position/side AND + // we're editing the page AND + // ( + // we have the capability to manage blocks OR + // we are in myMoodle page AND have the capibility to manage myMoodle blocks + // ) + if ($page->blocks_default_position() == $position && $page->user_is_editing() && (has_capability('moodle/site:manageblocks', get_context_instance(CONTEXT_COURSE, $COURSE->id)) || ($page->type == PAGE_MY_MOODLE && has_capability('moodle/my:manageblocks', get_context_instance(CONTEXT_COURSE, $COURSE->id)))) ) { blocks_print_adminblock($page, $pageblocks); } } diff --git a/lib/db/access.php b/lib/db/access.php index 77c29cc72a..adb71d1c11 100644 --- a/lib/db/access.php +++ b/lib/db/access.php @@ -1003,7 +1003,16 @@ $moodle_capabilities = array( 'editingteacher' => CAP_ALLOW, 'admin' => CAP_ALLOW ) - ) + ), + + 'moodle/my:manageblocks' => array( + 'captype' => 'write', + 'contextlevel' => CONTEXT_SYSTEM, + 'legacy' => array( + 'user' => CAP_ALLOW + ) + ) + ); ?> diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index f25f5b3509..adeeef7a89 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -1280,6 +1280,18 @@ function xmldb_main_upgrade($oldversion=0) { } } + if ($result && $oldversion < 2007051801) { + // Get the role id of the "Auth. User" role and check if the default role id is different + $userrole = get_record( 'role', 'shortname', 'user' ); + $defaultroleid = $CFG->defaultuserroleid; + + if( $defaultroleid != $userrole->id ) { + // Add in the new moodle/my:manageblocks capibility to the default user role + $context = get_context_instance(CONTEXT_SYSTEM, SITEID); + assign_capability('moodle/my:manageblocks',CAP_ALLOW,$defaultroleid,$context->id); + } + } + return $result; } diff --git a/my/pagelib.php b/my/pagelib.php index a126458a07..b003bf62d2 100644 --- a/my/pagelib.php +++ b/my/pagelib.php @@ -12,7 +12,7 @@ class page_my_moodle extends page_base { page_id_and_class($id,$class); if ($id == PAGE_MY_MOODLE) { return true; - } else if (has_capability('moodle/site:manageblocks', get_context_instance(CONTEXT_SYSTEM, SITEID)) && defined('ADMIN_STICKYBLOCKS')) { + } else if (has_capability('moodle/my:manageblocks', get_context_instance(CONTEXT_SYSTEM, SITEID)) && defined('ADMIN_STICKYBLOCKS')) { return true; } return false; @@ -20,7 +20,7 @@ class page_my_moodle extends page_base { function user_is_editing() { global $USER; - if (has_capability('moodle/site:manageblocks', get_context_instance(CONTEXT_SYSTEM, SITEID)) && defined('ADMIN_STICKYBLOCKS')) { + if (has_capability('moodle/my:manageblocks', get_context_instance(CONTEXT_SYSTEM, SITEID)) && defined('ADMIN_STICKYBLOCKS')) { return true; } return (!empty($USER->editing)); diff --git a/version.php b/version.php index ec0eff3525..3bb8451a5b 100644 --- a/version.php +++ b/version.php @@ -6,7 +6,7 @@ // This is compared against the values stored in the database to determine // whether upgrades should be performed (see lib/db/*.php) - $version = 2007051101; // YYYYMMDD = date + $version = 2007051801; // YYYYMMDD = date // XY = increments within a single day $release = '1.9 dev'; // Human-friendly version name -- 2.39.5