MDL-21710, MDL-21711 new permissions evaluation and overriding UI

This commit is contained in:
Petr Skoda
2010-03-07 09:28:54 +00:00
parent f42e7f7853
commit 01a2ce80ec
26 changed files with 1783 additions and 2093 deletions
+54 -89
View File
@@ -1,35 +1,29 @@
<?php
///////////////////////////////////////////////////////////////////////////
// //
// NOTICE OF COPYRIGHT //
// //
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
// http://moodle.org //
// //
// Copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.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 //
// //
///////////////////////////////////////////////////////////////////////////
// This file is part of Moodle - http://moodle.org/
//
// Moodle 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 3 of the License, or
// (at your option) any later version.
//
// Moodle 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.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Handles headers and tabs for the roles control at any level apart from SYSTEM level
* We assume that $currenttab, $assignableroles and $overridableroles are defined
*
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package roles
*//** */
* @package moodlecore
* @subpackage role
* @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
if (!defined('MOODLE_INTERNAL')) {
die('Direct access to this script is forbidden.'); // It must be included from a Moodle page
@@ -56,11 +50,9 @@ if ($currenttab != 'update') {
$PAGE->navbar->add($straction);
$PAGE->set_title($title);
$PAGE->set_heading($SITE->fullname);
echo $OUTPUT->header();
break;
case CONTEXT_USER:
echo $OUTPUT->header();
break;
case CONTEXT_COURSECAT:
@@ -78,14 +70,12 @@ if ($currenttab != 'update') {
$PAGE->navbar->add(get_string("roles"));
$PAGE->set_title($title);
$PAGE->set_heading("$SITE->fullname: $strcourses");
echo $OUTPUT->header();
break;
case CONTEXT_COURSE:
if ($context->instanceid != SITEID) {
$course = $DB->get_record('course', array('id'=>$context->instanceid));
require_login($course);
if (empty($title)) {
$title = get_string("editcoursesettings");
}
@@ -93,7 +83,6 @@ if ($currenttab != 'update') {
$PAGE->navbar->add(get_string('roles'), $roleslink, navigation_node::TYPE_SETTING);
$PAGE->set_title($title);
$PAGE->set_heading($course->fullname);
echo $OUTPUT->header();
}
break;
@@ -105,8 +94,6 @@ if ($currenttab != 'update') {
print_error('invalidcourse');
}
require_login($course);
$PAGE->navigation->add(get_string('roles'));
if (empty($title)) {
@@ -114,45 +101,16 @@ if ($currenttab != 'update') {
}
$PAGE->set_title($title);
$PAGE->set_cacheable(false);
echo $OUTPUT->header();
break;
case CONTEXT_BLOCK:
if ($blockinstance = $DB->get_record('block_instances', array('id' => $context->instanceid))) {
$blockname = print_context_name($context);
$parentcontext = get_context_instance_by_id($blockinstance->parentcontextid);
switch ($parentcontext->contextlevel) {
case CONTEXT_SYSTEM:
break;
case CONTEXT_COURSECAT:
$PAGE->set_category_by_id($parentcontext->instanceid);
break;
case CONTEXT_COURSE:
require_login($parentcontext->instanceid);
break;
case CONTEXT_MODULE:
$cm = get_coursemodule_from_id('', $parentcontext->instanceid);
require_login($parentcontext->instanceid, false, $cm);
break;
case CONTEXT_USER:
break;
default:
throw new invalid_state_exception('Block context ' . $blockname .
' has parent context with an improper contextlevel ' . $parentcontext->contextlevel);
}
$PAGE->navbar->add($blockname);
$PAGE->navbar->add($straction);
$PAGE->set_title("$straction: $blockname");
$PAGE->set_heading($PAGE->course->fullname);
echo $OUTPUT->header();
}
break;
@@ -167,16 +125,12 @@ if ($currenttab != 'update') {
$toprow = array();
$inactive = array();
$activetwo = array();
$secondrow = array();
$permissionsrow = array();
if ($context->contextlevel != CONTEXT_SYSTEM) { // Print tabs for anything except SYSTEM context
if (!empty($returnurl)) {
$returnurlparam = '&amp;returnurl=' . $returnurl;
} else {
$returnurlparam = '';
}
if ($context->contextlevel == CONTEXT_MODULE) { // Only show update button if module
$toprow[] = new tabobject('update', $CFG->wwwroot.'/course/mod.php?update='.
$context->instanceid.'&amp;return=true&amp;sesskey='.sesskey(), get_string('settings'));
@@ -184,29 +138,40 @@ if ($context->contextlevel != CONTEXT_SYSTEM) { // Print tabs for anything ex
if (!empty($assignableroles) || $currenttab=='assign') {
$toprow[] = new tabobject('assign',
$CFG->wwwroot.'/'.$CFG->admin.'/roles/assign.php?contextid='.$context->id.$returnurlparam,
new moodle_url('/admin/roles/assign.php', array('contextid'=>$context->id)),
get_string('localroles', 'role'), '', true);
}
if (!empty($overridableroles)) {
$toprow[] = new tabobject('override',
$CFG->wwwroot.'/'.$CFG->admin.'/roles/override.php?contextid='.$context->id.$returnurlparam,
get_string('overridepermissions', 'role'), '', true);
if (has_capability('moodle/role:review', $context) or !empty($overridableroles)) {
$permissionsrow['permissions'] = new tabobject('permissions',
new moodle_url('/admin/roles/permissions.php', array('contextid'=>$context->id)),
get_string('permissions', 'role'), '', true);
}
if (has_any_capability(array('moodle/role:assign', 'moodle/role:safeoverride',
'moodle/role:override', 'moodle/role:assign'), $context)) {
$toprow[] = new tabobject('check',
$CFG->wwwroot.'/'.$CFG->admin.'/roles/check.php?contextid='.$context->id.$returnurlparam,
$permissionsrow['check'] = new tabobject('check',
new moodle_url('/admin/roles/check.php', array('contextid'=>$context->id)),
get_string('checkpermissions', 'role'));
}
if ($permissionsrow) {
$firstpermissionrow = reset($permissionsrow);
$toprow[] = new tabobject('toppermissions', $firstpermissionrow->link, get_string('permissions', 'role'), '', true);
if (!empty($permissionsrow[$currenttab])) {
$secondrow = array_values($permissionsrow);
$inactive = array('toppermissions');
$activetwo = array('toppermissions');
}
}
if (!empty($availablefilters)) {
$toprow[] = new tabobject('filters',
$CFG->wwwroot.'/filter/manage.php?contextid=' . $context->id,
new moodle_url('/filter/manage.php', array('contextid'=>$context->id)),
get_string('filters', 'admin'));
}
}
unset($permissionsrow);
/// Here other core tabs should go (always calling tabs.php files)
/// All the logic to decide what to show must be self-contained in the tabs file
@@ -215,26 +180,26 @@ if ($context->contextlevel != CONTEXT_SYSTEM) { // Print tabs for anything ex
/// Finally, we support adding some 'on-the-fly' tabs here
/// All the logic to decide what to show must be self-cointained in the tabs file
if (!empty($CFG->extratabs)) {
if ($extratabs = explode(',', $CFG->extratabs)) {
asort($extratabs);
foreach($extratabs as $extratab) {
/// Each extra tab must be one $CFG->dirroot relative file
if (file_exists($CFG->dirroot . '/' . $extratab)) {
include_once($CFG->dirroot . '/' . $extratab);
}
if (!empty($CFG->extratabs)) {
if ($extratabs = explode(',', $CFG->extratabs)) {
asort($extratabs);
foreach($extratabs as $extratab) {
/// Each extra tab must be one $CFG->dirroot relative file
if (file_exists($CFG->dirroot . '/' . $extratab)) {
include($CFG->dirroot . '/' . $extratab);
}
}
}
}
$inactive[] = $currenttab;
$inactive[] = $currenttab;
$tabs = array($toprow);
$tabs = array($toprow);
/// If there are any secondrow defined, let's introduce it
if (isset($secondrow) && is_array($secondrow) && !empty($secondrow)) {
$tabs[] = $secondrow;
}
if (!empty($secondrow)) {
$tabs[] = $secondrow;
}
print_tabs($tabs, $currenttab, $inactive, $activetwo);
print_tabs($tabs, $currenttab, $inactive, $activetwo);