From: Jan Schneider Date: Mon, 15 Mar 2010 22:39:59 +0000 (+0100) Subject: Allow remove all user and group permissions at once. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=00ebec56daa675c0940cd7251d89b516f45b4e8a;p=horde.git Allow remove all user and group permissions at once. --- diff --git a/framework/Perms/lib/Horde/Perms/Permission.php b/framework/Perms/lib/Horde/Perms/Permission.php index 8c94d6318..5ceaed276 100644 --- a/framework/Perms/lib/Horde/Perms/Permission.php +++ b/framework/Perms/lib/Horde/Perms/Permission.php @@ -362,24 +362,30 @@ class Horde_Perms_Permission * 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) { @@ -391,17 +397,17 @@ class Horde_Perms_Permission * 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']); @@ -416,17 +422,17 @@ class Horde_Perms_Permission * 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']); @@ -441,17 +447,17 @@ class Horde_Perms_Permission * 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']); @@ -466,26 +472,30 @@ class Horde_Perms_Permission * 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) { diff --git a/kronolith/lib/Kronolith.php b/kronolith/lib/Kronolith.php index d2b1a890e..a28fc0752 100644 --- a/kronolith/lib/Kronolith.php +++ b/kronolith/lib/Kronolith.php @@ -1617,6 +1617,7 @@ class Kronolith $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); @@ -1632,28 +1633,18 @@ class Kronolith 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); } } @@ -1665,6 +1656,7 @@ class Kronolith $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; @@ -1672,28 +1664,18 @@ class Kronolith 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); } }