4 commits - lib/api lib/Auth lib/client lib/Conf.php lib/kolab_client_task.php

Aleksander Machniak machniak at kolabsys.com
Mon Apr 9 11:45:48 CEST 2012


 lib/Auth/LDAP.php                        |   15 ++++-
 lib/Conf.php                             |    5 -
 lib/api/kolab_api_service_form_value.php |    1 
 lib/api/kolab_api_service_groups.php     |    1 
 lib/api/kolab_api_service_users.php      |    3 -
 lib/client/kolab_client_task_group.php   |   16 -----
 lib/client/kolab_client_task_user.php    |   20 +------
 lib/kolab_client_task.php                |   85 +++++++++++++++++++++++++++++++
 8 files changed, 107 insertions(+), 39 deletions(-)

New commits:
commit 084db79d046280765ad67a1391cb77ee791ce602
Author: Aleksander Machniak <machniak at kolabsys.com>
Date:   Mon Apr 9 11:45:35 2012 +0200

    Resolve group names too

diff --git a/lib/api/kolab_api_service_form_value.php b/lib/api/kolab_api_service_form_value.php
index 694a1d8..00a6bdd 100644
--- a/lib/api/kolab_api_service_form_value.php
+++ b/lib/api/kolab_api_service_form_value.php
@@ -703,7 +703,6 @@ class kolab_api_service_form_value extends kolab_api_service
         );
 
         $result = $service->users_list(null, $data);
-
         $list   = $result['list'];
 
         $service = $this->controller->get_service('groups');
diff --git a/lib/api/kolab_api_service_groups.php b/lib/api/kolab_api_service_groups.php
index ff8781b..86ab9b5 100644
--- a/lib/api/kolab_api_service_groups.php
+++ b/lib/api/kolab_api_service_groups.php
@@ -33,6 +33,7 @@ class kolab_api_service_groups extends kolab_api_service
         'gidnumber',
         'objectclass',
         'mail',
