From 7aedf9ac133b63020a805955963a8d5542945664 Mon Sep 17 00:00:00 2001 From: Gunnar Wrobel Date: Sat, 25 Apr 2009 08:02:08 +0200 Subject: [PATCH] Added getGroupAddresses() to return the mail addresses of groups the user belongs to. --- .../Kolab/Server/Object/Kolabgroupofnames.php | 43 ++++++++++++++++++++++ framework/Kolab_Server/package.xml | 2 + .../test/Horde/Kolab/Server/TestTest.php | 8 ++++ 3 files changed, 53 insertions(+) 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 aabcd7944..228c7bab0 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Kolabgroupofnames.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Kolabgroupofnames.php @@ -147,6 +147,7 @@ class Horde_Kolab_Server_Object_Kolabgroupofnames extends Horde_Kolab_Server_Obj $searches = array( 'gidForMail', 'memberOfGroupAddress', + 'getGroupAddresses', ); return $searches; } @@ -200,4 +201,46 @@ class Horde_Kolab_Server_Object_Kolabgroupofnames extends Horde_Kolab_Server_Obj return !empty($result); } + + /** + * Get the mail addresses for the group of this object. + * + * @param string $uid The UID of the object to fetch. + * + * @return array An array of mail addresses. + * + * @throws Horde_Kolab_Server_Exception + */ + static public function getGroupAddresses($server, $uid) + { + $criteria = array('AND' => + array( + array('field' => self::ATTRIBUTE_OC, + 'op' => '=', + 'test' => self::OBJECTCLASS_GROUPOFNAMES), + array('field' => self::ATTRIBUTE_MEMBER, + 'op' => '=', + 'test' => $uid), + ), + ); + + $data = self::attrsForSearch($server, $criteria, array(self::ATTRIBUTE_MAIL), + self::RESULT_MANY); + + if (empty($data)) { + return array(); + } + + $mails = array(); + foreach ($data as $element) { + if (isset($element[self::ATTRIBUTE_MAIL])) { + if (is_array($element[self::ATTRIBUTE_MAIL])) { + $mails = array_merge($mails, $element[self::ATTRIBUTE_MAIL]); + } else { + $mails[] = $element[self::ATTRIBUTE_MAIL]; + } + } + } + return $mails; + } } diff --git a/framework/Kolab_Server/package.xml b/framework/Kolab_Server/package.xml index 40b02c532..111e4d528 100644 --- a/framework/Kolab_Server/package.xml +++ b/framework/Kolab_Server/package.xml @@ -51,6 +51,8 @@ http://pear.php.net/dtd/package-2.0.xsd"> * Added LDAP write support. * Real LDAP server unit testing. * Support configurable attribute mapping. + * Added getGroupAddresses() to return the mail addresses of groups + the user belongs to. diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/TestTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/TestTest.php index 29e78a886..a9ec3df52 100644 --- a/framework/Kolab_Server/test/Horde/Kolab/Server/TestTest.php +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/TestTest.php @@ -415,10 +415,18 @@ class Horde_Kolab_Server_testTest extends Horde_Kolab_Test_Server $this->assertNoError($groups); $this->assertContains('cn=group@example.org,dc=example,dc=org', $groups); + $groups = $server->getGroupAddresses($server->uidForIdOrMailOrAlias('g.wrobel@example.org')); + $this->assertNoError($groups); + $this->assertContains('group@example.org', $groups); + $groups = $server->getGroups($server->uidForIdOrMailOrAlias('test@example.org')); $this->assertNoError($groups); $this->assertContains('cn=group@example.org,dc=example,dc=org', $groups); + $groups = $server->getGroupAddresses($server->uidForIdOrMailOrAlias('test@example.org')); + $this->assertNoError($groups); + $this->assertContains('group@example.org', $groups); + $groups = $server->getGroups('nobody'); $this->assertNoError($groups); $this->assertTrue(empty($groups)); -- 2.11.0