diff options
author | Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com> | 2012-04-09 14:38:15 (GMT) |
---|---|---|
committer | Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com> | 2012-04-09 14:38:15 (GMT) |
commit | c60c67c360d441bc40ca2017c1d0358301b0e10e (patch) | |
tree | 180f73d33007ebbf12eec35a7717af53bb7242aa | |
parent | 0f4ab65529e6be6a31c67c39b46da9f195ec7598 (diff) | |
parent | 6a72d8db409e11077dd04c43b2600cc0a1a7e782 (diff) | |
download | kolab-wap-c60c67c360d441bc40ca2017c1d0358301b0e10e.tar.gz |
Merge branch 'master' of ssh://git.kolab.org/git/kolab-wap
Conflicts:
lib/api/kolab_api_service_form_value.php
-rw-r--r-- | lib/Auth/LDAP.php | 15 | ||||
-rw-r--r-- | lib/Conf.php | 5 | ||||
-rw-r--r-- | lib/api/kolab_api_service_form_value.php | 68 | ||||
-rw-r--r-- | lib/api/kolab_api_service_groups.php | 1 | ||||
-rw-r--r-- | lib/api/kolab_api_service_users.php | 3 | ||||
-rw-r--r-- | lib/client/kolab_client_task_group.php | 16 | ||||
-rw-r--r-- | lib/client/kolab_client_task_user.php | 20 | ||||
-rw-r--r-- | lib/kolab_api_service.php | 8 | ||||
-rw-r--r-- | lib/kolab_client_task.php | 89 |
9 files changed, 125 insertions, 100 deletions
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/Conf.php b/lib/Conf.php index ccfe451..4f1f883 100644 --- a/lib/Conf.php +++ b/lib/Conf.php @@ -151,9 +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; } diff --git a/lib/api/kolab_api_service_form_value.php b/lib/api/kolab_api_service_form_value.php index 7164246..63c04d7 100644 --- a/lib/api/kolab_api_service_form_value.php +++ b/lib/api/kolab_api_service_form_value.php @@ -206,16 +206,10 @@ class kolab_api_service_form_value extends kolab_api_service private function generate_cn($postdata, $attribs = array()) { - $conf = Conf::get_instance(); - $unique_attr = $conf->get('unique_attribute'); - if (!$unique_attr) { - $unique_attr = 'nsuniqueid'; - } - if (isset($attribs['auto_form_fields']) && isset($attribs['auto_form_fields']['cn'])) { // Use Data Please foreach ($attribs['auto_form_fields']['cn']['data'] as $key) { - if (!isset($postdata[$key]) && !($key == $unique_attr)) { + if (!isset($postdata[$key])) { throw new Exception("Key not set: " . $key, 12356); } } @@ -229,16 +223,10 @@ class kolab_api_service_form_value extends kolab_api_service private function generate_displayname($postdata, $attribs = array()) { - $conf = Conf::get_instance(); - $unique_attr = $conf->get('unique_attribute'); - if (!$unique_attr) { - $unique_attr = 'nsuniqueid'; - } - if (isset($attribs['auto_form_fields']) && isset($attribs['auto_form_fields']['displayname'])) { // Use Data Please foreach ($attribs['auto_form_fields']['displayname']['data'] as $key) { - if (!isset($postdata[$key]) && !($key == $unique_attr)) { + if (!isset($postdata[$key])) { throw new Exception("Key not set: " . $key, 12356); } } @@ -309,16 +297,10 @@ class kolab_api_service_form_value extends kolab_api_service private function generate_homedirectory($postdata, $attribs = array()) { - $conf = Conf::get_instance(); - $unique_attr = $conf->get('unique_attribute'); - if (!$unique_attr) { - $unique_attr = 'nsuniqueid'; - } - if (isset($attribs['auto_form_fields']) && isset($attribs['auto_form_fields']['homedirectory'])) { // Use Data Please foreach ($attribs['auto_form_fields']['homedirectory']['data'] as $key) { - if (!isset($postdata[$key]) && !($key == $unique_attr)) { + if (!isset($postdata[$key])) { throw new Exception("Key not set: " . $key, 12356); } } @@ -369,16 +351,10 @@ class kolab_api_service_form_value extends kolab_api_service private function generate_primary_mail($postdata, $attribs = array()) { - $conf = Conf::get_instance(); - $unique_attr = $conf->get('unique_attribute'); - if (!$unique_attr) { - $unique_attr = 'nsuniqueid'; - } - if (isset($attribs['auto_form_fields']) && isset($attribs['auto_form_fields']['mail'])) { // Use Data Please foreach ($attribs['auto_form_fields']['mail']['data'] as $key) { - if (!isset($postdata[$key]) && !($key == $unique_attr)) { + if (!isset($postdata[$key])) { throw new Exception("Key not set: " . $key, 12356); } } @@ -397,16 +373,10 @@ class kolab_api_service_form_value extends kolab_api_service private function generate_primary_mail_group($postdata, $attribs = array()) { - $conf = Conf::get_instance(); - $unique_attr = $conf->get('unique_attribute'); - if (!$unique_attr) { - $unique_attr = 'nsuniqueid'; - } - if (isset($attribs['auto_form_fields']) && isset($attribs['auto_form_fields']['mail'])) { // Use Data Please foreach ($attribs['auto_form_fields']['mail']['data'] as $key) { - if (!isset($postdata[$key]) && !($key == $unique_attr)) { + if (!isset($postdata[$key])) { throw new Exception("Key not set: " . $key, 12356); } } @@ -419,12 +389,6 @@ class kolab_api_service_form_value extends kolab_api_service private function generate_secondary_mail($postdata, $attribs = array()) { - $conf = Conf::get_instance(); - $unique_attr = $conf->get('unique_attribute'); - if (!$unique_attr) { - $unique_attr = 'nsuniqueid'; - } - $secondary_mail_address = Array(); if (isset($attribs['auto_form_fields'])) { @@ -437,7 +401,7 @@ class kolab_api_service_form_value extends kolab_api_service } foreach ($attribs['auto_form_fields'][$secondary_mail_key]['data'] as $key) { - if (!isset($postdata[$key]) && !($key == $unique_attr)) { + if (!isset($postdata[$key])) { throw new Exception("Key not set: " . $key, 456789); } } @@ -456,18 +420,10 @@ class kolab_api_service_form_value extends kolab_api_service private function generate_uid($postdata, $attribs = array()) { - //console("generate_uid() \$postdata", $postdata); - - $conf = Conf::get_instance(); - $unique_attr = $conf->get('unique_attribute'); - if (!$unique_attr) { - $unique_attr = 'nsuniqueid'; - } - if (isset($attribs['auto_form_fields']) && isset($attribs['auto_form_fields']['uid'])) { // Use Data Please foreach ($attribs['auto_form_fields']['uid']['data'] as $key) { - if (!isset($postdata[$key]) && !($key == $unique_attr)) { + if (!isset($postdata[$key])) { throw new Exception("Key not set: " . $key, 12356); } } @@ -489,6 +445,12 @@ class kolab_api_service_form_value extends kolab_api_service $orig_uid = $uid; $auth = Auth::get_instance($_SESSION['user']->get_domain()); + $conf = Conf::get_instance(); + + $unique_attr = $conf->get('unique_attribute'); + if (!$unique_attr) { + $unique_attr = 'nsuniqueid'; + } $x = 2; while (($user_found = $auth->user_find_by_attribute(array('uid' => $uid)))) { @@ -634,6 +596,9 @@ class kolab_api_service_form_value extends kolab_api_service $conf = Conf::get_instance(); $unique_attr = $conf->get('unique_attribute'); + if (!$unique_attr) { + $unique_attr = 'nsuniqueid'; + } $base_dn = $conf->get('user_base_dn'); if (!$base_dn) { @@ -720,7 +685,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/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_api_service.php b/lib/kolab_api_service.php index b99e780..d43aa67 100644 --- a/lib/kolab_api_service.php +++ b/lib/kolab_api_service.php @@ -166,14 +166,6 @@ abstract class kolab_api_service if ($key != "id") { if ($key == "attributes") { $object_types[$row['id']][$key] = json_decode($value, true); - // TODO: Insert unique_attr to attributes, auto_form_fields, $attribute, $data here. - if (array_key_exists('auto_form_fields', $object_types[$row['id']][$key])) { - foreach ($object_types[$row['id']][$key]['auto_form_fields'] as $attribute => $data) { - if (array_key_exists('data', $data) && !in_array($unique_attr, $data['data'])) { - $object_types[$row['id']][$key]['auto_form_fields'][$attribute]['data'][] = $unique_attr; - } - } - } } else { $object_types[$row['id']][$key] = $value; diff --git a/lib/kolab_client_task.php b/lib/kolab_client_task.php index e8fa114..a4cd924 100644 --- a/lib/kolab_client_task.php +++ b/lib/kolab_client_task.php @@ -789,7 +789,6 @@ class kolab_client_task //console("\$field value for \$auto_fields[\$idx] (idx: $idx)", $auto_fields[$idx]); if (!is_array($field)) { //console("not an array... unsetting"); - unset($auto_fields[$idx]); continue; } @@ -803,7 +802,7 @@ class kolab_client_task } $field['name'] = $idx; - $fields[$idx] = $this->form_element_type($field, $data); + $fields[$idx] = $this->form_element_type($field, $data); $fields[$idx]['readonly'] = true; $extra_fields[$idx] = true; @@ -901,6 +900,7 @@ class kolab_client_task 'attributes' => $auto_attribs, 'object_type' => $name, )); + $resp = $this->api->post('form_value.generate', null, $data); $data = array_merge((array)$data, (array)$resp->get()); } @@ -1117,4 +1117,89 @@ 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-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])) { + 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 + $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'] . '>'; + } + } + } + + // 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; + } + } + } + } |