]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-11563 replaced hardcoded permission check from admin_tree_block
authorskodak <skodak>
Sun, 28 Oct 2007 22:35:00 +0000 (22:35 +0000)
committerskodak <skodak>
Sun, 28 Oct 2007 22:35:00 +0000 (22:35 +0000)
14 files changed:
admin/settings/appearance.php
admin/settings/courses.php
admin/settings/frontpage.php
admin/settings/grades.php
admin/settings/language.php
admin/settings/location.php
admin/settings/misc.php
admin/settings/mnet.php
admin/settings/security.php
admin/settings/server.php
admin/settings/top.php
admin/settings/unsupported.php
admin/settings/users.php
blocks/admin_tree/block_admin_tree.php

index 7b16d9ff159e1b75eab51a2891d35b0ac3293f3f..68ccd986ac5b94a40aa08e6659a61e4e2c1da1bd 100644 (file)
@@ -2,6 +2,9 @@
 
 // This file defines settingpages and externalpages under the "appearance" category
 
+if ($hassiteconfig) { // speedup for non-admins, add all caps used on this page
+
+
 $ADMIN->add('appearance', new admin_category('themes', get_string('themes')));
 // "themesettings" settingpage
 $temp = new admin_settingpage('themesettings', get_string('themesettings', 'admin'));
@@ -124,4 +127,6 @@ $ADMIN->add('appearance', $temp);
 
 // link to tag management interface
 $ADMIN->add('appearance', new admin_externalpage('managetags', get_string('managetags', 'tag'), "$CFG->wwwroot/tag/manage.php"));
+
+} // end of speedup
 ?>
index 47e711dc525edd87ad8210b1098e05a6d32c7539..c83e87b306097bf2779753951486c9952bf71a0c 100644 (file)
@@ -2,6 +2,10 @@
 
 // This file defines settingpages and externalpages under the "courses" category
 
+if ($hassiteconfig
+ or has_capability('moodle/site:backup', $systemcontext)
+ or has_capability('moodle/category:update', $systemcontext)) { // speedup for non-admins, add all caps used on this page
+
 
 $ADMIN->add('courses', new admin_externalpage('coursemgmt', get_string('coursemgmt', 'admin'), $CFG->wwwroot . '/course/index.php?categoryedit=on','moodle/category:update'));
 
@@ -48,5 +52,6 @@ $temp->add(new admin_setting_special_backuptime());
 $temp->add(new admin_setting_special_backupsaveto());
 $ADMIN->add('courses', $temp);
 
+} // end of speedup
 
 ?>