+        'entrydn',
     );
 
     /**
diff --git a/lib/kolab_client_task.php b/lib/kolab_client_task.php
index e17593c..14e644a 100644
--- a/lib/kolab_client_task.php
+++ b/lib/kolab_client_task.php
@@ -1137,7 +1137,7 @@ class kolab_client_task
             }
         }
 
-        // Get user names for DN lists, e.g. kolabdelegate
+        // Get user-friendly names for DN lists, e.g. kolabdelegate
         $list_attrs = array('kolabdelegate', 'member', 'uniquemember');
         foreach ($list_attrs as $la) {
             if (!empty($fields[$la]) && !empty($data[$la])) {
@@ -1163,7 +1163,6 @@ class kolab_client_task
                 );
 
                 // get users list
-                // @TODO: what about groups here?
                 $result = $this->api->post('users.list', null, $post);
                 $result = $result->get('list');
                 $list   = array();
@@ -1176,6 +1175,23 @@ class kolab_client_task
                         }
                     }
                 }
+
+                // Search for groups too
+                if (count($list) < count($search)) {
+                    // get groups list
+                    $result = $this->api->post('groups.list', null, $post);
+                    $result = $result->get('list');
+                
+                    if (is_array($result)) {
+                        foreach ($result as $key => $val) {
+                            $list[$key] = $val['cn'];
+                            if ($val['mail']) {
+                                $list[$key] .= ' <' . $val['mail'] . '>';
+                            }
+                        }
+                    }
+                }
+
                 $data[$la] = $list;
             }
         }


commit 384593bb684fefe50b2e56c3a92657c3f6da374c
Author: Aleksander Machniak <machniak at kolabsys.com>
Date:   Mon Apr 9 11:38:50 2012 +0200

    Add unified method to resolve entrydn into user-friendly text.
    Fixed bug where entrydn was listed on list widgets after form reload (type_id change).

diff --git a/lib/Auth/LDAP.php b/lib/Auth/LDAP.php
index cf64ff9..bcd3491 100644
--- a/lib/Auth/LDAP.php
+++ b/lib/Auth/LDAP.php
@@ -1623,8 +1623,6 @@ class LDAP
 
         $filter = '';
         foreach ((array) $search['params'] as $field => $param) {
-            $value = self::_quote_string($param['value']);
-
             switch ((string)$param['type']) {
             case 'prefix':
                 $prefix = '';
@@ -1645,7 +1643,18 @@ class LDAP
                 break;
             }
 
-            $filter .= "($field=$prefix" . $value . "$suffix)";
+            if (is_array($param['value'])) {
+                $val_filter = array();
+                foreach ($param['value'] as $val) {
+                    $value = self::_quote_string($val);
+                    $val_filter[] = "($field=$prefix" . $value . "$suffix)";
+                }
+                $filter .= "(|" . implode($val_filter, '') . ")";
+            }
+            else {
+                $value = self::_quote_string($param['value']);
+                $filter .= "($field=$prefix" . $value . "$suffix)";
+            }
         }
 
         // join search parameters with specified operator ('OR' or 'AND')
diff --git a/lib/api/kolab_api_service_users.php b/lib/api/kolab_api_service_users.php
index 854fc46..2b60e56 100644
--- a/lib/api/kolab_api_service_users.php
+++ b/lib/api/kolab_api_service_users.php
@@ -39,7 +39,7 @@ class kolab_api_service_users extends kolab_api_service
         'uidnumber',
         'gidnumber',
         'mailhost',
-        'dn',
+        'entrydn',
     );
 
 
@@ -86,6 +86,7 @@ class kolab_api_service_users extends kolab_api_service
         // searching
         if (!empty($post['search']) && is_array($post['search'])) {
             $params = $post['search'];
+
             foreach ($params as $idx => $param) {
                 // get only supported attributes
                 if (!in_array($idx, $this->list_attribs)) {
diff --git a/lib/client/kolab_client_task_group.php b/lib/client/kolab_client_task_group.php
index d014a21..d257129 100644
--- a/lib/client/kolab_client_task_group.php
+++ b/lib/client/kolab_client_task_group.php
@@ -252,20 +252,8 @@ class kolab_client_task_group extends kolab_client_task
             );
         }
 
-        // Members (get member names)
-        if (!$add_mode) {
-            // find members attribute name
-            foreach (array('member', 'uniquemember') as $attr) {
-                if (isset($fields[$attr]) && isset($data[$attr])) {
-                    $attr_name = $attr;
-                }
-            }
-            if (!empty($attr_name)) {
-                $result = $this->api->get('group.members_list', array('group' => $data['id']));
-                $list   = (array) $result->get('list');
-                $data[$attr_name] = $this->parse_members($list);
-            }
-        }
+        // Prepare data of the form
+        $this->form_data_prepare($fields, $data);
 
         // Create form object and populate with fields
         $form = $this->form_create('group', $attribs, $sections, $fields, $fields_map, $data, $add_mode);
diff --git a/lib/client/kolab_client_task_user.php b/lib/client/kolab_client_task_user.php
index bf92ee0..34ca6c2 100644
--- a/lib/client/kolab_client_task_user.php
+++ b/lib/client/kolab_client_task_user.php
@@ -311,25 +311,11 @@ class kolab_client_task_user extends kolab_client_task
                 'section'  => 'personal',
                 'value'    => $accttypes[$type]['content'],
             );
-
-            // Roles (extract role names)
-            $role_attrs = array('nsrole', 'nsroledn');
-            foreach ($role_attrs as $ra) {
-                if (!empty($fields[$ra]) && !empty($data[$ra])) {
-                    if (!is_array($data[$ra])) {
-                        $data[$ra] = (array) $data[$ra];
-                    }
-                    $data[$ra] = array_combine($data[$ra], $data[$ra]);
-                    foreach ($data[$ra] as $dn => $val) {
-                        // @TODO: maybe ldap_explode_dn() would be better?
-                        if (preg_match('/^cn=([^,]+)/i', $val, $m)) {
-                            $data[$ra][$dn] = $m[1];
-                        }
-                    }
-                }
-            }
         }
 
+        // Prepare data for the form
+        $this->form_data_prepare($fields, $data);
+
         // Create form object and populate with fields
         $form = $this->form_create('user', $attribs, $sections, $fields, $fields_map, $data, $add_mode);
 
diff --git a/lib/kolab_client_task.php b/lib/kolab_client_task.php
index 7f14df4..e17593c 100644
--- a/lib/kolab_client_task.php
+++ b/lib/kolab_client_task.php
@@ -1112,4 +1112,73 @@ class kolab_client_task
         return $form;
     }
 
+    /**
+     * Resolves entries of common list fields into user-friendly form
+     *
+     * @param array $fields  Form fields definition
+     * @param array $data    Form data
+     */
+    protected function form_data_prepare($fields, &$data)
+    {
+        // Roles (extract role names)
+        $role_attrs = array('nsrole', 'nsroledn');
+        foreach ($role_attrs as $ra) {
+            if (!empty($fields[$ra]) && !empty($data[$ra])) {
+                if (!is_array($data[$ra])) {
+                    $data[$ra] = (array) $data[$ra];
+                }
+                $data[$ra] = array_combine($data[$ra], $data[$ra]);
+                foreach ($data[$ra] as $dn => $val) {
+                    // @TODO: maybe ldap_explode_dn() would be better?
+                    if (preg_match('/^cn=([^,]+)/i', $val, $m)) {
+                        $data[$ra][$dn] = $m[1];
+                    }
+                }
+            }
+        }
+
+        // Get user names for DN lists, e.g. kolabdelegate
+        $list_attrs = array('kolabdelegate', 'member', 'uniquemember');
+        foreach ($list_attrs as $la) {
+            if (!empty($fields[$la]) && !empty($data[$la])) {
+                if (!is_array($data[$la])) {
+                    $data[$la] = (array) $data[$la];
+                }
+
+                $search = array();
+                foreach ($data[$la] as $key => $val) {
+                    $search[] = $val;
+                }
+
+                // request parameters
+                $post = array(
+                    'attributes'      => array('displayname', 'cn', 'mail'),
+                    'search'          => array(
+                        'entrydn' => array(
+                            'value' => $search,
+                            'type'  => 'exact',
+                        ),
+                    ),
+                    'search_operator' => 'OR',
+                );
+
+                // get users list
+                // @TODO: what about groups here?
+                $result = $this->api->post('users.list', null, $post);
+                $result = $result->get('list');
+                $list   = array();
+                
+                if (is_array($result)) {
+                    foreach ($result as $key => $val) {
+                        $list[$key] = $val['displayname'] ? $val['displayname'] : $val['cn'];
+                        if ($val['mail']) {
+                            $list[$key] .= ' <' . $val['mail'] . '>';
+                        }
+                    }
+                }
+                $data[$la] = $list;
+            }
+        }
+    }
+
 }


