From 7d8a09b91707ca667a32023ffa9a82655801f8e7 Mon Sep 17 00:00:00 2001 From: Gunnar Wrobel Date: Wed, 8 Apr 2009 18:50:52 +0200 Subject: [PATCH] Fix the kolabGroupOfNames hierarchy by adding a class for groupofnames. Support it in the server. --- .../Kolab_Server/lib/Horde/Kolab/Server/Kolab.php | 1 + .../lib/Horde/Kolab/Server/Object/Groupofnames.php | 232 +++++++++++++++++++++ .../Kolab/Server/Object/Kolabgroupofnames.php | 217 +++---------------- framework/Kolab_Server/package.xml | 2 + 4 files changed, 268 insertions(+), 184 deletions(-) create mode 100644 framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Groupofnames.php diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Kolab.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Kolab.php index b10091981..c14befda1 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Kolab.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Kolab.php @@ -37,6 +37,7 @@ class Horde_Kolab_Server_Kolab extends Horde_Kolab_Server_Ldap { $objects = array( 'Horde_Kolab_Server_Object', + 'Horde_Kolab_Server_Object_Groupofnames', 'Horde_Kolab_Server_Object_Kolabinetorgperson', 'Horde_Kolab_Server_Object_Kolabgroupofnames', ); diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Groupofnames.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Groupofnames.php new file mode 100644 index 000000000..bd39b3951 --- /dev/null +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Groupofnames.php @@ -0,0 +1,232 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ + +/** + * This class provides methods to deal with groups. + * + * Copyright 2008-2009 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + * + * @category Kolab + * @package Kolab_Server + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ +class Horde_Kolab_Server_Object_Groupofnames extends Horde_Kolab_Server_Object +{ + /** Define attributes specific to this object type */ + + /** The common name */ + const ATTRIBUTE_CN = 'cn'; + + /** The members of this group */ + const ATTRIBUTE_MEMBER = 'member'; + + /** The specific object class of this object type */ + const OBJECTCLASS_GROUPOFNAMES = 'groupOfNames'; + + /** + * A structure to initialize the attribute structure for this class. + * + * @var array + */ + static public $init_attributes = array( + 'required' => array( + self::ATTRIBUTE_CN, + self::ATTRIBUTE_MEMBER, + ), + 'defined' => array( + self::ATTRIBUTE_CN, + self::ATTRIBUTE_MEMBER, + ), + 'object_classes' => array( + self::OBJECTCLASS_GROUPOFNAMES, + ), + ); + + /** + * Return the filter string to retrieve this object type. + * + * @static + * + * @return string The filter to retrieve this object type from the server + * database. + */ + public static function getFilter() + { + return '(' . self::ATTRIBUTE_OC . '=' . self::OBJECTCLASS_GROUPOFNAMES . ')'; + } + + /** + * Generates an ID for the given information. + * + * @param array $info The data of the object. + * + * @static + * + * @return string|PEAR_Error The ID. + */ + public static function generateId($info) + { + return trim(self::ATTRIBUTE_CN . '=' . $info[self::ATTRIBUTE_CN], " \t\n\r\0\x0B,"); + } + + /** + * Retrieve the member list for this group. + * + * @return array|PEAR_Error The list of members in this group. + */ + public function getMembers() + { + return $this->_get(self::ATTRIBUTE_MEMBER, false); + } + + /** + * Add a member to this group. + * + * @param string $member The UID of the member to add. + * + * @return array|PEAR_Error True if successful. + */ + public function addMember($member) + { + $members = $this->getMembers(); + if (is_a($members, 'PEAR_Error')) { + return $members; + } + if (!in_array($member, $members)) { + $this->_cache[self::ATTRIBUTE_MEMBER][] = $member; + } else { + return PEAR::raiseError(_("The UID %s is already a member of the group %s!"), + $member, $this->_uid); + } + return $this->save($this->_cache); + } + + /** + * Delete a member from this group. + * + * @param string $member The UID of the member to delete. + * + * @return array|PEAR_Error True if successful. + */ + public function deleteMember($member) + { + $members = $this->getMembers(); + if (is_a($members, 'PEAR_Error')) { + return $members; + } + if (in_array($member, $members)) { + //FIXME: As the member attribute is required we may not remove the last member + $this->_cache[self::ATTRIBUTE_MEMBER] = + array_diff($this->_cache[self::ATTRIBUTE_MEMBER], + array($member)); + } else { + return PEAR::raiseError(_("The UID %s is no member of the group %s!"), + $member, $this->_uid); + + } + return $this->save($this->_cache); + } + + /** + * Is the specified UID member of this group? + * + * @param string $member The UID of the member to check. + * + * @return boolean|PEAR_Error True if the UID is a member of the group, + * false otherwise. + */ + public function isMember($member) + { + $members = $this->getMembers(); + if (is_a($members, 'PEAR_Error') || !is_array($members)) { + return $members; + } + if (!in_array($member, $members)) { + return false; + } else { + return true; + } + } + + /** + * Returns the set of search operations supported by this object type. + * + * @return array An array of supported search operations. + */ + static public function getSearchOperations() + { + $searches = array( + 'gidForSearch', + 'getGroups', + ); + return $searches; + } + + /** + * FIXME: This method belongs somewhere where we are aware of groups + * Identify the GID for the first group found using the specified + * search criteria + * + * @param array $criteria The search parameters as array. + * @param int $restrict A Horde_Kolab_Server::RESULT_* result restriction. + * + * @return boolean|string|array The GID(s) or false if there was no result. + * + * @throws Horde_Kolab_Server_Exception + */ + static public function gidForSearch($server, $criteria, + $restrict = Horde_Kolab_Server_Object::RESULT_SINGLE) + { + $groups = array('field' => self::ATTRIBUTE_OC, + 'op' => '=', + 'test' => self::OBJECTCLASS_GROUPOFNAMES); + if (!empty($criteria)) { + $criteria = array('AND' => array($groups, $criteria)); + } else { + $criteria = array('AND' => array($groups)); + } + return self::basicUidForSearch($server, $criteria, $restrict); + } + + /** + * Get the groups for this object. + * + * @param string $uid The UID of the object to fetch. + * + * @return array An array of group ids. + * + * @throws Horde_Kolab_Server_Exception + */ + public function getGroups($server, $uid) + { + $criteria = array('AND' => + array( + array('field' => self::ATTRIBUTE_MEMBER, + 'op' => '=', + 'test' => $uid), + ), + ); + + $result = self::gidForSearch($server, $criteria, self::RESULT_MANY); + if (empty($result)) { + return array(); + } + return $result; + } + +} diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Kolabgroupofnames.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Kolabgroupofnames.php index 060e781df..8af79306e 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Kolabgroupofnames.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Kolabgroupofnames.php @@ -25,43 +25,41 @@ * @license http://www.fsf.org/copyleft/lgpl.html LGPL * @link http://pear.horde.org/index.php?package=Kolab_Server */ -class Horde_Kolab_Server_Object_Kolabgroupofnames extends Horde_Kolab_Server_Object_Inetorgperson +class Horde_Kolab_Server_Object_Kolabgroupofnames extends Horde_Kolab_Server_Object_Groupofnames { + /** Define attributes specific to this object type */ - const ATTRIBUTE_VISIBILITY = 'visible'; - const ATTRIBUTE_MEMBER = 'member'; + /** The visibility of the group */ + const ATTRIBUTE_VISIBILITY = 'visible'; - const OBJECTCLASS_KOLABGROUPOFNAMES = 'kolabGroupOfNames'; + /** The members of this group */ + const ATTRIBUTE_MEMBER = 'member'; - /** - * Attributes derived from the LDAP values. - * - * @var array - */ - public $derived_attributes = array( - self::ATTRIBUTE_ID, - self::ATTRIBUTE_VISIBILITY, - ); + /** The mail address of this group */ + const ATTRIBUTE_MAIL = 'mail'; + + /** The specific object class of this object type */ + const OBJECTCLASS_KOLABGROUPOFNAMES = 'kolabGroupOfNames'; /** - * The ldap classes for this type of object. + * A structure to initialize the attribute structure for this class. * * @var array */ - public $object_classes = array( - self::OBJECTCLASS_TOP, - self::OBJECTCLASS_INETORGPERSON, - self::OBJECTCLASS_KOLABGROUPOFNAMES, + static public $init_attributes = array( + 'defined' => array( + self::ATTRIBUTE_VISIBILITY, + self::ATTRIBUTE_MAIL, + ), + 'derived' => array( + self::ATTRIBUTE_VISIBILITY => array(), + ), + 'object_classes' => array( + self::OBJECTCLASS_KOLABGROUPOFNAMES, + ), ); /** - * Sort by this attributes (must be a LDAP attribute). - * - * @var string - */ - public $sort_by = self::ATTRIBUTE_MAIL; - - /** * Return the filter string to retrieve this object type. * * @static @@ -71,7 +69,7 @@ class Horde_Kolab_Server_Object_Kolabgroupofnames extends Horde_Kolab_Server_Obj */ public static function getFilter() { - return '(objectClass=kolabGroupOfNames)'; + return '(' . self::ATTRIBUTE_OC . '=' . self::OBJECTCLASS_KOLABGROUPOFNAMES . ')'; } /** @@ -85,6 +83,8 @@ class Horde_Kolab_Server_Object_Kolabgroupofnames extends Horde_Kolab_Server_Obj { switch ($attr) { case self::ATTRIBUTE_VISIBILITY: + //FIXME: This needs structural knowledge and should be in a + //structural class. return strpos($this->_uid, 'cn=internal') === false; default: return parent::derive($attr); @@ -92,25 +92,6 @@ class Horde_Kolab_Server_Object_Kolabgroupofnames extends Horde_Kolab_Server_Obj } /** - * Convert the object attributes to a hash. - * - * @param string $attrs The attributes to return. - * - * @return array|PEAR_Error The hash representing this object. - */ - public function toHash($attrs = null) - { - if (!isset($attrs)) { - $attrs = array( - self::ATTRIBUTE_ID, - self::ATTRIBUTE_MAIL, - self::ATTRIBUTE_VISIBILITY, - ); - } - return parent::toHash($attrs); - } - - /** * Generates an ID for the given information. * * @param array $info The data of the object. @@ -121,10 +102,10 @@ class Horde_Kolab_Server_Object_Kolabgroupofnames extends Horde_Kolab_Server_Obj */ public static function generateId($info) { - if (isset($info['mail'])) { - return trim($info['mail'], " \t\n\r\0\x0B,"); + if (isset($info[self::ATTRIBUTE_MAIL])) { + return trim(self::ATTRIBUTE_CN . '=' . $info[self::ATTRIBUTE_MAIL], " \t\n\r\0\x0B,"); } else { - return trim($info['cn'], " \t\n\r\0\x0B,"); + return trim(self::ATTRIBUTE_CN . '=' . $info[self::ATTRIBUTE_CN], " \t\n\r\0\x0B,"); } } @@ -137,95 +118,17 @@ class Horde_Kolab_Server_Object_Kolabgroupofnames extends Horde_Kolab_Server_Obj */ public function save($info) { - if (!isset($info['cn'])) { - if (!isset($info['mail'])) { + if (!isset($info[self::ATTRIBUTE_CN])) { + if (!isset($info[self::ATTRIBUTE_MAIL])) { throw new Horde_Kolab_Server_Exception('Either the mail address or the common name has to be specified for a group object!'); } else { - $info['cn'] = $info['mail']; + $info[self::ATTRIBUTE_CN] = $info[self::ATTRIBUTE_MAIL]; } } return parent::save($info); } /** - * Retrieve the member list for this group. - * - * @return array|PEAR_Error The list of members in this group. - */ - public function getMembers() - { - return $this->_get(self::ATTRIBUTE_MEMBER, false); - } - - /** - * Add a member to this group. - * - * @param string $member The UID of the member to add. - * - * @return array|PEAR_Error True if successful. - */ - public function addMember($member) - { - $members = $this->getMembers(); - if (is_a($members, 'PEAR_Error')) { - return $members; - } - if (!in_array($member, $members)) { - $this->_cache[self::ATTRIBUTE_MEMBER][] = $member; - } else { - return PEAR::raiseError(_("The UID %s is already a member of the group %s!"), - $member, $this->_uid); - } - return $this->save($this->_cache); - } - - /** - * Delete a member from this group. - * - * @param string $member The UID of the member to delete. - * - * @return array|PEAR_Error True if successful. - */ - public function deleteMember($member) - { - $members = $this->getMembers(); - if (is_a($members, 'PEAR_Error')) { - return $members; - } - if (in_array($member, $members)) { - $this->_cache[self::ATTRIBUTE_MEMBER] = - array_diff($this->_cache[self::ATTRIBUTE_MEMBER], - array($member)); - } else { - return PEAR::raiseError(_("The UID %s is no member of the group %s!"), - $member, $this->_uid); - - } - return $this->save($this->_cache); - } - - /** - * Is the specified UID member of this group? - * - * @param string $member The UID of the member to check. - * - * @return boolean|PEAR_Error True if the UID is a member of the group, - * false otherwise. - */ - public function isMember($member) - { - $members = $this->getMembers(); - if (is_a($members, 'PEAR_Error') || !is_array($members)) { - return $members; - } - if (!in_array($member, $members)) { - return false; - } else { - return true; - } - } - - /** * Returns the set of search operations supported by this object type. * * @return array An array of supported search operations. @@ -233,41 +136,13 @@ class Horde_Kolab_Server_Object_Kolabgroupofnames extends Horde_Kolab_Server_Obj static public function getSearchOperations() { $searches = array( - 'gidForSearch', 'gidForMail', 'memberOfGroupAddress', - 'getGroups', ); return $searches; } /** - * FIXME: This method belongs somewhere where we are aware of groups - * Identify the GID for the first group found using the specified - * search criteria - * - * @param array $criteria The search parameters as array. - * @param int $restrict A Horde_Kolab_Server::RESULT_* result restriction. - * - * @return boolean|string|array The GID(s) or false if there was no result. - * - * @throws Horde_Kolab_Server_Exception - */ - static public function gidForSearch($server, $criteria, - $restrict = Horde_Kolab_Server_Object::RESULT_SINGLE) - { - $groups = array('field' => self::ATTRIBUTE_OC, - 'op' => '=', - 'test' => self::OBJECTCLASS_KOLABGROUPOFNAMES); - if (!empty($criteria)) { - $criteria = array('AND' => array($groups, $criteria)); - } else { - $criteria = array('AND' => array($groups)); - } - return self::basicUidForSearch($server, $criteria, $restrict); - } - - /** * Identify the GID for the first group found with the given mail. * * @param string $mail Search for groups with this mail address. @@ -280,7 +155,7 @@ class Horde_Kolab_Server_Object_Kolabgroupofnames extends Horde_Kolab_Server_Obj static public function gidForMail($server, $mail, $restrict = Horde_Kolab_Server_Object::RESULT_SINGLE) { - $criteria = array('AND' => array(array('field' => self::ATTRIBUTE_MEMBER, + $criteria = array('AND' => array(array('field' => self::ATTRIBUTE_MAIL, 'op' => '=', 'test' => $mail), ), @@ -316,30 +191,4 @@ class Horde_Kolab_Server_Object_Kolabgroupofnames extends Horde_Kolab_Server_Obj return !empty($result); } - /** - * Get the groups for this object. - * - * @param string $uid The UID of the object to fetch. - * - * @return array An array of group ids. - * - * @throws Horde_Kolab_Server_Exception - */ - public function getGroups($server, $uid) - { - $criteria = array('AND' => - array( - array('field' => self::ATTRIBUTE_MEMBER, - 'op' => '=', - 'test' => $uid), - ), - ); - - $result = self::gidForSearch($server, $criteria, self::RESULT_MANY); - if (empty($result)) { - return array(); - } - return $result; - } - } diff --git a/framework/Kolab_Server/package.xml b/framework/Kolab_Server/package.xml index 7a23dcf48..e443dd65c 100644 --- a/framework/Kolab_Server/package.xml +++ b/framework/Kolab_Server/package.xml @@ -55,6 +55,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> + @@ -146,6 +147,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> + -- 2.11.0