Commit da354b62 authored by Robert Lyon's avatar Robert Lyon Committed by Gerrit Code Review
Browse files

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

parents 85432b09 8b93bf61
......@@ -952,7 +952,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) {
......
......@@ -764,9 +764,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");
}
......@@ -851,6 +852,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();
}
/**
......
Supports Markdown
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