commit 78c736b237feac475f83c4427ff902bb39b15066
Author: Aleksander Machniak <machniak at kolabsys.com>
Date:   Mon Apr 9 10:51:58 2012 +0200

    Fix parse error in last commit

diff --git a/lib/Conf.php b/lib/Conf.php
index 326f66f..4f1f883 100644
--- a/lib/Conf.php
+++ b/lib/Conf.php
@@ -152,8 +152,7 @@ class Conf {
         }
 
 //        error_log("Could not find setting for \$key1: " . $key1 .
-//                " with \$key2: " . $key2
-            );
+//                " with \$key2: " . $key2);
 
         return false;
     }


commit 969b3e5f01870d19643a3d291539d58a0ba1b58e
Author: Aleksander Machniak <machniak at kolabsys.com>
Date:   Mon Apr 9 10:50:32 2012 +0200

    Comment out some debug code

diff --git a/lib/Conf.php b/lib/Conf.php
index ccfe451..326f66f 100644
--- a/lib/Conf.php
+++ b/lib/Conf.php
@@ -151,8 +151,8 @@ class Conf {
             return $this->_conf['kolab'][$key1];
         }
 
-        error_log("Could not find setting for \$key1: " . $key1 .
-                " with \$key2: " . $key2
+//        error_log("Could not find setting for \$key1: " . $key1 .
+//                " with \$key2: " . $key2
             );
 
         return false;





More information about the commits mailing list