Skip to content

Commit

Permalink
MDL-9802 added my:manageblocks capability so admins can define whethe…
Browse files Browse the repository at this point in the history
…r users can add/remove blocks from myMoodle page
  • Loading branch information
jmg324 committed May 18, 2007
1 parent 0ac948e commit 282c169
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 5 deletions.
1 change: 1 addition & 0 deletions lang/en_utf8/role.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
$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';
Expand Down
9 changes: 8 additions & 1 deletion lib/blocklib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
11 changes: 10 additions & 1 deletion lib/db/access.php
Original file line number Diff line number Diff line change
Expand Up @@ -1003,7 +1003,16 @@
'editingteacher' => CAP_ALLOW,
'admin' => CAP_ALLOW
)
)
),

'moodle/my:manageblocks' => array(
'captype' => 'write',
'contextlevel' => CONTEXT_SYSTEM,
'legacy' => array(
'user' => CAP_ALLOW
)
)

);

?>
12 changes: 12 additions & 0 deletions lib/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions my/pagelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ function user_allowed_editing() {
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;
}

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));
Expand Down
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 282c169

Please sign in to comment.