index 28ddfccae945031993d672b4220691f914d087a4..3ec40b0962be987057c891ebf356689d4174a5c3 100644 (file)
@@ -5,13 +5,13 @@
 if (get_site()) { //do not use during installation
     $frontpagecontext = get_context_instance(CONTEXT_COURSE, SITEID);
 
-    if (has_capability('moodle/site:config',        $systemcontext)
+    if ($hassiteconfig
      or has_capability('moodle/course:update',      $frontpagecontext)
      or has_capability('moodle/role:assign',        $frontpagecontext)
      or has_capability('moodle/site:restore',       $frontpagecontext)
      or has_capability('moodle/site:backup',        $frontpagecontext)
-     or has_capability('moodle/course:managefiles', $frontpagecontext)
-     ) {
+     or has_capability('moodle/course:managefiles', $frontpagecontext)) {
+
         // "frontpage" settingpage
         $temp = new admin_settingpage('frontpagesettings', get_string('frontpagesettings','admin'), 'moodle/course:update', false, $frontpagecontext);
         $temp->add(new admin_setting_sitesettext('fullname', get_string('fullsitename'), '', NULL)); // no default
index e6e0242b9efcf5833948e0cfd39a58c96d387824..8cb2a2795b41458f96f33f4682bfdf302243968e 100644 (file)
@@ -2,11 +2,14 @@
 
 // This file defines settingpages and externalpages under the "grades" section
 
+if (has_capability('moodle/grade:manage', $systemcontext)
+ or has_capability('moodle/grade:manageletters', $systemcontext)) { // speedup for non-admins, add all caps used on this page
+
 // General settings
 
 require_once $CFG->libdir.'/grade/constants.php';
 
-$temp = new admin_settingpage('gradessettings', get_string('gradessettings', 'grades'));
+$temp = new admin_settingpage('gradessettings', get_string('gradessettings', 'grades'), 'moodle/grade:manage');
 
 // enable outcomes checkbox
 $temp->add(new admin_setting_configcheckbox('enableoutcomes', get_string('enableoutcomes', 'grades'), get_string('configenableoutcomes', 'grades'), 0, PARAM_INT));
@@ -57,7 +60,7 @@ $temp->add(new admin_setting_special_gradeexport());
 $ADMIN->add('grades', $temp);
 
 /// Grade category settings
-$temp = new admin_settingpage('gradecategorysettings', get_string('gradecategorysettings', 'grades'));
+$temp = new admin_settingpage('gradecategorysettings', get_string('gradecategorysettings', 'grades'), 'moodle/grade:manage');
 
 $temp->add(new admin_setting_configcheckbox('grade_hideforcedsettings', get_string('hideforcedsettings', 'grades'), get_string('confighideforcedsettings', 'grades'), 0, PARAM_INT));
 
@@ -117,7 +120,7 @@ foreach (get_list_of_plugins('grade/report') as $plugin) {
 
     if (file_exists($CFG->dirroot.'/grade/report/'.$plugin.'/settings.php')) {
 
-        $settings = new admin_settingpage('gradereport'.$plugin, get_string('modulename', 'gradereport_'.$plugin));
+        $settings = new admin_settingpage('gradereport'.$plugin, get_string('modulename', 'gradereport_'.$plugin), 'moodle/grade:manage');
         include($CFG->dirroot.'/grade/report/'.$plugin.'/settings.php');
         $ADMIN->add('gradereports', $settings);
     }
@@ -135,7 +138,7 @@ foreach (get_list_of_plugins('grade/import') as $plugin) {
             $first = false;
         }
 
-        $settings = new admin_settingpage('gradeimport'.$plugin, get_string('modulename', 'gradeimport_'.$plugin));
+        $settings = new admin_settingpage('gradeimport'.$plugin, get_string('modulename', 'gradeimport_'.$plugin), 'moodle/grade:manage');
         include($CFG->dirroot.'/grade/import/'.$plugin.'/settings.php');
         $ADMIN->add('gradeimports', $settings);
     }
@@ -153,9 +156,12 @@ foreach (get_list_of_plugins('grade/export') as $plugin) {
             $first = false;
         }
 
-        $settings = new admin_settingpage('gradeexport'.$plugin, get_string('modulename', 'gradeexport_'.$plugin));
+        $settings = new admin_settingpage('gradeexport'.$plugin, get_string('modulename', 'gradeexport_'.$plugin), 'moodle/grade:manage');
         include($CFG->dirroot.'/grade/export/'.$plugin.'/settings.php');
         $ADMIN->add('gradeexports', $settings);
     }
 }
+
+} // end of speedup
+
 ?>
index ea155e2c93efeeefc11563b7744cd4f41534e0e3..379e5c031805b9ea25ca137b14730b54399bb4c0 100644 (file)
@@ -2,6 +2,9 @@
 
 // This file defines settingpages and externalpages under the "appearance" category
 
+if ($hassiteconfig) { // speedup for non-admins, add all caps used on this page
+
+
 // "languageandlocation" settingpage
 $temp = new admin_settingpage('langsettings', get_string('languagesettings', 'admin'));
 $temp->add(new admin_setting_configselect('lang', get_string('lang', 'admin'), get_string('configlang', 'admin'), current_language(), get_list_of_languages())); // $CFG->lang might be set in installer already, default en or en_utf8 is in setup.php
@@ -19,4 +22,6 @@ $ADMIN->add('language', $temp);
 $ADMIN->add('language', new admin_externalpage('langedit', get_string('langedit', 'admin'), "$CFG->wwwroot/$CFG->admin/lang.php"));
 $ADMIN->add('language', new admin_externalpage('langimport', get_string('langpacks', 'admin'), "$CFG->wwwroot/$CFG->admin/langimport.php"));
 
+} // end of speedup
+
 ?>
index 2ec09bc2bc9b787a6d1675d98993fe289c9f56d5..a054ca53422b254f451e576c117d97aa0cc1e952 100644 (file)
@@ -1,5 +1,8 @@
 <?php // $Id$
 
+if ($hassiteconfig) { // speedup for non-admins, add all caps used on this page
+
+
 // "locations" settingpage
 $temp = new admin_settingpage('locationsettings', get_string('locationsettings', 'admin'));
 $options = get_list_of_timezones();
@@ -24,4 +27,6 @@ $ADMIN->add('location', $temp);
 
 $ADMIN->add('location', new admin_externalpage('timezoneimport', get_string('updatetimezones', 'admin'), "$CFG->wwwroot/$CFG->admin/timezoneimport.php"));
 
+} // end of speedup
+
 ?>
index 9e030be0240256767b2f3711a2f141d2fe95e86e..bf2d04a719f29912b4ad74d92b6bc7817b7e5eb9 100644 (file)
@@ -2,6 +2,9 @@
 
 // * Miscellaneous settings
 
+if ($hassiteconfig) { // speedup for non-admins, add all caps used on this page
+
+
 // Experimental settings page
 $temp = new admin_settingpage('experimental', get_string('experimental', 'admin'));
 $temp->add(new admin_setting_configcheckbox('enableglobalsearch', get_string('enableglobalsearch', 'admin'), get_string('configenableglobalsearch', 'admin'), 0));
@@ -21,4 +24,6 @@ $ADMIN->add('misc', new admin_externalpage('upgradeforumread', 'Upgrade forum',
 $ADMIN->add('misc', new admin_externalpage('upgradelogs', 'Upgrade logs', $CFG->wwwroot.'/'.$CFG->admin.'/upgradelogs.php', 'moodle/site:config', true));
 $ADMIN->add('misc', new admin_externalpage('multilangupgrade', get_string('multilangupgrade', 'admin'), $CFG->wwwroot.'/'.$CFG->admin.'/multilangupgrade.php', 'moodle/site:config', !empty($CFG->filter_multilang_converted)));
 
+} // end of speedup
+
 ?>
index 1f5e8c7c418238f0f26eafdeb48d3439c8d92177..66cbc8934b0501283876753423cff93e3e346fdd 100644 (file)
@@ -2,6 +2,9 @@
 
 // This file defines settingpages and externalpages under the "mnet" category
 
+if ($hassiteconfig) { // speedup for non-admins, add all caps used on this page
+
+
 $ADMIN->add('mnet', new admin_externalpage('net', get_string('settings', 'mnet'), 
                                            $CFG->wwwroot . '/admin/mnet/index.php', 
                                            'moodle/site:config'));
@@ -18,4 +21,7 @@ $ADMIN->add('mnet', new admin_externalpage('mnetenrol', get_string('mnetenrol',
 $ADMIN->add('mnet', new admin_externalpage('trustedhosts', get_string('trustedhosts', 'mnet'), 
                                            $CFG->wwwroot . '/admin/mnet/trustedhosts.php', 
                                            'moodle/site:config'));
+
+} // end of speedup
+
 ?>
index 285007849ea238b5fb7ad93aa7fb1e05cbeb3355..9c91e16d043ceb7461d3dbd6c8b82957f3605294 100644 (file)
@@ -1,5 +1,6 @@
 <?php // $Id$
 
+if ($hassiteconfig) { // speedup for non-admins, add all caps used on this page
 
 
 // "sitepolicies" settingpage
@@ -108,4 +109,6 @@ $temp->add(new admin_setting_configselect('clamfailureonupload', get_string('cla
                                                                                                                                                                                   'actlikevirus' => get_string('configclamactlikevirus', 'admin'))));
 $ADMIN->add('security', $temp);
 
+} // end of speedup
+
 ?>
index c095de24edbedd103e40d9da938bc3cfaec38d27..b6cdd8b1bd596869eea9024d24c8837f56a1b76a 100644 (file)
@@ -2,6 +2,9 @@
 
 // This file defines settingpages and externalpages under the "server" category
 
+if ($hassiteconfig) { // speedup for non-admins, add all caps used on this page
+
+
 // "systempaths" settingpage
 $temp = new admin_settingpage('systempaths', get_string('systempaths','admin'));
 $temp->add(new admin_setting_configselect('gdversion', get_string('gdversion','admin'), get_string('configgdversion', 'admin'), check_gd_version(), array('0' => get_string('gdnot'),
@@ -216,4 +219,6 @@ if (file_exists("$CFG->dirroot/$CFG->admin/mysql/frame.php")) {
     $ADMIN->add('server', new admin_externalpage('database', get_string('managedatabase'), "$CFG->wwwroot/$CFG->admin/mysql/frame.php"));
 }
 
+} // end of speedup
+
 ?>
index 55938e8aa9d2bba0a81192c782ecc5b174770896..d76f04b8f006a9ff255f6211ded88b8fb16cfba9 100644 (file)
@@ -6,6 +6,7 @@
 // are added to them.
 
 $systemcontext = get_context_instance(CONTEXT_SYSTEM);
+$hassiteconfig = has_capability('moodle/site:config', $systemcontext);
 
 $ADMIN->add('root', new admin_externalpage('adminnotifications', get_string('notifications'), "$CFG->wwwroot/$CFG->admin/index.php"));
 
index 427fda0b6a6a7506036944e41619925cc9a96902..f0170f15bb4a7c14636418b9fd0059e5a9c3560f 100644 (file)
@@ -2,10 +2,13 @@
 
 // This file defines settingpages and externalpages in the "unsupported" hidden category, use wisely!
 
+if ($hassiteconfig) { // speedup for non-admins, add all caps used on this page
+
 $ADMIN->add('unsupported', new admin_externalpage('purgemoodledata', 'Purge moodledata', $CFG->wwwroot.'/'.$CFG->admin.'/delete.php'));
 $ADMIN->add('unsupported', new admin_externalpage('healthcenter', get_string('healthcenter'), $CFG->wwwroot.'/'.$CFG->admin.'/health.php'));
 $ADMIN->add('unsupported', new admin_externalpage('toinodb', 'Convert to InnoDB', $CFG->wwwroot.'/'.$CFG->admin.'/innodb.php'));
 $ADMIN->add('unsupported', new admin_externalpage('replace', 'Search and replace', $CFG->wwwroot.'/'.$CFG->admin.'/replace.php'));
 
+} // end of speedup
 
 ?>
index 4d1802d9ef4ccaa0e275509d7ec3271c6f440cba..b0fd5e9e54c75a09bdbac6228f9df0f746f973dd 100644 (file)
@@ -2,7 +2,7 @@
 
 // This file defines settingpages and externalpages under the "users" category
 
-if (has_capability('moodle/site:config',$systemcontext)) { // speedup for non-admins
+if ($hassiteconfig) { // speedup for non-admins, add all caps used on this page
 
 
 $ADMIN->add('users', new admin_externalpage('userauthentication', get_string('authentication','admin'), "$CFG->wwwroot/$CFG->admin/auth.php"));
@@ -108,6 +108,6 @@ $temp->add(new admin_setting_configmultiselect('hiddenuserfields', get_string('h
 
 $ADMIN->add('roles', $temp);
 
-} // end of admin tree capability if
+} // end of speedup
 
 ?>
index 5bf4bbf16c680c7256168494ebd345a7e42d7966..228b75f0edc5fe384c4cfa2d0d56c3a906d950a6 100644 (file)
@@ -22,11 +22,8 @@ class block_admin_tree extends block_base {
     }
 
     function applicable_formats() {
-        if (block_admin_tree::has_admin_caps()) {
-            return array('site' => true, 'admin' => true, 'my' => true);
-        } else {
-            return array('site' => true);
-        }
+        //TODO: add 'my' only if user has role assigned in system or any course category context
+        return array('site' => true, 'admin' => true, 'my' => true);
     }
 
     function preferred_width() {
@@ -104,7 +101,8 @@ class block_admin_tree extends block_base {
             return $this->content;
         }
 
-        if (!($this->has_admin_caps())) {
+        if (isguestuser() or !isloggedin()) {
+            // these users can not change any settings
             $this->content = '';
             return '';
         }
@@ -213,28 +211,6 @@ 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/grade:manage',         $sysctx)
-                || has_capability('moodle/grade:manageletters',  $sysctx)
-                || has_capability('moodle/grade:managescales',   $sysctx)
-                || has_capability('moodle/site:readallmessages', $sysctx));
-    }
 }
 
 ?>