MDL-40337 cleanup role override code
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Library code used by the roles administration interfaces.
|
||||
* override permissions table.
|
||||
*
|
||||
* @package core_role
|
||||
* @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
|
||||
@@ -29,7 +29,7 @@ class core_role_override_permissions_table_advanced extends core_role_capability
|
||||
protected $haslockedcapabilities = false;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* Constructor.
|
||||
*
|
||||
* This method loads loads all the information about the current state of
|
||||
* the overrides, then updates that based on any submitted data. It also
|
||||
@@ -43,9 +43,9 @@ class core_role_override_permissions_table_advanced extends core_role_capability
|
||||
public function __construct($context, $roleid, $safeoverridesonly) {
|
||||
parent::__construct($context, 'overriderolestable', $roleid);
|
||||
$this->displaypermissions = $this->allpermissions;
|
||||
$this->strnotset = get_string('notset', 'role');
|
||||
$this->strnotset = get_string('notset', 'core_role');
|
||||
|
||||
/// Determine which capabilities should be locked.
|
||||
// Determine which capabilities should be locked.
|
||||
if ($safeoverridesonly) {
|
||||
foreach ($this->capabilities as $capid => $cap) {
|
||||
if (!is_safe_capability($cap)) {
|
||||
@@ -57,10 +57,8 @@ class core_role_override_permissions_table_advanced extends core_role_capability
|
||||
}
|
||||
|
||||
protected function load_parent_permissions() {
|
||||
global $DB;
|
||||
|
||||
/// Get the capabilities from the parent context, so that can be shown in the interface.
|
||||
$parentcontext = context::instance_by_id(get_parent_contextid($this->context));
|
||||
// Get the capabilities from the parent context, so that can be shown in the interface.
|
||||
$parentcontext = context::instance_by_id($this->context->get_parent_context());
|
||||
$this->parentpermissions = role_context_capabilities($this->roleid, $parentcontext);
|
||||
}
|
||||
|
||||
@@ -74,7 +72,7 @@ class core_role_override_permissions_table_advanced extends core_role_capability
|
||||
$disabled = ' disabled="disabled"';
|
||||
}
|
||||
|
||||
/// One cell for each possible permission.
|
||||
// One cell for each possible permission.
|
||||
foreach ($this->displaypermissions as $perm => $permname) {
|
||||
$strperm = $this->strperms[$permname];
|
||||
$extraclass = '';
|
||||
|
||||
+20
-22
@@ -1,5 +1,4 @@
|
||||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
@@ -18,16 +17,15 @@
|
||||
/**
|
||||
* Lets you override role definitions in contexts.
|
||||
*
|
||||
* @package core
|
||||
* @subpackage role
|
||||
* @package core_role
|
||||
* @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
require('../../config.php');
|
||||
|
||||
$contextid = required_param('contextid', PARAM_INT); // context id
|
||||
$roleid = required_param('roleid', PARAM_INT); // requested role id
|
||||
$contextid = required_param('contextid', PARAM_INT);
|
||||
$roleid = required_param('roleid', PARAM_INT);
|
||||
|
||||
list($context, $course, $cm) = get_context_info_array($contextid);
|
||||
|
||||
@@ -47,7 +45,7 @@ if ($course) {
|
||||
}
|
||||
}
|
||||
|
||||
// security first
|
||||
// Security first.
|
||||
require_login($course, false, $cm);
|
||||
$safeoverridesonly = false;
|
||||
if (!has_capability('moodle/role:override', $context)) {
|
||||
@@ -69,15 +67,15 @@ if (optional_param('cancel', false, PARAM_BOOL)) {
|
||||
|
||||
$role = $DB->get_record('role', array('id'=>$roleid), '*', MUST_EXIST);
|
||||
|
||||
// These are needed early
|
||||
// These are needed early.
|
||||
$assignableroles = get_assignable_roles($context, ROLENAME_BOTH);
|
||||
list($overridableroles, $overridecounts, $nameswithcounts) = get_overridable_roles($context, ROLENAME_BOTH, true);
|
||||
|
||||
// Work out an appropriate page title.
|
||||
$contextname = print_context_name($context);
|
||||
$straction = get_string('overrideroles', 'role'); // Used by tabs.php
|
||||
$a = (object)array('context' => $contextname, 'role' => $overridableroles[$roleid]);
|
||||
$title = get_string('overridepermissionsforrole', 'role', $a);
|
||||
$contextname = $context->get_context_name();
|
||||
$straction = get_string('overrideroles', 'core_role'); // Used by tabs.php.
|
||||
$a = (object)array('context' => $contextname, 'core_role' => $overridableroles[$roleid]);
|
||||
$title = get_string('overridepermissionsforrole', 'core_role', $a);
|
||||
|
||||
$currenttab = 'permissions';
|
||||
|
||||
@@ -104,7 +102,7 @@ switch ($context->contextlevel) {
|
||||
}
|
||||
break;
|
||||
case CONTEXT_MODULE:
|
||||
$PAGE->set_heading(print_context_name($context, false));
|
||||
$PAGE->set_heading($context->get_context_name(false));
|
||||
$PAGE->set_cacheable(false);
|
||||
break;
|
||||
case CONTEXT_BLOCK:
|
||||
@@ -112,12 +110,12 @@ switch ($context->contextlevel) {
|
||||
break;
|
||||
}
|
||||
|
||||
// Make sure this user can override that role
|
||||
// Make sure this user can override that role.
|
||||
if (empty($overridableroles[$roleid])) {
|
||||
$a = new stdClass;
|
||||
$a->roleid = $roleid;
|
||||
$a->context = $contextname;
|
||||
print_error('cannotoverriderolehere', '', get_context_url($context), $a);
|
||||
print_error('cannotoverriderolehere', '', $context->get_url(), $a);
|
||||
}
|
||||
|
||||
// If we are actually overriding a role, create the table object, and save changes if appropriate.
|
||||
@@ -131,26 +129,26 @@ if (optional_param('savechanges', false, PARAM_BOOL) && confirm_sesskey()) {
|
||||
redirect($returnurl);
|
||||
}
|
||||
|
||||
// Finally start page output
|
||||
// Finally start page output.
|
||||
echo $OUTPUT->header();
|
||||
echo $OUTPUT->heading_with_help($title, 'overridepermissions', 'role');
|
||||
echo $OUTPUT->heading_with_help($title, 'overridepermissions', 'core_role');
|
||||
|
||||
// Show UI for overriding roles.
|
||||
if (!empty($capabilities)) {
|
||||
echo $OUTPUT->box(get_string('nocapabilitiesincontext', 'role'), 'generalbox boxaligncenter');
|
||||
echo $OUTPUT->box(get_string('nocapabilitiesincontext', 'core_role'), 'generalbox boxaligncenter');
|
||||
|
||||
} else {
|
||||
// Print the capabilities overrideable in this context
|
||||
// Print the capabilities overrideable in this context.
|
||||
echo $OUTPUT->box_start('generalbox capbox');
|
||||
echo html_writer::start_tag('form', array('id'=>'overrideform', 'action'=>$PAGE->url->out(), 'method'=>'post'));
|
||||
echo html_writer::start_tag('div');
|
||||
echo html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'sesskey', 'value'=>sesskey()));
|
||||
echo html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'roleid', 'value'=>$roleid));
|
||||
echo html_writer::tag('p', get_string('highlightedcellsshowinherit', 'role'), array('class'=>'overridenotice'));
|
||||
echo html_writer::tag('p', get_string('highlightedcellsshowinherit', 'core_role'), array('class'=>'overridenotice'));
|
||||
|
||||
$overridestable->display();
|
||||
if ($overridestable->has_locked_capabilities()) {
|
||||
echo '<p class="overridenotice">' . get_string('safeoverridenotice', 'role') . "</p>\n";
|
||||
echo '<p class="overridenotice">' . get_string('safeoverridenotice', 'core_role') . "</p>\n";
|
||||
}
|
||||
|
||||
echo html_writer::start_tag('div', array('class'=>'submit_buttons'));
|
||||
@@ -165,9 +163,9 @@ if (!empty($capabilities)) {
|
||||
// Print a form to swap roles, and a link back to the all roles list.
|
||||
echo html_writer::start_tag('div', array('class'=>'backlink'));
|
||||
$select = new single_select($PAGE->url, 'roleid', $nameswithcounts, $roleid, null);
|
||||
$select->label = get_string('overrideanotherrole', 'role');
|
||||
$select->label = get_string('overrideanotherrole', 'core_role');
|
||||
echo $OUTPUT->render($select);
|
||||
echo html_writer::tag('p', html_writer::tag('a', get_string('backtoallroles', 'role'), array('href'=>$returnurl)));
|
||||
echo html_writer::tag('p', html_writer::tag('a', get_string('backtoallroles', 'core_role'), array('href'=>$returnurl)));
|
||||
echo html_writer::end_tag('div');
|
||||
|
||||
echo $OUTPUT->footer();
|
||||
|
||||
Reference in New Issue
Block a user