summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAleksander Machniak <machniak@kolabsys.com>2012-04-09 17:58:25 +0200
committerAleksander Machniak <machniak@kolabsys.com>2012-04-09 17:58:25 +0200
commit0ff0e866114ef705b11e5dc196eba859f9a0dc37 (patch)
treef28e812ee8cedc26085570ab3f6682a0b81414f8
parentc60c67c360d441bc40ca2017c1d0358301b0e10e (diff)
downloadwebadmin-0ff0e866114ef705b11e5dc196eba859f9a0dc37.tar.gz
Move list options convertion to user-friendly values to the API
Fixed role attribute list "resolving"
-rw-r--r--lib/api/kolab_api_service_form_value.php102
-rw-r--r--lib/api/kolab_api_service_roles.php2
-rw-r--r--lib/client/kolab_client_task_group.php3
-rw-r--r--lib/client/kolab_client_task_user.php3
-rw-r--r--lib/kolab_client_task.php123
5 files changed, 98 insertions, 135 deletions
diff --git a/lib/api/kolab_api_service_form_value.php b/lib/api/kolab_api_service_form_value.php
index 63c04d7..614bd18 100644
--- a/lib/api/kolab_api_service_form_value.php
+++ b/lib/api/kolab_api_service_form_value.php
@@ -516,21 +516,31 @@ class kolab_api_service_form_value extends kolab_api_service
private function list_options_kolabdelegate($postdata, $attribs = array())
{
- $service = $this->controller->get_service('users');
-
- $keyword = array('value' => $postdata['search']);
- $data = array(
- 'attributes' => array('displayname', 'mail'),
- 'page_size' => 15,
- 'search' => array(
+ // return specified records only, by exact DN attributes
+ if (!empty($postdata['list'])) {
+ $data['search'] = array(
+ 'entrydn' => array(
+ 'value' => $postdata['list'],
+ 'type' => 'exact',
+ ),
+ );
+ }
+ // return records with specified string
+ else {
+ $keyword = array('value' => $postdata['search']);
+ $data['page_size'] = 15;
+ $data['search'] = array(
'displayname' => $keyword,
'cn' => $keyword,
'mail' => $keyword,
- ),
- );
+ );
+ }
+
+ $data['attributes'] = array('displayname', 'mail');
- $result = $service->users_list(null, $data);
- $list = $result['list'];
+ $service = $this->controller->get_service('users');
+ $result = $service->users_list(null, $data);
+ $list = $result['list'];
// convert to key=>value array
foreach ($list as $idx => $value) {
@@ -556,21 +566,31 @@ class kolab_api_service_form_value extends kolab_api_service
private function list_options_nsroledn($postdata, $attribs = Array())
{
- $service = $this->controller->get_service('roles');
-
- $keyword = array('value' => $postdata['search']);
- $data = array(
- 'attributes' => array('cn'),
- 'page_size' => 15,
- 'search' => array(
+ // return specified records only, by exact DN attributes
+ if (!empty($postdata['list'])) {
+ $data['search'] = array(
+ 'entrydn' => array(
+ 'value' => $postdata['list'],
+ 'type' => 'exact',
+ ),
+ );
+ }
+ // return records with specified string
+ else {
+ $keyword = array('value' => $postdata['search']);
+ $data['page_size'] = 15;
+ $data['search'] = array(
'displayname' => $keyword,
'cn' => $keyword,
'mail' => $keyword,
- ),
- );
+ );
+ }
- $result = $service->roles_list(null, $data);
- $list = $result['list'];
+ $data['attributes'] = array('cn');
+
+ $service = $this->controller->get_service('roles');
+ $result = $service->roles_list(null, $data);
+ $list = $result['list'];
// convert to key=>value array
foreach ($list as $idx => $value) {
@@ -671,27 +691,37 @@ class kolab_api_service_form_value extends kolab_api_service
private function _list_options_members($postdata, $attribs = array())
{
- $service = $this->controller->get_service('users');
-
- $keyword = array('value' => $postdata['search']);
- $data = array(
- 'attributes' => array('displayname', 'cn', 'mail'),
- 'page_size' => 15,
- 'search' => array(
+ // return specified records only, by exact DN attributes
+ if (!empty($postdata['list'])) {
+ $data['search'] = array(
+ 'entrydn' => array(
+ 'value' => $postdata['list'],
+ 'type' => 'exact',
+ ),
+ );
+ }
+ // return records with specified string
+ else {
+ $keyword = array('value' => $postdata['search']);
+ $data['page_size'] = 15;
+ $data['search'] = array(
'displayname' => $keyword,
'cn' => $keyword,
'mail' => $keyword,
- ),
- );
+ );
+ }
- $result = $service->users_list(null, $data);
- $list = $result['list'];
+ $data['attributes'] = array('displayname', 'cn', 'mail');
+
+ $service = $this->controller->get_service('users');
+ $result = $service->users_list(null, $data);
+ $list = $result['list'];
- $service = $this->controller->get_service('groups');
$data['attributes'] = array('cn', 'mail');
- $result = $service->groups_list(null, $data);
- $list = array_merge($list, $result['list']);
+ $service = $this->controller->get_service('groups');
+ $result = $service->groups_list(null, $data);
+ $list = array_merge($list, $result['list']);
// convert to key=>value array
foreach ($list as $idx => $value) {
diff --git a/lib/api/kolab_api_service_roles.php b/lib/api/kolab_api_service_roles.php
index 1c9b8aa..7f67ab3 100644
--- a/lib/api/kolab_api_service_roles.php
+++ b/lib/api/kolab_api_service_roles.php
@@ -31,7 +31,7 @@ class kolab_api_service_roles extends kolab_api_service
public $list_attribs = array(
'cn',
'objectclass',
- 'dn',
+ 'entrydn',
'description',
);
diff --git a/lib/client/kolab_client_task_group.php b/lib/client/kolab_client_task_group.php
index d257129..402fabe 100644
--- a/lib/client/kolab_client_task_group.php
+++ b/lib/client/kolab_client_task_group.php
@@ -252,9 +252,6 @@ class kolab_client_task_group extends kolab_client_task
);
}
- // 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 34ca6c2..e390868 100644
--- a/lib/client/kolab_client_task_user.php
+++ b/lib/client/kolab_client_task_user.php
@@ -313,9 +313,6 @@ class kolab_client_task_user extends kolab_client_task
);
}
- // 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 a4cd924..53422e4 100644
--- a/lib/kolab_client_task.php
+++ b/lib/kolab_client_task.php
@@ -944,18 +944,41 @@ class kolab_client_task
// Add object type hidden field
$fields['object_type'] = array(
- 'section' => 'system',
- 'type' => kolab_form::INPUT_HIDDEN,
- 'value' => $name,
- );
+ 'section' => 'system',
+ 'type' => kolab_form::INPUT_HIDDEN,
+ 'value' => $name,
+ );
+
+ // Get user-friendly names for lists
+ foreach ($fields as $fname => $field) {
+ if (!empty($field['data-autocomplete']) && !empty($data[$fname])) {
+ if (!is_array($data[$fname])) {
+ $data[$fname] = (array) $data[$fname];
+ }
+
+ // request parameters
+ $post = array(
+ 'list' => $data[$fname],
+ 'attribute' => $fname,
+ 'object_type' => $name,
+ 'type_id' => $data['type_id'],
+ );
+
+ // get options list
+ $result = $this->api->post('form_value.list_options', null, $post);
+ $result = $result->get('list');
+
+ $data[$fname] = $result;
+ }
+ }
// Add entry identifier
if (!$add_mode) {
$fields['id'] = array(
- 'section' => 'system',
- 'type' => kolab_form::INPUT_HIDDEN,
- 'value' => $data['id']
- );
+ 'section' => 'system',
+ 'type' => kolab_form::INPUT_HIDDEN,
+ 'value' => $data['id']
+ );
}
return array($fields, $types, $type);
@@ -1117,89 +1140,5 @@ 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;
- }
- }
- }
}