* Removes a permission that a user currently has on this object.
*
* @param string $user The user to remove the permission from.
+ * Defaults to all users.
* @param integer $permission The permission (DELETE, etc.) to
- * remove.
+ * remove. Defaults to all permissions.
* @param boolean $update Whether to automatically update the
* backend.
*/
- public function removeUserPermission($user, $permission, $update = true)
+ public function removeUserPermission($user = null, $permission = null,
+ $update = true)
{
- if (empty($user) || !isset($this->data['users'][$user])) {
- return;
- }
+ if (is_null($user)) {
+ $this->data['users'] = array();
+ } else {
+ if (!isset($this->data['users'][$user])) {
+ return;
+ }
- if ($this->get('type') == 'matrix') {
- $this->data['users'][$user] &= ~$permission;
- if (empty($this->data['users'][$user])) {
+ if ($permission && $this->get('type') == 'matrix') {
+ $this->data['users'][$user] &= ~$permission;
+ if (empty($this->data['users'][$user])) {
+ unset($this->data['users'][$user]);
+ }
+ } else {
unset($this->data['users'][$user]);
}
- } else {
- unset($this->data['users'][$user]);
}
if ($update) {
* Removes a permission that guests currently have on this object.
*
* @param integer $permission The permission (DELETE, etc.) to
- * remove.
+ * remove. Defaults to all permissions.
* @param boolean $update Whether to automatically update the
* backend.
*/
- public function removeGuestPermission($permission, $update = true)
+ public function removeGuestPermission($permission = null, $update = true)
{
if (!isset($this->data['guest'])) {
return;
}
- if ($this->get('type') == 'matrix') {
+ if ($permission && $this->get('type') == 'matrix') {
$this->data['guest'] &= ~$permission;
} else {
unset($this->data['guest']);
* Removes a permission that creators currently have on this object.
*
* @param integer $permission The permission (DELETE, etc.) to
- * remove.
+ * remove. Defaults to all permissions.
* @param boolean $update Whether to automatically update the
* backend.
*/
- public function removeCreatorPermission($permission, $update = true)
+ public function removeCreatorPermission($permission = null, $update = true)
{
if (!isset($this->data['creator'])) {
return;
}
- if ($this->get('type') == 'matrix') {
+ if ($permission && $this->get('type') == 'matrix') {
$this->data['creator'] &= ~$permission;
} else {
unset($this->data['creator']);
* Removes a default permission on this object.
*
* @param integer $permission The permission (DELETE, etc.) to
- * remove.
+ * remove. Defaults to all permissions.
* @param boolean $update Whether to automatically update the
* backend.
*/
- public function removeDefaultPermission($permission, $update = true)
+ public function removeDefaultPermission($permission = null, $update = true)
{
if (!isset($this->data['default'])) {
return;
}
- if ($this->get('type') == 'matrix') {
+ if ($permission && $this->get('type') == 'matrix') {
$this->data['default'] &= ~$permission;
} else {
unset($this->data['default']);
* Removes a permission that a group currently has on this object.
*
* @param integer $groupId The id of the group to remove the
- * permission from.
+ * permission from. Defaults to all groups.
* @param integer $permission The permission (DELETE, etc.) to
- * remove.
+ * remove. Defaults to all permissions.
* @param boolean $update Whether to automatically update the
* backend.
*/
- public function removeGroupPermission($groupId, $permission,
+ public function removeGroupPermission($groupId = null, $permission = null,
$update = true)
{
- if (empty($groupId) || !isset($this->data['groups'][$groupId])) {
- return;
- }
+ if (is_null($groupId)) {
+ $this->data['groups'] = array();
+ } else {
+ if (!isset($this->data['groups'][$groupId])) {
+ return;
+ }
- if ($this->get('type') == 'matrix') {
- $this->data['groups'][$groupId] &= ~$permission;
- if (empty($this->data['groups'][$groupId])) {
+ if ($permission && $this->get('type') == 'matrix') {
+ $this->data['groups'][$groupId] &= ~$permission;
+ if (empty($this->data['groups'][$groupId])) {
+ unset($this->data['groups'][$groupId]);
+ }
+ } else {
unset($this->data['groups'][$groupId]);
}
- } else {
- unset($this->data['groups'][$groupId]);
}
if ($update) {
$u_delete = Horde_Util::getFormData('u_delete');
$u_delegate = Horde_Util::getFormData('u_delegate');
+ $perm->removeUserPermission(null, null, false);
foreach ($u_names as $key => $user_backend) {
// Apply backend hooks
$user = Horde_Auth::convertUsername($user_backend, true);
if (!empty($u_show[$key])) {
$perm->addUserPermission($user, Horde_Perms::SHOW, false);
- } else {
- $perm->removeUserPermission($user, Horde_Perms::SHOW, false);
}
if (!empty($u_read[$key])) {
$perm->addUserPermission($user, Horde_Perms::READ, false);
- } else {
- $perm->removeUserPermission($user, Horde_Perms::READ, false);
}
if (!empty($u_edit[$key])) {
$perm->addUserPermission($user, Horde_Perms::EDIT, false);
- } else {
- $perm->removeUserPermission($user, Horde_Perms::EDIT, false);
}
if (!empty($u_delete[$key])) {
$perm->addUserPermission($user, Horde_Perms::DELETE, false);
- } else {
- $perm->removeUserPermission($user, Horde_Perms::DELETE, false);
}
if (!empty($u_delegate[$key])) {
$perm->addUserPermission($user, Kronolith::PERMS_DELEGATE, false);
- } else {
- $perm->removeUserPermission($user, Kronolith::PERMS_DELEGATE, false);
}
}
$g_delete = Horde_Util::getFormData('g_delete');
$g_delegate = Horde_Util::getFormData('g_delegate');
+ $perm->removeGroupPermission(null, null, false);
foreach ($g_names as $key => $group) {
if (empty($group)) {
continue;
if (!empty($g_show[$key])) {
$perm->addGroupPermission($group, Horde_Perms::SHOW, false);
- } else {
- $perm->removeGroupPermission($group, Horde_Perms::SHOW, false);
}
if (!empty($g_read[$key])) {
$perm->addGroupPermission($group, Horde_Perms::READ, false);
- } else {
- $perm->removeGroupPermission($group, Horde_Perms::READ, false);
}
if (!empty($g_edit[$key])) {
$perm->addGroupPermission($group, Horde_Perms::EDIT, false);
- } else {
- $perm->removeGroupPermission($group, Horde_Perms::EDIT, false);
}
if (!empty($g_delete[$key])) {
$perm->addGroupPermission($group, Horde_Perms::DELETE, false);
- } else {
- $perm->removeGroupPermission($group, Horde_Perms::DELETE, false);
}
if (!empty($g_delegate[$key])) {
$perm->addGroupPermission($group, Kronolith::PERMS_DELEGATE, false);
- } else {
- $perm->removeGroupPermission($group, Kronolith::PERMS_DELEGATE, false);
}
}