Skip to content

Commit

Permalink
MDL-37728 show role risks
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed Jan 27, 2013
1 parent c7e2e4d commit ba4b17d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
37 changes: 37 additions & 0 deletions admin/roles/lib.php
Expand Up @@ -767,6 +767,10 @@ protected function get_allow_role_control($type) {
}
}

protected function get_role_risks_info() {
return '';
}

protected function print_field($name, $caption, $field) {
global $OUTPUT;
// Attempt to generate HTML like formslib.
Expand Down Expand Up @@ -813,6 +817,9 @@ public function display() {
$this->print_field('', get_string('allowassign', 'role'), $this->get_allow_role_control('assign'));
$this->print_field('', get_string('allowoverride', 'role'), $this->get_allow_role_control('override'));
$this->print_field('', get_string('allowswitch', 'role'), $this->get_allow_role_control('switch'));
if ($risks = $this->get_role_risks_info()) {
$this->print_field('', get_string('rolerisks', 'role'), $risks);
}
echo "</div>";

$this->print_show_hide_advanced_button();
Expand Down Expand Up @@ -914,6 +921,36 @@ protected function print_show_hide_advanced_button() {
// Do nothing.
}

protected function get_role_risks_info() {
global $OUTPUT;

if (empty($this->roleid)) {
return '';
}

$risks = array();
$allrisks = get_all_risks();
foreach ($this->capabilities as $capability) {
$perm = $this->permissions[$capability->name];
if ($perm != CAP_ALLOW) {
continue;
}
foreach ($allrisks as $type=>$risk) {
if ($risk & (int)$capability->riskbitmask) {
$risks[$type] = $risk;
}
}
}

$risksurl = new moodle_url(get_docs_url(s(get_string('risks', 'role'))));
foreach ($risks as $type=>$risk) {
$pixicon = new pix_icon('/i/' . str_replace('risk', 'risk_', $type), get_string($type . 'short', 'admin'));
$risks[$type] = $OUTPUT->action_icon($risksurl, $pixicon, new popup_action('click', $risksurl));
}

return implode(' ', $risks);
}

protected function skip_row($capability) {
$perm = $this->permissions[$capability->name];
if ($perm == CAP_INHERIT) {
Expand Down
1 change: 1 addition & 0 deletions lang/en/role.php
Expand Up @@ -313,6 +313,7 @@
$string['role:review'] = 'Review permissions for others';
$string['roleprohibitheader'] = 'Prohibit role';
$string['roleprohibitinfo'] = 'Select a role to be added to the list of prohibited roles in context {$a->context}, capability {$a->cap}:';
$string['rolerisks'] = 'Role risks';
$string['roles'] = 'Roles';
$string['roles_help'] = 'A role is a collection of permissions defined for the whole system that you can assign to specific users in specific contexts.';
$string['roles_link'] = 'roles';
Expand Down

0 comments on commit ba4b17d

Please sign in to comment.