Added getGroupAddresses() to return the mail addresses of groups
authorGunnar Wrobel <p@rdus.de>
Sat, 25 Apr 2009 06:02:08 +0000 (08:02 +0200)
committerGunnar Wrobel <p@rdus.de>
Sat, 25 Apr 2009 06:02:08 +0000 (08:02 +0200)
the user belongs to.

framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Kolabgroupofnames.php
framework/Kolab_Server/package.xml
framework/Kolab_Server/test/Horde/Kolab/Server/TestTest.php

index aabcd79..228c7ba 100644 (file)
@@ -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;
+    }
 }
index 40b02c5..111e4d5 100644 (file)
@@ -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.
  </notes>
  <contents>
   <dir name="/">
index 29e78a8..a9ec3df 100644 (file)
@@ -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));