From: skodak Date: Wed, 26 Nov 2008 19:27:39 +0000 (+0000) Subject: MDL-17372 admin reports: Added full plugin support for admin reports; added specail... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=d994ced22b713c7dc541dc23207fe66e32094620;p=moodle.git MDL-17372 admin reports: Added full plugin support for admin reports; added specail capability for unittest execution, minor refactoring --- diff --git a/admin/report/backups/index.php b/admin/report/backups/index.php index 612501c4dd..d380cbb6d7 100644 --- a/admin/report/backups/index.php +++ b/admin/report/backups/index.php @@ -5,13 +5,10 @@ require_once($CFG->libdir.'/adminlib.php'); require_once($CFG->dirroot.'/backup/lib.php'); - admin_externalpage_setup('reportbackups'); - - admin_externalpage_print_header(); - $courseid = optional_param('courseid', 0, PARAM_INT); - require_capability('moodle/site:backup', get_context_instance(CONTEXT_SYSTEM)); + admin_externalpage_setup('reportbackups'); + admin_externalpage_print_header(); /// Scheduled backups are disabled by the server admin if (!empty($CFG->disablescheduledbackups)) { diff --git a/admin/report/courseoverview/index.php b/admin/report/courseoverview/index.php index 6e0792f0e4..712b32adc1 100644 --- a/admin/report/courseoverview/index.php +++ b/admin/report/courseoverview/index.php @@ -4,15 +4,12 @@ require_once($CFG->dirroot.'/lib/statslib.php'); require_once($CFG->libdir.'/adminlib.php'); - admin_externalpage_setup('reportcourseoverview'); - - admin_externalpage_print_header(); - $report = optional_param('report', STATS_REPORT_ACTIVE_COURSES, PARAM_INT); $time = optional_param('time', 0, PARAM_INT); $numcourses = optional_param('numcourses', 20, PARAM_INT); - require_capability('moodle/site:viewreports', get_context_instance(CONTEXT_SYSTEM)); // needed? + admin_externalpage_setup('reportcourseoverview'); + admin_externalpage_print_header(); if (empty($CFG->enablestats)) { redirect("$CFG->wwwroot/$CFG->admin/settings.php?section=stats", get_string('mustenablestats', 'admin'), 3); diff --git a/admin/report/courseoverview/settings.php b/admin/report/courseoverview/settings.php new file mode 100644 index 0000000000..cb54298156 --- /dev/null +++ b/admin/report/courseoverview/settings.php @@ -0,0 +1,3 @@ +add('reports', new admin_externalpage('reportcourseoverview', get_string('courseoverview', 'admin'), "$CFG->wwwroot/$CFG->admin/report/courseoverview/index.php",'moodle/site:viewreports')); +?> \ No newline at end of file diff --git a/admin/report/log/index.php b/admin/report/log/index.php index df808f31b5..2878ee76c0 100644 --- a/admin/report/log/index.php +++ b/admin/report/log/index.php @@ -6,7 +6,6 @@ require_once($CFG->libdir.'/adminlib.php'); admin_externalpage_setup('reportlog'); - admin_externalpage_print_header(); diff --git a/admin/report/log/settings.php b/admin/report/log/settings.php new file mode 100644 index 0000000000..1f11339668 --- /dev/null +++ b/admin/report/log/settings.php @@ -0,0 +1,3 @@ +add('reports', new admin_externalpage('reportlog', get_string('log', 'admin'), "$CFG->wwwroot/$CFG->admin/report/log/index.php",'moodle/site:viewreports')); +?> \ No newline at end of file diff --git a/admin/report/questioninstances/index.php b/admin/report/questioninstances/index.php index 598d4f4eb1..d4852422ca 100644 --- a/admin/report/questioninstances/index.php +++ b/admin/report/questioninstances/index.php @@ -11,21 +11,16 @@ require_once(dirname(__FILE__).'/../../../config.php'); require_once($CFG->libdir.'/adminlib.php'); require_once($CFG->libdir.'/questionlib.php'); -// Check permissions. -require_login(); -$systemcontext = get_context_instance(CONTEXT_SYSTEM); -require_capability('moodle/site:viewreports', $systemcontext); - // Get URL parameters. $requestedqtype = optional_param('qtype', '', PARAM_SAFEDIR); -// Log. -add_to_log(SITEID, "admin", "report questioninstances", "report/questioninstances/index.php?qtype=$requestedqtype", $requestedqtype); - -// Print the header. +// Print the header & check permissions. admin_externalpage_setup('reportquestioninstances'); admin_externalpage_print_header(); +// Log. +add_to_log(SITEID, "admin", "report questioninstances", "report/questioninstances/index.php?qtype=$requestedqtype", $requestedqtype); + // Prepare the list of capabilites to choose from $qtypechoices = array(); foreach ($QTYPES as $qtype) { diff --git a/admin/report/questioninstances/settings.php b/admin/report/questioninstances/settings.php new file mode 100644 index 0000000000..fea0d3c800 --- /dev/null +++ b/admin/report/questioninstances/settings.php @@ -0,0 +1,3 @@ +add('reports', new admin_externalpage('reportquestioninstances', get_string('questioninstances', 'report_questioninstances'), "$CFG->wwwroot/$CFG->admin/report/questioninstances/index.php", 'moodle/site:viewreports')); +?> \ No newline at end of file diff --git a/admin/report/stats/index.php b/admin/report/stats/index.php index 86ce469ff0..8f0e86853e 100644 --- a/admin/report/stats/index.php +++ b/admin/report/stats/index.php @@ -6,11 +6,6 @@ require_once($CFG->libdir.'/adminlib.php'); - admin_externalpage_setup('reportstats'); - - admin_externalpage_print_header(); - - $courseid = optional_param('course', SITEID, PARAM_INT); $report = optional_param('report', 0, PARAM_INT); $time = optional_param('time', 0, PARAM_INT); @@ -18,6 +13,13 @@ $userid = optional_param('userid', 0, PARAM_INT); $roleid = 0; + admin_externalpage_setup('reportstats'); + admin_externalpage_print_header(); + + if (empty($CFG->enablestats)) { + redirect("$CFG->wwwroot/$CFG->admin/settings.php?section=stats", get_string('mustenablestats', 'admin'), 3); + } + if ($report > 50) { $roleid = substr($report,1); $report = 5; @@ -41,14 +43,6 @@ } } - require_login(); - - if (empty($CFG->enablestats)) { - redirect("$CFG->wwwroot/$CFG->admin/settings.php?section=stats", get_string('mustenablestats', 'admin'), 3); - } - - require_capability('moodle/site:viewreports', get_context_instance(CONTEXT_SYSTEM)); - add_to_log($course->id, "course", "report stats", "report/stats/index.php?course=$course->id", $course->id); stats_check_uptodate($course->id); diff --git a/admin/report/stats/settings.php b/admin/report/stats/settings.php index beb5c038bb..5eca48c38e 100644 --- a/admin/report/stats/settings.php +++ b/admin/report/stats/settings.php @@ -1,5 +1,3 @@ enablestats)) { - $ADMIN->add('reports', new admin_externalpage('reportstats', get_string('stats', 'admin'), "$CFG->wwwroot/$CFG->admin/report/stats/index.php",'moodle/site:viewreports')); -} +$ADMIN->add('reports', new admin_externalpage('reportstats', get_string('stats', 'admin'), "$CFG->wwwroot/$CFG->admin/report/stats/index.php",'moodle/site:viewreports')); ?> \ No newline at end of file diff --git a/admin/report/unittest/db/access.php b/admin/report/unittest/db/access.php new file mode 100644 index 0000000000..dd9915f05c --- /dev/null +++ b/admin/report/unittest/db/access.php @@ -0,0 +1,40 @@ + array( + 'riskbitmask' => RISK_DATALOSS, + 'captype' => 'read', + 'contextlevel' => CONTEXT_SYSTEM, + 'legacy' => array( + 'admin' => CAP_ALLOW + ), + + 'clonepermissionsfrom' => 'moodle/site:config', + ) +); + +?> diff --git a/admin/report/unittest/dbtest.php b/admin/report/unittest/dbtest.php index 506b9d0051..dd58e15235 100644 --- a/admin/report/unittest/dbtest.php +++ b/admin/report/unittest/dbtest.php @@ -11,12 +11,13 @@ require_once($CFG->libdir.'/simpletestlib.php'); require_once('ex_simple_test.php'); require_once('ex_reporter.php'); -require_login(); -require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM)); - $showpasses = optional_param('showpasses', 0, PARAM_BOOL); $selected = optional_param('selected', array(), PARAM_INT); +// Print the header and check access. +admin_externalpage_setup('reportdbtest'); +admin_externalpage_print_header(); + global $UNITTEST; $UNITTEST = new object(); @@ -27,9 +28,6 @@ if (!data_submitted()) { } } -// Print the header. -admin_externalpage_setup('reportdbtest'); -admin_externalpage_print_header(); $dbinfos = array(); $tests = array(); diff --git a/admin/report/unittest/index.php b/admin/report/unittest/index.php index 10adcfd6b9..47a350f900 100644 --- a/admin/report/unittest/index.php +++ b/admin/report/unittest/index.php @@ -16,12 +16,6 @@ require_once($CFG->libdir.'/simpletestlib.php'); require_once('ex_simple_test.php'); require_once('ex_reporter.php'); -require_login(); -require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM)); - -$langfile = 'simpletest'; -$unittest = true; - // CGI arguments $path = optional_param('path', null, PARAM_PATH); $showpasses = optional_param('showpasses', false, PARAM_BOOL); @@ -35,13 +29,17 @@ $continuesetuptesttables = optional_param('continuesetuptesttables', false, PARA $droptesttables = optional_param('droptesttables', false, PARAM_BOOL); $testtablesok = optional_param('testtablesok', false, PARAM_BOOL); +admin_externalpage_setup('reportsimpletest'); +admin_externalpage_print_header(); + +$langfile = 'simpletest'; +$unittest = true; + global $UNITTEST; $UNITTEST = new object(); // Print the header. -admin_externalpage_setup('reportsimpletest'); $strtitle = get_string('unittests', $langfile); -admin_externalpage_print_header(); if ($testtablesok) { print_heading(get_string('testtablesok', 'simpletest')); diff --git a/admin/report/unittest/settings.php b/admin/report/unittest/settings.php index 2c2d3f0538..8bccf04f75 100644 --- a/admin/report/unittest/settings.php +++ b/admin/report/unittest/settings.php @@ -1,6 +1,6 @@ add('development', new admin_externalpage('reportsimpletest', get_string('simpletest', 'admin'), "$CFG->wwwroot/$CFG->admin/report/unittest/index.php",'moodle/site:config')); - $ADMIN->add('development', new admin_externalpage('reportdbtest', get_string('dbtest', 'admin'), "$CFG->wwwroot/$CFG->admin/report/unittest/dbtest.php",'moodle/site:config')); + $ADMIN->add('development', new admin_externalpage('reportsimpletest', get_string('simpletest', 'admin'), "$CFG->wwwroot/$CFG->admin/report/unittest/index.php",'report/unittest:view')); + $ADMIN->add('development', new admin_externalpage('reportdbtest', get_string('dbtest', 'admin'), "$CFG->wwwroot/$CFG->admin/report/unittest/dbtest.php",'report/unittest:view')); } ?> \ No newline at end of file diff --git a/admin/report/unittest/version.php b/admin/report/unittest/version.php new file mode 100644 index 0000000000..645c20a45c --- /dev/null +++ b/admin/report/unittest/version.php @@ -0,0 +1,29 @@ +version = 2008112601; +$plugin->requires = 2008112600; + +?> diff --git a/admin/settings/report.php b/admin/settings/report.php new file mode 100644 index 0000000000..790d0d7353 --- /dev/null +++ b/admin/settings/report.php @@ -0,0 +1,18 @@ +admin.'/report') as $plugin) { + $settings_path = "$CFG->dirroot/$CFG->admin/report/$plugin/settings.php"; + if (file_exists($settings_path)) { + include($settings_path); + continue; + } + + $index_path = "$CFG->dirroot/$CFG->admin/report/$plugin/index.php"; + if (!file_exists($index_path)) { + continue; + } + // old style 3rd party plugin without settings.php + $ADMIN->add('reports', new admin_externalpage('report'.$plugin, $plugin, $index_path, 'moodle/site:viewreports')); +} + +?> diff --git a/admin/settings/top.php b/admin/settings/top.php index e295eae035..b09703ee1b 100644 --- a/admin/settings/top.php +++ b/admin/settings/top.php @@ -24,6 +24,9 @@ if ($hassiteconfig) { } $ADMIN->add('root', new admin_category('users', get_string('users','admin'))); + $ADMIN->add('users', new admin_category('authsettings', get_string('authentication','admin'))); + $ADMIN->add('users', new admin_category('accounts', get_string('accounts', 'admin'))); + $ADMIN->add('users', new admin_category('roles', get_string('permissions', 'role'))); $ADMIN->add('root', new admin_category('courses', get_string('courses','admin'))); $ADMIN->add('root', new admin_category('grades', get_string('grades'))); $ADMIN->add('root', new admin_category('location', get_string('location','admin'))); @@ -36,8 +39,10 @@ $ADMIN->add('root', new admin_category('server', get_string('server','admin'))); $ADMIN->add('root', new admin_category('mnet', get_string('net','mnet'), (isset($CFG->mnet_dispatcher_mode) and $CFG->mnet_dispatcher_mode === 'off'))); $ADMIN->add('root', new admin_category('reports', get_string('reports'))); $ADMIN->add('root', new admin_category('development', get_string('development', 'admin'))); + // hidden unsupported category $ADMIN->add('root', new admin_category('unsupported', get_string('unsupported', 'admin'), true)); + // hidden search script $ADMIN->add('root', new admin_externalpage('search', get_string('searchresults'), "$CFG->wwwroot/$CFG->admin/search.php", 'moodle/site:config', true)); diff --git a/admin/settings/users.php b/admin/settings/users.php index f703294c9d..17de059d2e 100644 --- a/admin/settings/users.php +++ b/admin/settings/users.php @@ -11,8 +11,6 @@ if ($hassiteconfig or has_capability('moodle/role:assign', $systemcontext)) { // speedup for non-admins, add all caps used on this page - $ADMIN->add('users', new admin_category('authsettings', get_string('authentication','admin'))); - $temp = new admin_settingpage('manageauths', get_string('authsettings', 'admin')); $temp->add(new admin_setting_manageauths()); $temp->add(new admin_setting_heading('manageauthscommonheading', get_string('commonsettings', 'admin'), '')); @@ -70,7 +68,6 @@ if ($hassiteconfig $securewwwroot = str_replace('http:','https:',$CFG->wwwroot); } // stuff under the "accounts" subcategory - $ADMIN->add('users', new admin_category('accounts', get_string('accounts', 'admin'))); $ADMIN->add('accounts', new admin_externalpage('editusers', get_string('userlist','admin'), "$CFG->wwwroot/$CFG->admin/user.php", array('moodle/user:update', 'moodle/user:delete'))); $ADMIN->add('accounts', new admin_externalpage('userbulk', get_string('userbulk','admin'), "$CFG->wwwroot/$CFG->admin/user/user_bulk.php", array('moodle/user:update', 'moodle/user:delete'))); $ADMIN->add('accounts', new admin_externalpage('addnewuser', get_string('addnewuser'), "$securewwwroot/user/editadvanced.php?id=-1", 'moodle/user:create')); @@ -80,7 +77,6 @@ if ($hassiteconfig // stuff under the "roles" subcategory - $ADMIN->add('users', new admin_category('roles', get_string('permissions', 'role'))); // "userpolicies" settingpage $temp = new admin_settingpage('userpolicies', get_string('userpolicies', 'admin')); diff --git a/lang/en_utf8/report_unittest.php b/lang/en_utf8/report_unittest.php new file mode 100644 index 0000000000..2227cf0d9a --- /dev/null +++ b/lang/en_utf8/report_unittest.php @@ -0,0 +1,5 @@ + diff --git a/lib/accesslib.php b/lib/accesslib.php index 8160cced27..b3c36b8cc8 100755 --- a/lib/accesslib.php +++ b/lib/accesslib.php @@ -3028,7 +3028,11 @@ function load_capability_def($component) { } else { $compparts = explode('/', $component); - if ($compparts[0] == 'block') { + if ($compparts[0] == 'report') { + $defpath = $CFG->dirroot.'/'.$CFG->admin.'/report/'.$compparts[1].'/db/access.php'; + $varprefix = $compparts[0].'_'.$compparts[1]; + + } else if ($compparts[0] == 'block') { // Blocks are an exception. Blocks directory is 'blocks', and not // 'block'. So we need to jump through hoops. $defpath = $CFG->dirroot.'/'.$compparts[0]. @@ -3884,6 +3888,10 @@ function get_capability_string($capabilityname) { $componentname = $components[0]; // choice switch ($names[0]) { + case 'report': + $string = get_string($stringname, 'report_'.$componentname); + break; + case 'mod': $string = get_string($stringname, $componentname); break; @@ -3952,6 +3960,8 @@ function get_component_string($component, $contextlevel) { } else if (preg_match('|^local|', $component)) { $langname = str_replace('/', '_', $component); $string = get_string('local'); + } else if (preg_match('|^report/|', $component)) { + $string = get_string('reports'); } else { $string = get_string('coresystem'); } @@ -5547,7 +5557,10 @@ function component_level_changed($cap, $comp, $contextlevel) { $compsa = explode('/', $cap->component); $compsb = explode('/', $comp); - + // list of system reports + if (($compsa[0] == 'report') &&($compsb[0] == 'report')) { + return false; + } // we are in gradebook, still if (($compsa[0] == 'gradeexport' || $compsa[0] == 'gradeimport' || $compsa[0] == 'gradereport') && diff --git a/lib/adminlib.php b/lib/adminlib.php index 89d0ac81c8..9cfb22f143 100644 --- a/lib/adminlib.php +++ b/lib/adminlib.php @@ -5380,21 +5380,6 @@ function &admin_get_root($reload=false, $requirefulltree=true) { } } - // Add all the report plugings. Do this last so they can choose where in the tree - // they want to be added. - foreach (get_list_of_plugins($CFG->admin.'/report') as $plugin) { - $settingsfile = "$CFG->dirroot/$CFG->admin/report/$plugin/settings.php"; - if (file_exists($settingsfile)) { - include($settingsfile); - } else { - $reportname = get_string($plugin, 'report_' . $plugin); - if ($reportname[1] == '[') { - $reportname = get_string($plugin, 'admin'); - } - $ADMIN->add('reports', new admin_externalpage('report'.$plugin, $reportname, "$CFG->wwwroot/$CFG->admin/report/$plugin/index.php",'moodle/site:viewreports')); - } - } - if (file_exists($CFG->dirroot.'/local/settings.php')) { include_once($CFG->dirroot.'/local/settings.php'); } diff --git a/version.php b/version.php index 9f793bb7e0..0bc166ba5c 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 = 2008112400; // YYYYMMDD = date of the last version bump + $version = 2008112600; // YYYYMMDD = date of the last version bump // XX = daily increments $release = '2.0 dev (Build: 20081126)'; // Human-friendly version name