From 2d89f2de76965d469c61b0c43698950665e6d8ca Mon Sep 17 00:00:00 2001 From: skodak Date: Wed, 26 Nov 2008 20:58:03 +0000 Subject: [PATCH] MDL-17372 admin reports: Added full plugin support for admin reports; added specail capability for unittest execution, minor refactoring - backported from HEAD --- admin/report/backups/index.php | 7 +--- admin/report/backups/settings.php | 3 ++ admin/report/courseoverview/index.php | 7 +--- admin/report/courseoverview/settings.php | 3 ++ admin/report/log/index.php | 1 - admin/report/log/settings.php | 3 ++ admin/report/question/index.php | 2 +- admin/report/question/settings.php | 3 ++ admin/report/stats/index.php | 12 +++--- admin/report/stats/settings.php | 3 ++ admin/report/unittest/db/access.php | 40 +++++++++++++++++++ .../{simpletest => unittest}/ex_reporter.php | 0 .../ex_simple_test.php | 0 .../report/{simpletest => unittest}/index.php | 18 ++++----- admin/report/unittest/settings.php | 3 ++ admin/report/unittest/version.php | 29 ++++++++++++++ admin/settings/report.php | 18 +++++++++ admin/settings/top.php | 25 ++---------- admin/settings/users.php | 4 -- lang/en_utf8/report_unittest.php | 5 +++ lib/accesslib.php | 17 +++++++- lib/moodlelib.php | 2 +- theme/standard/styles_color.css | 16 ++++---- theme/standard/styles_layout.css | 4 +- version.php | 2 +- 25 files changed, 160 insertions(+), 67 deletions(-) create mode 100644 admin/report/backups/settings.php create mode 100644 admin/report/courseoverview/settings.php create mode 100644 admin/report/log/settings.php create mode 100644 admin/report/question/settings.php create mode 100644 admin/report/stats/settings.php create mode 100644 admin/report/unittest/db/access.php rename admin/report/{simpletest => unittest}/ex_reporter.php (100%) rename admin/report/{simpletest => unittest}/ex_simple_test.php (100%) rename admin/report/{simpletest => unittest}/index.php (96%) create mode 100644 admin/report/unittest/settings.php create mode 100644 admin/report/unittest/version.php create mode 100644 admin/settings/report.php create mode 100644 lang/en_utf8/report_unittest.php diff --git a/admin/report/backups/index.php b/admin/report/backups/index.php index bbb707359383e..bdb0bd22188e7 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/backups/settings.php b/admin/report/backups/settings.php new file mode 100644 index 0000000000000..e80322b0606f7 --- /dev/null +++ b/admin/report/backups/settings.php @@ -0,0 +1,3 @@ +add('reports', new admin_externalpage('reportbackups', get_string('backups', 'admin'), "$CFG->wwwroot/$CFG->admin/report/backups/index.php",'moodle/site:backup')); +?> \ No newline at end of file diff --git a/admin/report/courseoverview/index.php b/admin/report/courseoverview/index.php index 64d9bd56e6a2b..38f4865d036d4 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 0000000000000..cb54298156a3e --- /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 df808f31b572d..2878ee76c0da4 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 0000000000000..1f11339668793 --- /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/question/index.php b/admin/report/question/index.php index 67ab0779ee114..d327900606cb7 100644 --- a/admin/report/question/index.php +++ b/admin/report/question/index.php @@ -5,8 +5,8 @@ require_once($CFG->libdir.'/adminlib.php'); admin_externalpage_setup('reportquestion'); - admin_externalpage_print_header(); + print_heading(get_string('adminreport', 'question')); $probstr = ''; diff --git a/admin/report/question/settings.php b/admin/report/question/settings.php new file mode 100644 index 0000000000000..2fe9fbfa490cc --- /dev/null +++ b/admin/report/question/settings.php @@ -0,0 +1,3 @@ +add('reports', new admin_externalpage('reportquestion', get_string('question', 'admin'), "$CFG->wwwroot/$CFG->admin/report/question/index.php", 'moodle/site:config')); +?> \ No newline at end of file diff --git a/admin/report/stats/index.php b/admin/report/stats/index.php index 0cfd68de55844..ac11b13be3809 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; diff --git a/admin/report/stats/settings.php b/admin/report/stats/settings.php new file mode 100644 index 0000000000000..5eca48c38efc8 --- /dev/null +++ b/admin/report/stats/settings.php @@ -0,0 +1,3 @@ +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 0000000000000..dd9915f05c17a --- /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/simpletest/ex_reporter.php b/admin/report/unittest/ex_reporter.php similarity index 100% rename from admin/report/simpletest/ex_reporter.php rename to admin/report/unittest/ex_reporter.php diff --git a/admin/report/simpletest/ex_simple_test.php b/admin/report/unittest/ex_simple_test.php similarity index 100% rename from admin/report/simpletest/ex_simple_test.php rename to admin/report/unittest/ex_simple_test.php diff --git a/admin/report/simpletest/index.php b/admin/report/unittest/index.php similarity index 96% rename from admin/report/simpletest/index.php rename to admin/report/unittest/index.php index 635a7f66f1452..281800cc7cde0 100644 --- a/admin/report/simpletest/index.php +++ b/admin/report/unittest/index.php @@ -16,14 +16,6 @@ require_once('ex_simple_test.php'); require_once('ex_reporter.php'); -require_login(); -require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM)); - -/* The UNITTEST constant can be checked elsewhere if you need to know - * when your code is being run as part of a unit test. */ -define('UNITTEST', true); -$langfile = 'simpletest'; - // CGI arguments $path = optional_param('path', null, PARAM_PATH); $showpasses = optional_param('showpasses', false, PARAM_BOOL); @@ -31,10 +23,16 @@ $thorough = optional_param('thorough', false, PARAM_BOOL); // Print the header. -admin_externalpage_setup('reportsimpletest'); -$strtitle = get_string('unittests', $langfile); +admin_externalpage_setup('reportunittest'); admin_externalpage_print_header(); +/* The UNITTEST constant can be checked elsewhere if you need to know + * when your code is being run as part of a unit test. */ +define('UNITTEST', true); +$langfile = 'simpletest'; + +$strtitle = get_string('unittests', $langfile); + if (!is_null($path)) { // Create the group of tests. $test =& new AutoGroupTest($showsearch, $thorough); diff --git a/admin/report/unittest/settings.php b/admin/report/unittest/settings.php new file mode 100644 index 0000000000000..e0f81a77183a2 --- /dev/null +++ b/admin/report/unittest/settings.php @@ -0,0 +1,3 @@ +add('reports', new admin_externalpage('reportunittest', get_string('simpletest', 'admin'), "$CFG->wwwroot/$CFG->admin/report/unittest/index.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 0000000000000..c62920f9d7c3b --- /dev/null +++ b/admin/report/unittest/version.php @@ -0,0 +1,29 @@ +version = 2007101500; +$plugin->requires = 2007101532; + +?> diff --git a/admin/settings/report.php b/admin/settings/report.php new file mode 100644 index 0000000000000..eea1665be808a --- /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 a892b3449d516..c41ab9d81601d 100644 --- a/admin/settings/top.php +++ b/admin/settings/top.php @@ -19,39 +19,20 @@ $ADMIN->add('root', new admin_externalpage('upgradesettings', get_string('upgradesettings', 'admin'), "$CFG->wwwroot/$CFG->admin/upgradesettings.php", 'moodle/site:config', true)); $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'))); $ADMIN->add('root', new admin_category('language', get_string('language'))); - $ADMIN->add('root', new admin_category('modules', get_string('plugins', 'admin'))); - $ADMIN->add('root', new admin_category('security', get_string('security','admin'))); $ADMIN->add('root', new admin_category('appearance', get_string('appearance','admin'))); $ADMIN->add('root', new admin_category('frontpage', get_string('frontpage','admin'))); $ADMIN->add('root', new admin_category('server', get_string('server','admin'))); $ADMIN->add('root', new admin_category('mnet', get_string('net','mnet'))); - $ADMIN->add('root', new admin_category('reports', get_string('reports'))); -foreach (get_list_of_plugins($CFG->admin.'/report') as $plugin) { -/// This snippet is temporary until simpletest can be fixed to use xmldb. See MDL-7377 XXX TODO - if ($plugin == 'simpletest' && $CFG->dbfamily != 'mysql' && $CFG->dbfamily != 'postgres') { - continue; - } -/// End of removable snippet - $reportname = get_string($plugin, 'report_' . $plugin); - if ($reportname[1] == '[') { - $reportname = get_string($plugin, 'admin'); - } - // ugly hack for special access control in reports - switch($plugin) { - case 'backups': $cap = 'moodle/site:backup'; break; - case 'simpletest': $cap = 'moodle/site:config'; break; - default: $cap = 'moodle/site:viewreports'; - } - $ADMIN->add('reports', new admin_externalpage('report'.$plugin, $reportname, "$CFG->wwwroot/$CFG->admin/report/$plugin/index.php",$cap)); -} - $ADMIN->add('root', new admin_category('misc', get_string('miscellaneous'))); // hidden unsupported category diff --git a/admin/settings/users.php b/admin/settings/users.php index af666a44f70da..3aa0d7b1f638e 100644 --- a/admin/settings/users.php +++ b/admin/settings/users.php @@ -11,8 +11,6 @@ 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 @@ $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 @@ // stuff under the "roles" subcategory - $ADMIN->add('users', new admin_category('roles', get_string('permissions', 'role'))); $ADMIN->add('roles', new admin_externalpage('defineroles', get_string('defineroles', 'role'), "$CFG->wwwroot/$CFG->admin/roles/manage.php", 'moodle/role:manage')); $ADMIN->add('roles', new admin_externalpage('assignroles', get_string('assignglobalroles', 'role'), "$CFG->wwwroot/$CFG->admin/roles/assign.php?contextid=".$systemcontext->id, 'moodle/role:assign')); diff --git a/lang/en_utf8/report_unittest.php b/lang/en_utf8/report_unittest.php new file mode 100644 index 0000000000000..2227cf0d9ae65 --- /dev/null +++ b/lang/en_utf8/report_unittest.php @@ -0,0 +1,5 @@ + diff --git a/lib/accesslib.php b/lib/accesslib.php index e619edb37afb1..93fc7daf456c8 100755 --- a/lib/accesslib.php +++ b/lib/accesslib.php @@ -3064,7 +3064,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]. @@ -3774,6 +3778,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; @@ -3838,6 +3846,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'); } @@ -5246,7 +5256,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/moodlelib.php b/lib/moodlelib.php index a12b8dd62b789..1572d019857c8 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -6112,7 +6112,7 @@ function get_list_of_plugins($plugin='mod', $exclude='', $basedir='') { $dirhandle = opendir($basedir); while (false !== ($dir = readdir($dirhandle))) { $firstchar = substr($dir, 0, 1); - if ($firstchar == '.' or $dir == 'CVS' or $dir == '_vti_cnf' or $dir == $exclude) { + if ($firstchar == '.' or $dir == 'CVS' or $dir == '_vti_cnf' or $dir == 'simpletest' or $dir == $exclude) { continue; } if (filetype($basedir .'/'. $dir) != 'dir') { diff --git a/theme/standard/styles_color.css b/theme/standard/styles_color.css index edc6594a86bf0..870e3c819e4a5 100644 --- a/theme/standard/styles_color.css +++ b/theme/standard/styles_color.css @@ -199,7 +199,7 @@ table.formtable tbody th { *** Header ***/ -.breadcrumb .sep, #admin-report-simpletest-index .sep { +.breadcrumb .sep, #admin-report-unittest-index .sep { color:#aaa; } @@ -294,31 +294,31 @@ table.flexible .r1 { background-color: #fafafa; } -#admin-report-simpletest-index span.notice { +#admin-report-unittest-index span.notice { color: teal; } -#admin-report-simpletest-index b.pass { +#admin-report-unittest-index b.pass { color: green; } -#admin-report-simpletest-index b.fail, b.exception { +#admin-report-unittest-index b.fail, b.exception { color: red; } -#admin-report-simpletest-index .exception, .exception pre { +#admin-report-unittest-index .exception, .exception pre { background-color: #fdd; } -#admin-report-simpletest-index .unittestsummary { +#admin-report-unittest-index .unittestsummary { color: white; } -#admin-report-simpletest-index .unittestsummary.failed { +#admin-report-unittest-index .unittestsummary.failed { background-color: red; } -#admin-report-simpletest-index .unittestsummary.passed { +#admin-report-unittest-index .unittestsummary.passed { background-color: green; } diff --git a/theme/standard/styles_layout.css b/theme/standard/styles_layout.css index 3654ad0c30d36..c34fe79c6c1ca 100644 --- a/theme/standard/styles_layout.css +++ b/theme/standard/styles_layout.css @@ -907,11 +907,11 @@ body#admin-modules table.generaltable td.c0 text-align: center; } -#admin-report-simpletest-index .exception pre { +#admin-report-unittest-index .exception pre { padding: 8px; } -#admin-report-simpletest-index .unittestsummary { +#admin-report-unittest-index .unittestsummary { padding: 8px; margin-top: 1em; } diff --git a/version.php b/version.php index 0078e21221694..4a56c20457c4f 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 = 2007101532; // YYYYMMDD = date of the 1.9 branch (don't change) + $version = 2007101532.01; // YYYYMMDD = date of the 1.9 branch (don't change) // X = release number 1.9.[0,1,2,3...] // Y.YY = micro-increments between releases