Merge branch 'MDL-66034-master' of git://github.com/lameze/moodle

This commit is contained in:
Andrew Nicols
2019-08-06 09:30:14 +08:00
21 changed files with 473 additions and 78 deletions
-19
View File
@@ -46,25 +46,6 @@ $controller = new $classformode[$mode]();
if (optional_param('submit', false, PARAM_BOOL) && data_submitted() && confirm_sesskey()) {
$controller->process_submission();
$event = null;
// Create event depending on mode.
switch ($mode) {
case 'assign':
$event = \core\event\role_allow_assign_updated::create(array('context' => $syscontext));
break;
case 'override':
$event = \core\event\role_allow_override_updated::create(array('context' => $syscontext));
break;
case 'switch':
$event = \core\event\role_allow_switch_updated::create(array('context' => $syscontext));
break;
case 'view':
$event = \core\event\role_allow_view_updated::create(array('context' => $syscontext));
break;
}
if ($event) {
$event->trigger();
}
redirect($baseurl);
}
@@ -46,4 +46,8 @@ class core_role_allow_assign_page extends core_role_allow_role_page {
public function get_intro_text() {
return get_string('configallowassign', 'core_admin');
}
protected function get_eventclass() {
return \core\event\role_allow_assign_updated::class;
}
}
@@ -46,4 +46,8 @@ class core_role_allow_override_page extends core_role_allow_role_page {
public function get_intro_text() {
return get_string('configallowoverride2', 'core_admin');
}
protected function get_eventclass() {
return \core\event\role_allow_override_updated::class;
}
}
+30
View File
@@ -59,12 +59,36 @@ abstract class core_role_allow_role_page {
*/
public function process_submission() {
global $DB;
$context = context_system::instance();
$this->load_current_settings();
// Delete all records, then add back the ones that should be allowed.
$DB->delete_records($this->tablename);
foreach ($this->roles as $fromroleid => $notused) {
foreach ($this->roles as $targetroleid => $alsonotused) {
$isallowed = $this->allowed[$fromroleid][$targetroleid];
if (optional_param('s_' . $fromroleid . '_' . $targetroleid, false, PARAM_BOOL)) {
$this->set_allow($fromroleid, $targetroleid);
// Only trigger events if this role allow relationship did not exist and the checkbox element
// has been submitted.
if (!$isallowed) {
$eventclass = $this->get_eventclass();
$eventclass::create([
'context' => $context,
'objectid' => $fromroleid,
'other' => ['targetroleid' => $targetroleid, 'allow' => true]
])->trigger();
}
} else if ($isallowed) {
// When the user has deselect an existing role allow checkbox but it is in the list of roles
// allowances.
$eventclass = $this->get_eventclass();
$eventclass::create([
'context' => $context,
'objectid' => $fromroleid,
'other' => ['targetroleid' => $targetroleid, 'allow' => false]
])->trigger();
}
}
}
@@ -161,4 +185,10 @@ abstract class core_role_allow_role_page {
* @return string
*/
public abstract function get_intro_text();
/**
* Returns the allow class respective event class name.
* @return string
*/
protected abstract function get_eventclass();
}
@@ -58,4 +58,8 @@ class core_role_allow_switch_page extends core_role_allow_role_page {
public function get_intro_text() {
return get_string('configallowswitch', 'core_admin');
}
protected function get_eventclass() {
return \core\event\role_allow_switch_updated::class;
}
}
+4
View File
@@ -74,4 +74,8 @@ class core_role_allow_view_page extends core_role_allow_role_page {
public function get_intro_text() {
return get_string('configallowview', 'core_admin');
}
protected function get_eventclass() {
return \core\event\role_allow_view_updated::class;
}
}
@@ -434,7 +434,7 @@ class core_role_define_role_table_advanced extends core_role_capability_table_wi
}
public function save_changes() {
global $DB;
global $DB, $USER;
if (!$this->roleid) {
// Creating role.
@@ -444,6 +444,20 @@ class core_role_define_role_table_advanced extends core_role_capability_table_wi
// Updating role.
$DB->update_record('role', $this->role);
// Trigger role updated event.
\core\event\role_updated::create([
'userid' => $USER->id,
'objectid' => $this->role->id,
'context' => $this->context,
'other' => [
'name' => $this->role->name,
'shortname' => $this->role->shortname,
'description' => $this->role->description,
'archetype' => $this->role->archetype,
'contextlevels' => $this->contextlevels
]
])->trigger();
// This will ensure the course contacts cache is purged so name changes get updated in
// the UI. It would be better to do this only when we know that fields affected are
// updated. But thats getting into the weeds of the coursecat cache and role edits
@@ -473,10 +487,17 @@ class core_role_define_role_table_advanced extends core_role_capability_table_wi
$addfunction = "core_role_set_{$type}_allowed";
$deltable = 'role_allow_'.$type;
$field = 'allow'.$type;
$eventclass = "\\core\\event\\role_allow_" . $type . "_updated";
$context = context_system::instance();
foreach ($current as $roleid) {
if (!in_array($roleid, $wanted)) {
$DB->delete_records($deltable, array('roleid'=>$this->roleid, $field=>$roleid));
$eventclass::create([
'context' => $context,
'objectid' => $this->roleid,
'other' => ['targetroleid' => $roleid, 'allow' => false]
])->trigger();
continue;
}
$key = array_search($roleid, $wanted);
@@ -488,6 +509,14 @@ class core_role_define_role_table_advanced extends core_role_capability_table_wi
$roleid = $this->roleid;
}
$addfunction($this->roleid, $roleid);
if (in_array($roleid, $wanted)) {
$eventclass::create([
'context' => $context,
'objectid' => $this->roleid,
'other' => ['targetroleid' => $roleid, 'allow' => true]
])->trigger();
}
}
}
-13
View File
@@ -200,19 +200,6 @@ if (optional_param('cancel', false, PARAM_BOOL)) {
if (optional_param('savechanges', false, PARAM_BOOL) && confirm_sesskey() && $definitiontable->is_submission_valid()) {
$definitiontable->save_changes();
$tableroleid = $definitiontable->get_role_id();
// Trigger event.
$event = \core\event\role_capabilities_updated::create(
array(
'context' => $systemcontext,
'objectid' => $tableroleid
)
);
$event->set_legacy_logdata(array(SITEID, 'role', $action, 'admin/roles/define.php?action=view&roleid=' . $tableroleid,
$definitiontable->get_role_name(), '', $USER->id));
if (!empty($role)) {
$event->add_record_snapshot('role', $role);
}
$event->trigger();
if ($action === 'add') {
redirect(new moodle_url('/admin/roles/define.php', array('action'=>'view', 'roleid'=>$definitiontable->get_role_id())));
-16
View File
@@ -134,22 +134,6 @@ $overridestable->read_submitted_permissions();
if (optional_param('savechanges', false, PARAM_BOOL) && confirm_sesskey()) {
$overridestable->save_changes();
$rolename = $overridableroles[$roleid];
// Trigger event.
$event = \core\event\role_capabilities_updated::create(
array(
'context' => $context,
'objectid' => $roleid,
)
);
$event->set_legacy_logdata(
array(
$course->id, 'role', 'override', 'admin/roles/override.php?contextid=' . $context->id . '&roleid=' . $roleid,
$rolename, '', $USER->id
)
);
$event->add_record_snapshot('role', $role);
$event->trigger();
redirect($returnurl);
}
+1
View File
@@ -160,3 +160,4 @@ nobackpackcollections,core_badges
error:nogroups,core_badges
purgedefinitionsuccess,core_cache
purgestoresuccess,core_cache
eventrolecapabilitiesupdated,core_role
+6 -1
View File
@@ -225,14 +225,16 @@ $string['errorbadroleshortname'] = 'Incorrect role short name';
$string['errorexistsrolename'] = 'Role name already exists';
$string['errorexistsroleshortname'] = 'Role name already exists';
$string['errorroleshortnametoolong'] = 'The short name must not exceed 100 characters';
$string['eventcapabilityassigned'] = 'Capability assigned';
$string['eventcapabilityunassigned'] = 'Capability unassigned';
$string['eventroleallowassignupdated'] = 'Allow role assignment';
$string['eventroleallowoverrideupdated'] = 'Allow role override';
$string['eventroleallowswitchupdated'] = 'Allow role switch';
$string['eventroleallowviewupdated'] = 'Allow role view';
$string['eventroleassigned'] = 'Role assigned';
$string['eventrolecapabilitiesupdated'] = 'Role capabilities updated';
$string['eventroledeleted'] = 'Role deleted';
$string['eventroleunassigned'] = 'Role unassigned';
$string['eventroleupdated'] = 'Role updated';
$string['existingadmins'] = 'Current site administrators';
$string['existingusers'] = '{$a} existing users';
$string['explanation'] = 'Explanation';
@@ -495,3 +497,6 @@ $string['privacy:metadata:role_capabilities:tableexplanation'] = 'The capabiliti
$string['privacy:metadata:role_capabilities:timemodified'] = 'The date when the capability was created or modified.';
$string['privacy:metadata:role_cohortroles'] = 'Roles to cohort';
$string['course:togglecompletion'] = 'Manually mark activities as complete';
// Deprecated since Moodle 3.8.
$string['eventrolecapabilitiesupdated'] = 'Role capabilities updated';
+23 -1
View File
@@ -1379,6 +1379,18 @@ function assign_capability($capability, $permission, $roleid, $contextid, $overw
}
}
// Trigger capability_assigned event.
\core\event\capability_assigned::create([
'userid' => $cap->modifierid,
'context' => $context,
'objectid' => $roleid,
'other' => [
'capability' => $capability,
'oldpermission' => $existing->permission ?? CAP_INHERIT,
'permission' => $permission
]
])->trigger();
// Reset any cache of this role, including MUC.
accesslib_clear_role_cache($roleid);
@@ -1394,7 +1406,7 @@ function assign_capability($capability, $permission, $roleid, $contextid, $overw
* @return boolean true or exception
*/
function unassign_capability($capability, $roleid, $contextid = null) {
global $DB;
global $DB, $USER;
// Capability must exist.
if (!$capinfo = get_capability_info($capability)) {
@@ -1413,6 +1425,16 @@ function unassign_capability($capability, $roleid, $contextid = null) {
$DB->delete_records('role_capabilities', array('capability'=>$capability, 'roleid'=>$roleid));
}
// Trigger capability_assigned event.
\core\event\capability_unassigned::create([
'userid' => $USER->id,
'context' => $context ?? context_system::instance(),
'objectid' => $roleid,
'other' => [
'capability' => $capability,
]
])->trigger();
// Reset any cache of this role, including MUC.
accesslib_clear_role_cache($roleid);
+99
View File
@@ -0,0 +1,99 @@
<?php
// 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/>.
/**
* Capability assigned event.
*
* @package core
* @since Moodle 3.8
* @copyright 2019 Simey Lameze <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core\event;
defined('MOODLE_INTERNAL') || die();
/**
* Capability assigned event class.
*
* @package core
* @since Moodle 3.8
* @copyright 2019 Simey Lameze <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class capability_assigned extends base {
/**
* Initialise event parameters.
*/
protected function init() {
$this->data['objecttable'] = 'role_capabilities';
$this->data['crud'] = 'u';
$this->data['edulevel'] = self::LEVEL_OTHER;
}
/**
* Returns localised event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventcapabilityassigned', 'role');
}
/**
* Returns non-localised event description with id's for admin use only.
*
* @return string
*/
public function get_description() {
$strpermissions = [
CAP_INHERIT => get_string('notset', 'role'),
CAP_ALLOW => get_string('allow', 'role'),
CAP_PREVENT => get_string('prevent', 'role'),
CAP_PROHIBIT => get_string('prohibit', 'role')
];
$capability = $this->other['capability'];
$oldpermission = $this->other['oldpermission'];
$permission = $this->other['permission'];
if ($oldpermission == CAP_INHERIT && $permission == CAP_ALLOW) {
$description = "The user id '$this->userid' assigned the '$capability' capability for " .
"role '$this->objectid' with '$strpermissions[$permission]' permission";
} else {
$description = "The user id '$this->userid' changed the '$capability' capability permission for " .
"role '$this->objectid' from '$strpermissions[$oldpermission]' to '$strpermissions[$permission]'";
}
return $description;
}
/**
* Returns relevant URL.
*
* @return \moodle_url
*/
public function get_url() {
if ($this->contextlevel == CONTEXT_SYSTEM) {
return new \moodle_url('/admin/roles/define.php', ['action' => 'edit', 'roleid' => $this->objectid]);
} else {
return new \moodle_url('/admin/roles/override.php', ['contextid' => $this->contextid,
'roleid' => $this->objectid]);
}
}
}
@@ -0,0 +1,81 @@
<?php
// 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/>.
/**
* Capability unassigned event.
*
* @package core
* @since Moodle 3.8
* @copyright 2019 Simey Lameze <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core\event;
defined('MOODLE_INTERNAL') || die();
/**
* Capability unassigned event class.
*
* @package core
* @since Moodle 3.8
* @copyright 2019 Simey Lameze <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class capability_unassigned extends base {
/**
* Initialise event parameters.
*/
protected function init() {
$this->data['objecttable'] = 'role_capabilities';
$this->data['crud'] = 'u';
$this->data['edulevel'] = self::LEVEL_OTHER;
}
/**
* Returns localised event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventcapabilityunassigned', 'role');
}
/**
* Returns non-localised event description with id's for admin use only.
*
* @return string
*/
public function get_description() {
$capability = $this->other['capability'];
return "The user id id '$this->userid' has unassigned the '$capability' capability for role '$this->objectid'";
}
/**
* Returns relevant URL.
*
* @return \moodle_url
*/
public function get_url() {
if ($this->contextlevel == CONTEXT_SYSTEM) {
return new \moodle_url('/admin/roles/define.php', ['action' => 'view', 'roleid' => $this->objectid]);
} else {
return new \moodle_url('/admin/roles/override.php', ['contextid' => $this->contextid,
'roleid' => $this->objectid]);
}
}
}
@@ -42,6 +42,7 @@ class role_allow_assign_updated extends base {
protected function init() {
$this->data['crud'] = 'u';
$this->data['edulevel'] = self::LEVEL_OTHER;
$this->data['objecttable'] = 'role_allow_assign';
}
/**
@@ -59,7 +60,9 @@ class role_allow_assign_updated extends base {
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' updated Allow role assignments.";
$action = ($this->other['allow']) ? 'allow' : 'stop allowing';
return "The user with id '$this->userid' modified the role with id '" . $this->other['targetroleid']
. "' to $action users with that role from assigning the role with id '" . $this->objectid . "' to users";
}
/**
@@ -42,6 +42,7 @@ class role_allow_override_updated extends base {
protected function init() {
$this->data['crud'] = 'u';
$this->data['edulevel'] = self::LEVEL_OTHER;
$this->data['objecttable'] = 'role_allow_override';
}
/**
@@ -59,7 +60,9 @@ class role_allow_override_updated extends base {
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' updated Allow role overrides.";
$action = ($this->other['allow']) ? 'allow' : 'stop allowing';
return "The user with id '$this->userid' modified the role with id '" . $this->other['targetroleid']
. "' to $action users with that role from overriding the role with id '" . $this->objectid . "' to users";
}
/**
@@ -42,6 +42,7 @@ class role_allow_switch_updated extends base {
protected function init() {
$this->data['crud'] = 'u';
$this->data['edulevel'] = self::LEVEL_OTHER;
$this->data['objecttable'] = 'role_allow_switch';
}
/**
@@ -59,7 +60,9 @@ class role_allow_switch_updated extends base {
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' updated Allow role switches.";
$action = ($this->other['allow']) ? 'allow' : 'stop allowing';
return "The user with id '$this->userid' modified the role with id '" . $this->other['targetroleid']
. "' to $action users with that role from switching the role with id '" . $this->objectid . "' to users";
}
/**
@@ -42,6 +42,7 @@ class role_allow_view_updated extends base {
protected function init() {
$this->data['crud'] = 'u';
$this->data['edulevel'] = self::LEVEL_OTHER;
$this->data['objecttable'] = 'role_allow_view';
}
/**
@@ -59,7 +60,9 @@ class role_allow_view_updated extends base {
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' updated Allow role views.";
$action = ($this->other['allow']) ? 'allow' : 'stop allowing';
return "The user with id '$this->userid' modified the role with id '" . $this->other['targetroleid']
. "' to $action users with that role from viewing the role with id '" . $this->objectid . "' to users";
}
/**
@@ -27,6 +27,9 @@ namespace core\event;
defined('MOODLE_INTERNAL') || die();
debugging('core\\event\\role_capabilities_updated has been deprecated. Please use
core\\event\\capability_assigned instead', DEBUG_DEVELOPER);
/**
* Role updated event class.
*
@@ -102,4 +105,14 @@ class role_capabilities_updated extends base {
public static function get_objectid_mapping() {
return array('db' => 'role', 'restore' => 'role');
}
/**
* This event has been deprecated.
*
* @return boolean
*/
public static function is_deprecated() {
return true;
}
}
+97
View File
@@ -0,0 +1,97 @@
<?php
// 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/>.
/**
* Role updated event.
*
* @package core
* @copyright 2019 Simey Lameze <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core\event;
defined('MOODLE_INTERNAL') || die();
/**
* Role updated event class.
*
* @package core
* @since Moodle 3.8
* @copyright 2019 Simey Lameze <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class role_updated extends base {
/**
* Initialise event parameters.
*/
protected function init() {
$this->data['objecttable'] = 'role';
$this->data['crud'] = 'u';
$this->data['edulevel'] = self::LEVEL_OTHER;
}
/**
* Returns localised event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventroleupdated', 'role');
}
/**
* Returns non-localised event description with id's for admin use only.
*
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' updated the role with id '$this->objectid'.";
}
/**
* Returns relevant URL.
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/admin/roles/define.php', ['action' => 'edit', 'roleid' => $this->objectid]);
}
/**
* Returns array of parameters to be passed to legacy add_to_log() function.
*
* @return array
*/
protected function get_legacy_logdata() {
return [SITEID, 'role', 'update', 'admin/roles/manage.php?action=edit&roleid=' . $this->objectid,
$this->other['shortname'], ''];
}
/**
* Custom validation.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
parent::validate_data();
if (!isset($this->other['shortname'])) {
throw new \coding_exception('The \'shortname\' value must be set in other.');
}
}
}
+61 -23
View File
@@ -368,7 +368,7 @@ class core_accesslib_testcase extends advanced_testcase {
* Test adding of capabilities to roles.
*/
public function test_assign_capability() {
global $DB;
global $DB, $USER;
$this->resetAfterTest();
@@ -408,34 +408,40 @@ class core_accesslib_testcase extends advanced_testcase {
$permission = $DB->get_record('role_capabilities', array('contextid'=>$frontcontext->id, 'roleid'=>$student->id, 'capability'=>'moodle/backup:backupcourse'));
$this->assertEmpty($permission);
// Test event trigger.
$rolecapabilityevent = \core\event\role_capabilities_updated::create(array('context' => $syscontext,
'objectid' => $student->id,
'other' => array('name' => $student->shortname)
));
$expectedlegacylog = array(SITEID, 'role', 'view', 'admin/roles/define.php?action=view&roleid=' . $student->id,
$student->shortname, '', $user->id);
$rolecapabilityevent->set_legacy_logdata($expectedlegacylog);
$rolecapabilityevent->add_record_snapshot('role', $student);
// Test event triggered.
$sink = $this->redirectEvents();
$rolecapabilityevent->trigger();
$capability = 'moodle/backup:backupcourse';
assign_capability($capability, CAP_ALLOW, $student->id, $syscontext);
$events = $sink->get_events();
$sink->close();
$event = array_pop($events);
$this->assertCount(1, $events);
$event = $events[0];
$this->assertInstanceOf('\core\event\capability_assigned', $event);
$this->assertSame('role_capabilities', $event->objecttable);
$this->assertEquals($student->id, $event->objectid);
$this->assertEquals($syscontext->id, $event->contextid);
$other = ['capability' => $capability, 'oldpermission' => CAP_INHERIT, 'permission' => CAP_ALLOW];
$this->assertEquals($other, $event->other);
$description = "The user id '$USER->id' assigned the '$capability' capability for " .
"role '$student->id' with 'Allow' permission";
$this->assertEquals($description, $event->get_description());
$this->assertInstanceOf('\core\event\role_capabilities_updated', $event);
$expectedurl = new moodle_url('/admin/roles/define.php', array('action' => 'view', 'roleid' => $student->id));
$this->assertEquals($expectedurl, $event->get_url());
$this->assertEventLegacyLogData($expectedlegacylog, $event);
$this->assertEventContextNotUsed($event);
// Test if the event has different description when updating the capability permission.
$sink = $this->redirectEvents();
assign_capability($capability, CAP_PROHIBIT, $student->id, $syscontext, true);
$events = $sink->get_events();
$sink->close();
$event = $events[0];
$description = "The user id '$USER->id' changed the '$capability' capability permission for " .
"role '$student->id' from 'Allow' to 'Prohibit'";
$this->assertEquals($description, $event->get_description());
}
/**
* Test removing of capabilities from roles.
*/
public function test_unassign_capability() {
global $DB;
global $DB, $USER;
$this->resetAfterTest();
@@ -463,6 +469,22 @@ class core_accesslib_testcase extends advanced_testcase {
$this->assertTrue($result);
$this->assertFalse($DB->record_exists('role_capabilities', array('contextid'=>$syscontext->id, 'roleid'=>$manager->id, 'capability'=>'moodle/backup:backupcourse')));
$this->assertFalse($DB->record_exists('role_capabilities', array('contextid'=>$frontcontext->id, 'roleid'=>$manager->id, 'capability'=>'moodle/backup:backupcourse')));
// Test event triggered.
$sink = $this->redirectEvents();
$capability = 'moodle/backup:backupcourse';
unassign_capability($capability, CAP_ALLOW, $manager->id);
$events = $sink->get_events();
$sink->close();
$this->assertCount(1, $events);
$event = $events[0];
$this->assertInstanceOf('\core\event\capability_unassigned', $event);
$this->assertSame('role_capabilities', $event->objecttable);
$this->assertEquals($manager->id, $event->objectid);
$this->assertEquals($syscontext->id, $event->contextid);
$this->assertEquals($capability, $event->other['capability']);
$description = "The user id id '$USER->id' has unassigned the '$capability' capability for role '$manager->id'";
$this->assertEquals($description, $event->get_description());
}
/**
@@ -977,7 +999,11 @@ class core_accesslib_testcase extends advanced_testcase {
$this->assertTrue($DB->record_exists('role_allow_assign', array('roleid'=>$otherid, 'allowassign'=>$student->id)));
// Test event trigger.
$allowroleassignevent = \core\event\role_allow_assign_updated::create(array('context' => context_system::instance()));
$allowroleassignevent = \core\event\role_allow_assign_updated::create([
'context' => context_system::instance(),
'objectid' => $otherid,
'other' => ['targetroleid' => $student->id]
]);
$sink = $this->redirectEvents();
$allowroleassignevent->trigger();
$events = $sink->get_events();
@@ -1006,7 +1032,11 @@ class core_accesslib_testcase extends advanced_testcase {
$this->assertTrue($DB->record_exists('role_allow_override', array('roleid'=>$otherid, 'allowoverride'=>$student->id)));
// Test event trigger.
$allowroleassignevent = \core\event\role_allow_override_updated::create(array('context' => context_system::instance()));
$allowroleassignevent = \core\event\role_allow_override_updated::create([
'context' => context_system::instance(),
'objectid' => $otherid,
'other' => ['targetroleid' => $student->id]
]);
$sink = $this->redirectEvents();
$allowroleassignevent->trigger();
$events = $sink->get_events();
@@ -1035,7 +1065,11 @@ class core_accesslib_testcase extends advanced_testcase {
$this->assertTrue($DB->record_exists('role_allow_switch', array('roleid'=>$otherid, 'allowswitch'=>$student->id)));
// Test event trigger.
$allowroleassignevent = \core\event\role_allow_switch_updated::create(array('context' => context_system::instance()));
$allowroleassignevent = \core\event\role_allow_switch_updated::create([
'context' => context_system::instance(),
'objectid' => $otherid,
'other' => ['targetroleid' => $student->id]
]);
$sink = $this->redirectEvents();
$allowroleassignevent->trigger();
$events = $sink->get_events();
@@ -1064,7 +1098,11 @@ class core_accesslib_testcase extends advanced_testcase {
$this->assertTrue($DB->record_exists('role_allow_view', array('roleid' => $otherid, 'allowview' => $student->id)));
// Test event trigger.
$allowroleassignevent = \core\event\role_allow_view_updated::create(array('context' => context_system::instance()));
$allowroleassignevent = \core\event\role_allow_view_updated::create([
'context' => context_system::instance(),
'objectid' => $otherid,
'other' => ['targetroleid' => $student->id]
]);
$sink = $this->redirectEvents();
$allowroleassignevent->trigger();
$events = $sink->get_events();