Commit aeb91f9e authored by Robert Lyon's avatar Robert Lyon

Bug 1599305: Set users 'grouproles' to only contain undeleted groups

And also update the current user's group roles on group deletion

behatnotneeded

Change-Id: Id32ea6b0ba95a4057c1a84e860aa2ded3879f8b0
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
(cherry picked from commit 8b93bf61)
parent 23b0e15c
......@@ -936,7 +936,10 @@ class User {
}
public function reset_grouproles() {
$memberships = get_records_array('group_member', 'member', $this->get('id'));
$sql = "SELECT gm.* FROM {group_member} gm
JOIN {group} g ON g.id = gm.group
WHERE gm.member = ? AND g.deleted = 0";
$memberships = get_records_sql_array($sql, array($this->get('id')));
$roles = array();
if ($memberships) {
foreach ($memberships as $m) {
......
......@@ -765,9 +765,10 @@ function group_get_groups_for_editing($ids=null) {
* necessary}}
*/
function group_delete($groupid, $shortname=null, $institution=null, $notifymembers=true) {
global $USER;
if (empty($groupid) && !empty($institution) && !is_null($shortname) && strlen($shortname)) {
// External call to delete a group, check permission of $USER.
global $USER;
if (!$USER->can_edit_institution($institution)) {
throw new AccessDeniedException("group_delete: cannot delete a group in this institution");
}
......@@ -848,6 +849,9 @@ function group_delete($groupid, $shortname=null, $institution=null, $notifymembe
)
);
db_commit();
// Need to reset grouproles - normally done via group_remove_user() but we don't call
// it due to notification reasons (see above)
$USER->reset_grouproles();
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment