Commit 36cf8e72 authored by Robert Lyon's avatar Robert Lyon
Browse files

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: default avatarRobert Lyon <robertl@catalyst.net.nz>
(cherry picked from commit 8b93bf61)
parent 880b170e
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -940,7 +940,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) {
+5 −1
Original line number Diff line number Diff line
@@ -773,9 +773,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");
        }
@@ -860,6 +861,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();
}

/**