Skip to content

Commit

Permalink
MDL-17372 admin reports: Added full plugin support for admin reports;…
Browse files Browse the repository at this point in the history
… added specail capability for unittest execution, minor refactoring - backported from HEAD
  • Loading branch information
skodak committed Nov 26, 2008
1 parent 2910d40 commit 2d89f2d
Show file tree
Hide file tree
Showing 25 changed files with 160 additions and 67 deletions.
7 changes: 2 additions & 5 deletions admin/report/backups/index.php
Expand Up @@ -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)) {
Expand Down
3 changes: 3 additions & 0 deletions admin/report/backups/settings.php
@@ -0,0 +1,3 @@
<?php // $Id$
$ADMIN->add('reports', new admin_externalpage('reportbackups', get_string('backups', 'admin'), "$CFG->wwwroot/$CFG->admin/report/backups/index.php",'moodle/site:backup'));
?>
7 changes: 2 additions & 5 deletions admin/report/courseoverview/index.php
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions admin/report/courseoverview/settings.php
@@ -0,0 +1,3 @@
<?php // $Id$
$ADMIN->add('reports', new admin_externalpage('reportcourseoverview', get_string('courseoverview', 'admin'), "$CFG->wwwroot/$CFG->admin/report/courseoverview/index.php",'moodle/site:viewreports'));
?>
1 change: 0 additions & 1 deletion admin/report/log/index.php
Expand Up @@ -6,7 +6,6 @@
require_once($CFG->libdir.'/adminlib.php');

admin_externalpage_setup('reportlog');

admin_externalpage_print_header();


Expand Down
3 changes: 3 additions & 0 deletions admin/report/log/settings.php
@@ -0,0 +1,3 @@
<?php // $Id$
$ADMIN->add('reports', new admin_externalpage('reportlog', get_string('log', 'admin'), "$CFG->wwwroot/$CFG->admin/report/log/index.php",'moodle/site:viewreports'));
?>
2 changes: 1 addition & 1 deletion admin/report/question/index.php
Expand Up @@ -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 = '';
Expand Down
3 changes: 3 additions & 0 deletions admin/report/question/settings.php
@@ -0,0 +1,3 @@
<?php // $Id$
$ADMIN->add('reports', new admin_externalpage('reportquestion', get_string('question', 'admin'), "$CFG->wwwroot/$CFG->admin/report/question/index.php", 'moodle/site:config'));
?>
12 changes: 7 additions & 5 deletions admin/report/stats/index.php
Expand Up @@ -6,18 +6,20 @@

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);
$mode = optional_param('mode', STATS_MODE_GENERAL, PARAM_INT);
$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;
Expand Down
3 changes: 3 additions & 0 deletions admin/report/stats/settings.php
@@ -0,0 +1,3 @@
<?php // $Id$
$ADMIN->add('reports', new admin_externalpage('reportstats', get_string('stats', 'admin'), "$CFG->wwwroot/$CFG->admin/report/stats/index.php",'moodle/site:viewreports'));
?>
40 changes: 40 additions & 0 deletions admin/report/unittest/db/access.php
@@ -0,0 +1,40 @@
<?php // $Id$

///////////////////////////////////////////////////////////////////////////
// //
// NOTICE OF COPYRIGHT //
// //
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
// http://moodle.com //
// //
// Copyright (C) 1999 onwards Martin Dougiamas http://moodle.com //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation; either version 2 of the License, or //
// (at your option) any later version. //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License for more details: //
// //
// http://www.gnu.org/copyleft/gpl.html //
// //
///////////////////////////////////////////////////////////////////////////

$report_unittest_capabilities = array(

'report/unittest:view' => array(
'riskbitmask' => RISK_DATALOSS,
'captype' => 'read',
'contextlevel' => CONTEXT_SYSTEM,
'legacy' => array(
'admin' => CAP_ALLOW
),

'clonepermissionsfrom' => 'moodle/site:config',
)
);

?>
File renamed without changes.
File renamed without changes.
Expand Up @@ -16,25 +16,23 @@
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);
$showsearch = optional_param('showsearch', false, PARAM_BOOL);
$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);
Expand Down
3 changes: 3 additions & 0 deletions admin/report/unittest/settings.php
@@ -0,0 +1,3 @@
<?php //$Id$
$ADMIN->add('reports', new admin_externalpage('reportunittest', get_string('simpletest', 'admin'), "$CFG->wwwroot/$CFG->admin/report/unittest/index.php", 'report/unittest:view'));
?>
29 changes: 29 additions & 0 deletions admin/report/unittest/version.php
@@ -0,0 +1,29 @@
<?PHP // $Id$

///////////////////////////////////////////////////////////////////////////
// //
// NOTICE OF COPYRIGHT //
// //
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
// http://moodle.com //
// //
// Copyright (C) 1999 onwards Martin Dougiamas http://moodle.com //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation; either version 2 of the License, or //
// (at your option) any later version. //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License for more details: //
// //
// http://www.gnu.org/copyleft/gpl.html //
// //
///////////////////////////////////////////////////////////////////////////

$plugin->version = 2007101500;
$plugin->requires = 2007101532;

?>
18 changes: 18 additions & 0 deletions admin/settings/report.php
@@ -0,0 +1,18 @@
<?php //$Id$

foreach (get_list_of_plugins($CFG->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'));
}

?>
25 changes: 3 additions & 22 deletions admin/settings/top.php
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions admin/settings/users.php
Expand Up @@ -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'), ''));
Expand Down Expand Up @@ -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'));
Expand All @@ -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'));

Expand Down
5 changes: 5 additions & 0 deletions lang/en_utf8/report_unittest.php
@@ -0,0 +1,5 @@
<?PHP // $Id$

$string['unittest:view'] = 'Execute unit tests';

?>
17 changes: 15 additions & 2 deletions lib/accesslib.php
Expand Up @@ -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].
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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');
}
Expand Down Expand Up @@ -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') &&
Expand Down
2 changes: 1 addition & 1 deletion lib/moodlelib.php
Expand Up @@ -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') {
Expand Down

0 comments on commit 2d89f2d

Please sign in to comment.