MDL-62318 core_group: Updating cache when deleting group memberships
This commit is contained in:
@@ -142,6 +142,9 @@ class provider implements
|
||||
}
|
||||
|
||||
$DB->delete_records_select('groups_members', $select, $params);
|
||||
|
||||
// Purge the group and grouping cache for users.
|
||||
\cache_helper::purge_by_definition('core', 'user_group_groupings');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -182,6 +185,9 @@ class provider implements
|
||||
}
|
||||
|
||||
$DB->delete_records_select('groups_members', $select, $params);
|
||||
|
||||
// Invalidate the group and grouping cache for the user.
|
||||
\cache_helper::invalidate_by_definition('core', 'user_group_groupings', array(), array($userid));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -271,6 +271,37 @@ class core_group_privacy_provider_testcase extends provider_testcase {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for provider::delete_groups_for_all_users() to check deleting from cache.
|
||||
*/
|
||||
public function test_delete_groups_for_all_users_deletes_cache() {
|
||||
$this->resetAfterTest();
|
||||
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
|
||||
$group1 = $this->getDataGenerator()->create_group(array('courseid' => $course->id));
|
||||
$group2 = $this->getDataGenerator()->create_group(array('courseid' => $course->id));
|
||||
|
||||
$user1 = $this->getDataGenerator()->create_user();
|
||||
$user2 = $this->getDataGenerator()->create_user();
|
||||
|
||||
$this->getDataGenerator()->enrol_user($user1->id, $course->id);
|
||||
$this->getDataGenerator()->enrol_user($user2->id, $course->id);
|
||||
|
||||
$this->getDataGenerator()->create_group_member(array('userid' => $user1->id, 'groupid' => $group1->id));
|
||||
$this->getDataGenerator()->create_group_member(array('userid' => $user1->id, 'groupid' => $group2->id));
|
||||
$this->getDataGenerator()->create_group_member(array('userid' => $user2->id, 'groupid' => $group1->id));
|
||||
|
||||
$this->assertEquals([[$group1->id, $group2->id]], groups_get_user_groups($course->id, $user1->id), '', 0.0, 10, true);
|
||||
$this->assertEquals([[$group1->id]], groups_get_user_groups($course->id, $user2->id));
|
||||
|
||||
$coursecontext = context_course::instance($course->id);
|
||||
provider::delete_groups_for_all_users($coursecontext, '');
|
||||
|
||||
$this->assertEquals([[]], groups_get_user_groups($course->id, $user1->id));
|
||||
$this->assertEquals([[]], groups_get_user_groups($course->id, $user2->id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for provider::delete_groups_for_user() to delete manual group memberships.
|
||||
*/
|
||||
@@ -477,6 +508,34 @@ class core_group_privacy_provider_testcase extends provider_testcase {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for provider::delete_groups_for_user() to check deleting from cache.
|
||||
*/
|
||||
public function test_delete_groups_for_user_deletes_cache() {
|
||||
$this->resetAfterTest();
|
||||
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
|
||||
$group1 = $this->getDataGenerator()->create_group(array('courseid' => $course->id));
|
||||
$group2 = $this->getDataGenerator()->create_group(array('courseid' => $course->id));
|
||||
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
|
||||
$this->getDataGenerator()->enrol_user($user->id, $course->id);
|
||||
|
||||
$this->getDataGenerator()->create_group_member(array('userid' => $user->id, 'groupid' => $group1->id));
|
||||
$this->getDataGenerator()->create_group_member(array('userid' => $user->id, 'groupid' => $group2->id));
|
||||
|
||||
$this->assertEquals([[$group1->id, $group2->id]], groups_get_user_groups($course->id, $user->id), '', 0.0, 10, true);
|
||||
|
||||
$this->setUser($user);
|
||||
$coursecontext = context_course::instance($course->id);
|
||||
$approvedcontextlist = new \core_privacy\tests\request\approved_contextlist($user, 'core_group', [$coursecontext->id]);
|
||||
provider::delete_groups_for_user($approvedcontextlist, '');
|
||||
|
||||
$this->assertEquals([[]], groups_get_user_groups($course->id, $user->id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for provider::get_contexts_for_userid().
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user