From: martinlanghoff Date: Wed, 19 Sep 2007 07:46:24 +0000 (+0000) Subject: blocks/admin_tree: Show the block if some admin privs present... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=0146bd4190932cd255c607c2ca5421e368b9201c;p=moodle.git blocks/admin_tree: Show the block if some admin privs present... Dan Poltawski said: > Previously users with different permissions could have granular > access to the admin menu for the items they have access to, so > limiting to only users with moodle/site:config would break that. > Although I agree that that menu is slowww to render and needs > fixing. Perhaps permissions for the various elements could be > gathered and checked first This commit addresses the problem checking for all the caps that are mentioned by code in /admin (according to grep, at least). Some light testing with the "moodle/user:create" seems to work properly. This burdens us with maintaining the list in has_admin_caps() -- less than ideal, but easier than rewriting /admin. --- diff --git a/blocks/admin_tree/block_admin_tree.php b/blocks/admin_tree/block_admin_tree.php index 6045f44637..5213463016 100644 --- a/blocks/admin_tree/block_admin_tree.php +++ b/blocks/admin_tree/block_admin_tree.php @@ -22,7 +22,7 @@ class block_admin_tree extends block_base { } function applicable_formats() { - if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) { + if ($this->has_admin_caps()) { return array('site' => true, 'admin' => true); } else { return array('site' => true); @@ -98,17 +98,17 @@ class block_admin_tree extends block_base { function get_content() { - global $CFG, $ADMIN; - - if (!has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) { - $this->content = ''; - return ''; - } + global $CFG; if ($this->content !== NULL) { return $this->content; } + if (!($this->has_admin_caps())) { + $this->content = ''; + return ''; + } + require_once($CFG->libdir.'/adminlib.php'); $adminroot = admin_get_root(); @@ -213,6 +213,24 @@ class block_admin_tree extends block_base { return $this->content; } + + /* Return true + * if $USER has any caps that mean we should + * display this block... + */ + function has_admin_caps() { + + $sysctx = get_context_instance(CONTEXT_SYSTEM); + + return (has_capability('moodle/site:config', $sysctx) + || has_capability('moodle/site:langeditmaster', $sysctx) + || has_capability('moodle/site:langeditlocal', $sysctx) + || has_capability('moodle/site:manageblocks', $sysctx) + || has_capability('moodle/user:delete', $sysctx) + || has_capability('moodle/user:update', $sysctx) + || has_capability('moodle/user:create', $sysctx) + || has_capability('moodle/site:readallmessages', $sysctx)); + } } ?>