From 35e4eb42c0dada2e9af87ef4eabce58e002ed3a4 Mon Sep 17 00:00:00 2001 From: Rajesh Taneja Date: Thu, 8 Aug 2013 11:42:13 +0800 Subject: [PATCH] MDL-40044 Roles: Updated role_assigned and role_unassigned event to remove add_to_log --- admin/roles/assign.php | 4 ---- lib/classes/event/role_assigned.php | 12 ++++++++++++ lib/classes/event/role_unassigned.php | 12 ++++++++++++ lib/tests/accesslib_test.php | 12 +++++++++++- 4 files changed, 35 insertions(+), 5 deletions(-) diff --git a/admin/roles/assign.php b/admin/roles/assign.php index 8346640c5c6..cce23341f3d 100644 --- a/admin/roles/assign.php +++ b/admin/roles/assign.php @@ -110,8 +110,6 @@ if ($roleid) { $potentialuserselector->invalidate_selected_users(); $currentuserselector->invalidate_selected_users(); - $rolename = $assignableroles[$roleid]; - add_to_log($course->id, 'role', 'assign', 'admin/roles/assign.php?contextid='.$context->id.'&roleid='.$roleid, $rolename, '', $USER->id); // Counts have changed, so reload. list($assignableroles, $assigncounts, $nameswithcounts) = get_assignable_roles($context, ROLENAME_BOTH, true); } @@ -130,8 +128,6 @@ if ($roleid) { $potentialuserselector->invalidate_selected_users(); $currentuserselector->invalidate_selected_users(); - $rolename = $assignableroles[$roleid]; - add_to_log($course->id, 'role', 'unassign', 'admin/roles/assign.php?contextid='.$context->id.'&roleid='.$roleid, $rolename, '', $USER->id); // Counts have changed, so reload. list($assignableroles, $assigncounts, $nameswithcounts) = get_assignable_roles($context, ROLENAME_BOTH, true); } diff --git a/lib/classes/event/role_assigned.php b/lib/classes/event/role_assigned.php index ae670b950ca..9e748393ed5 100644 --- a/lib/classes/event/role_assigned.php +++ b/lib/classes/event/role_assigned.php @@ -75,4 +75,16 @@ class role_assigned extends base { protected function get_legacy_eventdata() { return $this->get_record_snapshot('role_assignments', $this->data['other']['id']); } + + /** + * Returns array of parameters to be passed to legacy add_to_log() function. + * + * @return array + */ + protected function get_legacy_logdata() { + $roles = get_all_roles(); + $rolenames = role_fix_names($roles, $this->get_context(), ROLENAME_ORIGINAL, true); + return array($this->courseid, 'role', 'assign', 'admin/roles/assign.php?contextid='.$this->contextid.'&roleid='.$this->objectid, + $rolenames[$this->objectid], '', $this->userid); + } } diff --git a/lib/classes/event/role_unassigned.php b/lib/classes/event/role_unassigned.php index 8912dda22c9..3bb4a100e90 100644 --- a/lib/classes/event/role_unassigned.php +++ b/lib/classes/event/role_unassigned.php @@ -75,4 +75,16 @@ class role_unassigned extends base { protected function get_legacy_eventdata() { return $this->get_record_snapshot('role_assignments', $this->data['other']['id']); } + + /** + * Returns array of parameters to be passed to legacy add_to_log() function. + * + * @return array + */ + protected function get_legacy_logdata() { + $roles = get_all_roles(); + $rolenames = role_fix_names($roles, $this->get_context(), ROLENAME_ORIGINAL, true); + return array($this->courseid, 'role', 'unassign', 'admin/roles/assign.php?contextid='.$this->contextid.'&roleid='.$this->objectid, + $rolenames[$this->objectid], '', $this->userid); + } } diff --git a/lib/tests/accesslib_test.php b/lib/tests/accesslib_test.php index 6e37d2dab68..d3c3c1e98b9 100644 --- a/lib/tests/accesslib_test.php +++ b/lib/tests/accesslib_test.php @@ -508,13 +508,18 @@ class core_accesslib_testcase extends advanced_testcase { $this->assertSame('', $event->other['component']); $this->assertEquals(0, $event->other['itemid']); $this->assertSame('role_assigned', $event::get_legacy_eventname()); + $roles = get_all_roles(); + $rolenames = role_fix_names($roles, $context, ROLENAME_ORIGINAL, true); + $expectedlegacylog = array($course->id, 'role', 'assign', + 'admin/roles/assign.php?contextid='.$context->id.'&roleid='.$role->id, $rolenames[$role->id], '', $USER->id); + $this->assertEventLegacyLogData($expectedlegacylog, $event); } /** * Test role unassigning. */ public function test_role_unassign() { - global $DB; + global $DB, $USER; $this->resetAfterTest(); @@ -551,6 +556,11 @@ class core_accesslib_testcase extends advanced_testcase { $this->assertCount(3, $event->other); $this->assertSame('', $event->other['component']); $this->assertEquals(0, $event->other['itemid']); + $roles = get_all_roles(); + $rolenames = role_fix_names($roles, $context, ROLENAME_ORIGINAL, true); + $expectedlegacylog = array($course->id, 'role', 'unassign', + 'admin/roles/assign.php?contextid='.$context->id.'&roleid='.$role->id, $rolenames[$role->id], '', $USER->id); + $this->assertEventLegacyLogData($expectedlegacylog, $event); } /**