Skip to content

Commit

Permalink
Fix #40 - deleting a group referenced by a user account restriction i…
Browse files Browse the repository at this point in the history
…s now prohibited
  • Loading branch information
tbar0970 committed Sep 11, 2015
1 parent b5d16fc commit 641bc4c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
12 changes: 11 additions & 1 deletion db_objects/person_group.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,11 +288,21 @@ function getInstancesQueryComps($params, $logic, $order)

function delete()
{
parent::delete();
$SQL = 'SELECT COUNT(*) FROM account_group_restriction WHERE groupid = '.(int)$this->id;
$res = $GLOBALS['db']->queryOne($SQL);
check_db_result($res);
if ($res > 0) {
add_message("This group cannot be deleted because it is used to restrict one or more user accounts", 'error');
return FALSE;
}

$r = parent::delete();
$db =& $GLOBALS['db'];
$sql = 'DELETE FROM person_group_membership WHERE groupid = '.$db->quote($this->id);
$res = $db->query($sql);
check_db_result($res);

return $r;
}

function printFieldValue($fieldname, $value=NULL)
Expand Down
9 changes: 6 additions & 3 deletions views/view_0_edit_group.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,12 @@ function _processObjectEditing()
if ($_POST['action'] == 'delete') { // must be POSTed
$GLOBALS['user_system']->checkPerm(PERM_EDITGROUP);
$name = $this->_edited_object->toString();
$this->_edited_object->delete();
add_message('Group "'.$name.'" deleted');
redirect('groups__list_all', Array('groupid' => NULL, 'action' => NULL)); // exits
if ($this->_edited_object->delete()) {
add_message('Group "'.$name.'" deleted');
redirect('groups__list_all', Array('groupid' => NULL, 'action' => NULL)); // exits
} else {
redirect('groups', Array('groupid' => $this->_edited_object->id));
}
}
break;
}
Expand Down

0 comments on commit 641bc4c

Please sign in to comment.