public function execute() { global $CFG, $DB; $roleid = $this->arguments[0]; $filearg = $this->arguments[1]; if (substr($filearg, 0, 1) == '/') { // Absolute file. $filename = $filearg; } else { // Relative to current directory. $filename = $this->cwd . DIRECTORY_SEPARATOR . $filearg; } $fh = fopen($filename, 'r'); $roledefinition = fread($fh, filesize($filename)); if ($roledefinition) { $systemcontext = \context_system::instance(); $options = array('shortname' => 1, 'name' => 1, 'description' => 1, 'permissions' => 1, 'archetype' => 1, 'contextlevels' => 1, 'allowassign' => 1, 'allowoverride' => 1, 'allowswitch' => 1, 'permissions' => 1); $definitiontable = new \core_role_define_role_table_advanced($systemcontext, $roleid); // Add all permissions from definition file to $_POST, otherwise, they won't be applied. $info = \core_role_preset::parse_preset($roledefinition); $_POST = $info['permissions']; $definitiontable->read_submitted_permissions(); $definitiontable->force_preset($roledefinition, $options); $definitiontable->save_changes(); } }
public function __construct($context, $roleid) { parent::__construct($context, $roleid); $this->displaypermissions = array(CAP_ALLOW => $this->allpermissions[CAP_ALLOW]); $this->stradvmessage = get_string('useshowadvancedtochange', 'core_role'); $this->strallow = $this->strperms[$this->allpermissions[CAP_ALLOW]]; }
/** * Returns true if the row should be skipped. * * @param string $capability * @return bool */ protected function skip_row($capability) { $perm = $this->permissions[$capability->name]; if ($perm == CAP_INHERIT) { // Do not print empty rows in role overview, admins need to know quickly what is allowed and prohibited, // if they want to see the list of all capabilities they can go to edit role page. return true; } parent::skip_row($capability); }