summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAleksander Machniak <machniak@kolabsys.com>2012-03-30 13:26:32 +0200
committerAleksander Machniak <machniak@kolabsys.com>2012-03-30 13:26:32 +0200
commit7906fe64d5b76d6abec033ade2d3e9fa56d9abd8 (patch)
tree9b0dbf6d00f497eb3726b79705394cdef12300c7
parentfe39a1887ffe4425b88613eeb384971f838103f3 (diff)
downloadwebadmin-7906fe64d5b76d6abec033ade2d3e9fa56d9abd8.tar.gz
Unified some methods: Use object_type_*() instead of separate user_type_*/group_type_*/<any>_type_*.
Unified some API calls arguments: Use object_name and type_id instead of user_type_id/group_type_id/<any>_type_id.
-rw-r--r--lib/api/kolab_api_service_form_value.php63
-rw-r--r--lib/api/kolab_api_service_group.php6
-rw-r--r--lib/api/kolab_api_service_group_types.php2
-rw-r--r--lib/api/kolab_api_service_user.php10
-rw-r--r--lib/api/kolab_api_service_user_types.php2
-rw-r--r--lib/client/kolab_client_task_group.php22
-rw-r--r--lib/client/kolab_client_task_user.php12
-rw-r--r--lib/kolab_api_service.php113
-rw-r--r--lib/kolab_client_task.php13
-rw-r--r--lib/locale/en_US.php4
-rw-r--r--public_html/js/kolab_admin.js5
11 files changed, 87 insertions, 165 deletions
diff --git a/lib/api/kolab_api_service_form_value.php b/lib/api/kolab_api_service_form_value.php
index 3f53d79..b006b84 100644
--- a/lib/api/kolab_api_service_form_value.php
+++ b/lib/api/kolab_api_service_form_value.php
@@ -52,22 +52,14 @@ class kolab_api_service_form_value extends kolab_api_service
* @param array $getdata GET parameters
* @param array $postdata POST parameters. Required parameters:
* - attributes: list of attribute names
- * - user_type_id or group_type_id: Type identifier
+ * - type_id: Type identifier
+ * - object_type: Object type (user, group, etc.)
*
* @return array Response with attribute name as a key
*/
public function generate($getdata, $postdata)
{
- if (isset($postdata['user_type_id'])) {
- $attribs = $this->user_type_attributes($postdata['user_type_id']);
- }
- else if (isset($postdata['group_type_id'])) {
- $attribs = $this->group_type_attributes($postdata['group_type_id']);
- }
- else {
- $attribs = array();
- }
-
+ $attribs = $this->object_type_attributes($postdata['object_type'], $postdata['type_id']);
$attributes = (array) $postdata['attributes'];
$result = array();
@@ -93,29 +85,18 @@ class kolab_api_service_form_value extends kolab_api_service
*
* @param array $getdata GET parameters
* @param array $postdata POST parameters. Required parameters:
- * - user_type_id or group_type_id: Type identifier
+ * - type_id: Type identifier
+ * - object_type: Object type (user, group, etc.)
*
* @return array Response with attribute name as a key
*/
public function validate($getdata, $postdata)
{
- if (isset($postdata['user_type_id'])) {
- $attribs = $this->user_type_attributes($postdata['user_type_id']);
- }
- else if (isset($postdata['group_type_id'])) {
- $attribs = $this->group_type_attributes($postdata['group_type_id']);
- }
- else {
- $attribs = array();
- }
-
- $result = array();
+ $attribs = $this->object_type_attributes($postdata['object_type'], $postdata['type_id']);
+ $result = array();
foreach ((array)$postdata as $attr_name => $attr_value) {
- if (empty($attr_name)) {
- continue;
- }
- if (preg_match('/^[a-z]+_type_id$/i', $attr_name)) {
+ if (empty($attr_name) || $attr_name == 'type_id' || $attr_name == 'object_type') {
continue;
}
@@ -138,22 +119,14 @@ class kolab_api_service_form_value extends kolab_api_service
* @param array $getdata GET parameters
* @param array $postdata POST parameters. Required parameters:
* - attributes: list of attribute names
- * - user_type_id or group_type_id: Type identifier
+ * - type_id: Type identifier
+ * - object_type: Object type (user, group, etc.)
*
* @return array Response with attribute name as a key
*/
public function select_options($getdata, $postdata)
{
- if (isset($postdata['user_type_id'])) {
- $attribs = $this->user_type_attributes($postdata['user_type_id']);
- }
- else if (isset($postdata['group_type_id'])) {
- $attribs = $this->group_type_attributes($postdata['group_type_id']);
- }
- else {
- $attribs = array();
- }
-
+ $attribs = $this->object_type_attributes($postdata['object_type'], $postdata['type_id']);
$attributes = (array) $postdata['attributes'];
$result = array();
@@ -181,22 +154,14 @@ class kolab_api_service_form_value extends kolab_api_service
* @param array $getdata GET parameters
* @param array $postdata POST parameters. Required parameters:
* - attribute: attribute name
- * - user_type_id or group_type_id: Type identifier
+ * - type_id: Type identifier
+ * - object_type: Object type (user, group, etc.)
*
* @return array Response with attribute name as a key
*/
public function list_options($getdata, $postdata)
{
- if (isset($postdata['user_type_id'])) {
- $attribs = $this->user_type_attributes($postdata['user_type_id']);
- }
- else if (isset($postdata['group_type_id'])) {
- $attribs = $this->group_type_attributes($postdata['group_type_id']);
- }
- else {
- $attribs = array();
- }
-
+ $attribs = $this->object_type_attributes($postdata['object_type'], $postdata['type_id']);
$attr_name = $postdata['attribute'];
$result = array(
// return search value, so client can match response to request
diff --git a/lib/api/kolab_api_service_group.php b/lib/api/kolab_api_service_group.php
index c1decaf..a527aa5 100644
--- a/lib/api/kolab_api_service_group.php
+++ b/lib/api/kolab_api_service_group.php
@@ -55,7 +55,7 @@ class kolab_api_service_group extends kolab_api_service
*/
public function group_add($getdata, $postdata)
{
- $gta = $this->group_type_attributes($postdata['group_type_id']);
+ $gta = $this->object_type_attributes('group', $postdata['type_id']);
$group_attributes = array();
if (isset($gta['form_fields'])) {
@@ -93,7 +93,7 @@ class kolab_api_service_group extends kolab_api_service
}
$auth = Auth::get_instance();
- $result = $auth->group_add($group_attributes, $postdata['group_type_id']);
+ $result = $auth->group_add($group_attributes, $postdata['type_id']);
if ($result) {
return $group_attributes;
@@ -150,7 +150,7 @@ class kolab_api_service_group extends kolab_api_service
$result['entrydn'] = $dn;
// add group type id to the result
- $result['group_type_id'] = $this->object_type_id('group', $result['objectclass']);
+ $result['type_id'] = $this->object_type_id('group', $result['objectclass']);
if ($result) {
return $result;
diff --git a/lib/api/kolab_api_service_group_types.php b/lib/api/kolab_api_service_group_types.php
index 7145654..e564c06 100644
--- a/lib/api/kolab_api_service_group_types.php
+++ b/lib/api/kolab_api_service_group_types.php
@@ -52,7 +52,7 @@ class kolab_api_service_group_types extends kolab_api_service
*/
public function group_types_list($get, $post)
{
- $group_types = $this->group_types();
+ $group_types = $this->object_types('group');
return array(
'list' => $group_types,
diff --git a/lib/api/kolab_api_service_user.php b/lib/api/kolab_api_service_user.php
index fea9f9d..855518f 100644
--- a/lib/api/kolab_api_service_user.php
+++ b/lib/api/kolab_api_service_user.php
@@ -59,7 +59,7 @@ class kolab_api_service_user extends kolab_api_service
*/
public function user_add($getdata, $postdata)
{
- $uta = $this->user_type_attributes($postdata['user_type_id']);
+ $uta = $this->object_type_attributes('user', $postdata['type_id']);
$form_service = $this->controller->get_service('form_value');
$user_attributes = array();
@@ -96,7 +96,7 @@ class kolab_api_service_user extends kolab_api_service
}
$auth = Auth::get_instance();
- $result = $auth->user_add($user_attributes, $postdata['user_type_id']);
+ $result = $auth->user_add($user_attributes, $postdata['type_id']);
if ($result) {
return $user_attributes;
@@ -154,12 +154,12 @@ class kolab_api_service_user extends kolab_api_service
$result['entrydn'] = $dn;
// add user type id to the result
- $result['user_type_id'] = $this->object_type_id('user', $result['objectclass']);
+ $result['type_id'] = $this->object_type_id('user', $result['objectclass']);
// Search for attributes associated with the type_id that are not part
// of the results returned earlier. Example: nsrole / nsroledn / aci, etc.
- if ($result['user_type_id']) {
- $uta = $this->user_type_attributes($result['user_type_id']);
+ if ($result['type_id']) {
+ $uta = $this->object_type_attributes('user', $result['type_id']);
$attrs = array();
foreach ($uta as $field_type => $attributes) {
diff --git a/lib/api/kolab_api_service_user_types.php b/lib/api/kolab_api_service_user_types.php
index b2adcf2..7a200ae 100644
--- a/lib/api/kolab_api_service_user_types.php
+++ b/lib/api/kolab_api_service_user_types.php
@@ -52,7 +52,7 @@ class kolab_api_service_user_types extends kolab_api_service
*/
public function user_types_list($get, $post)
{
- $user_types = $this->user_types();
+ $user_types = $this->object_types('user');
return array(
'list' => $user_types,
diff --git a/lib/client/kolab_client_task_group.php b/lib/client/kolab_client_task_group.php
index 9b57b99..ba213de 100644
--- a/lib/client/kolab_client_task_group.php
+++ b/lib/client/kolab_client_task_group.php
@@ -202,13 +202,13 @@ class kolab_client_task_group extends kolab_client_task
// field-to-section map and fields order
$fields_map = array(
- 'group_type_id' => 'system',
- 'group_type_id_name' => 'system',
- 'cn' => 'system',
- 'gidnumber' => 'system',
- 'mail' => 'system',
- 'uniquemember' => 'system',
- 'memberurl' => 'system',
+ 'type_id' => 'system',
+ 'type_id_name' => 'system',
+ 'cn' => 'system',
+ 'gidnumber' => 'system',
+ 'mail' => 'system',
+ 'uniquemember' => 'system',
+ 'memberurl' => 'system',
);
// Prepare fields
@@ -222,7 +222,7 @@ class kolab_client_task_group extends kolab_client_task
}
// Add user type id selector
- $fields['group_type_id'] = array(
+ $fields['type_id'] = array(
'section' => 'system',
'type' => kolab_form::INPUT_SELECT,
'options' => $accttypes,
@@ -231,7 +231,7 @@ class kolab_client_task_group extends kolab_client_task
// Hide account type selector if there's only one type
if (count($accttypes) < 2 || !$add_mode) {
- $fields['group_type_id']['type'] = kolab_form::INPUT_HIDDEN;
+ $fields['type_id']['type'] = kolab_form::INPUT_HIDDEN;
}
// Create mode
@@ -244,8 +244,8 @@ class kolab_client_task_group extends kolab_client_task
$title = $data['cn'];
// Add user type name
- $fields['group_type_id_name'] = array(
- 'label' => 'group.group_type_id',
+ $fields['type_id_name'] = array(
+ 'label' => 'group.type_id',
'section' => 'system',
'value' => $accttypes[$type]['content'],
);
diff --git a/lib/client/kolab_client_task_user.php b/lib/client/kolab_client_task_user.php
index 2daaead..f4c6d02 100644
--- a/lib/client/kolab_client_task_user.php
+++ b/lib/client/kolab_client_task_user.php
@@ -201,8 +201,8 @@ class kolab_client_task_user extends kolab_client_task
// field-to-section map and fields order
$fields_map = array(
- 'user_type_id' => 'personal',
- 'user_type_id_name' => 'personal',
+ 'type_id' => 'personal',
+ 'type_id_name' => 'personal',
'givenname' => 'personal',
'sn' => 'personal',
'displayname' => 'personal',
@@ -255,7 +255,7 @@ class kolab_client_task_user extends kolab_client_task
}
// Add user type id selector
- $fields['user_type_id'] = array(
+ $fields['type_id'] = array(
'section' => 'personal',
'type' => kolab_form::INPUT_SELECT,
'options' => $accttypes,
@@ -269,7 +269,7 @@ class kolab_client_task_user extends kolab_client_task
// Hide account type selector if there's only one type
if (count($accttypes) < 2 || !$add_mode) {
- $fields['user_type_id']['type'] = kolab_form::INPUT_HIDDEN;
+ $fields['type_id']['type'] = kolab_form::INPUT_HIDDEN;
}
// Create mode
@@ -288,8 +288,8 @@ class kolab_client_task_user extends kolab_client_task
$data['userpassword'] = '';
// Add user type name
- $fields['user_type_id_name'] = array(
- 'label' => 'user.user_type_id',
+ $fields['type_id_name'] = array(
+ 'label' => 'user.type_id',
'section' => 'personal',
'value' => $accttypes[$type]['content'],
);
diff --git a/lib/kolab_api_service.php b/lib/kolab_api_service.php
index 8c41e30..dfe69ea 100644
--- a/lib/kolab_api_service.php
+++ b/lib/kolab_api_service.php
@@ -51,55 +51,34 @@ abstract class kolab_api_service
/**
* Returns attributes of specified user type.
*
- * @param int $type_id User type identifier
- * @param bool $required Throws exception on empty ID
+ * @param string $object_name Name of the object (user, group, etc.)
+ * @param int $type_id User type identifier
+ * @param bool $required Throws exception on empty ID
*
* @return array User type attributes
*/
- protected function user_type_attributes($type_id, $required = true)
+ protected function object_type_attributes($object_name, $type_id, $required = true)
{
- if (empty($type_id)) {
- if ($required) {
- throw new Exception($this->controller->translate('user.notypeid'), 34);
- }
-
- return array();
+ $supported = array('group', 'user');
+ if (!in_array($object_name, $supported)) {
+
}
-
- $user_types = $this->user_types();
-
- if (empty($user_types[$type_id])) {
- throw new Exception($this->controller->translate('user.invalidtypeid'), 35);
- }
-
- return $user_types[$type_id]['attributes'];
- }
-
- /**
- * Returns attributes of specified group type.
- *
- * @param int $type_id Group type identifier
- * @param bool $required Throws exception on empty ID
- *
- * @return array Group type attributes
- */
- protected function group_type_attributes($type_id, $required = true)
- {
+
if (empty($type_id)) {
if ($required) {
- throw new Exception($this->controller->translate('group.notypeid'), 34);
+ throw new Exception($this->controller->translate($object_name . '.notypeid'), 34);
}
return array();
}
- $group_types = $this->group_types();
+ $object_types = $this->object_types($object_name);
- if (empty($group_types[$type_id])) {
- throw new Exception($this->controller->translate('group.invalidtypeid'), 35);
+ if (empty($object_types[$type_id])) {
+ throw new Exception($this->controller->translate($object_name . '.invalidtypeid'), 35);
}
- return $group_types[$type_id]['attributes'];
+ return $object_types[$type_id]['attributes'];
}
/**
@@ -116,14 +95,8 @@ abstract class kolab_api_service
return null;
}
- $method = $object_name . '_types';
-
- if (!method_exists($this, $method)) {
- return null;
- }
-
$object_class = array_map('strtolower', $object_class);
- $object_types = $this->$method();
+ $object_types = $this->object_types($object_name);
$type_score = -1;
$type_id = null;
@@ -160,66 +133,42 @@ abstract class kolab_api_service
}
/**
- * Returns user types definitions.
+ * Returns object types definitions.
+ *
+ * @param string $object_name Name of the object (user, group, etc.)
*
- * @return array User types.
+ * @return array Object types.
*/
- protected function user_types()
+ protected function object_types($object_name)
{
- if (!empty($this->cache['user_types'])) {
- return $this->cache['user_types'];
+ if (!empty($this->cache['object_types']) && !empty($this->cache['object_types'][$object_name])) {
+ return $this->cache['object_types'][$object_name];
}
- $sql_result = $this->db->query("SELECT * FROM user_types");
- $user_types = array();
-
- while ($row = $this->db->fetch_assoc($sql_result)) {
- $user_types[$row['id']] = array();
-
- foreach ($row as $key => $value) {
- if ($key != "id") {
- if ($key == "attributes") {
- $user_types[$row['id']][$key] = json_decode($value, true);
- }
- else {
- $user_types[$row['id']][$key] = $value;
- }
- }
- }
- }
-
- return $this->cache['user_types'] = $user_types;
- }
-
- /**
- * Returns group types definitions.
- *
- * @return array Group types.
- */
- protected function group_types()
- {
- if (!empty($this->cache['group_types'])) {
- return $this->cache['group_types'];
+ $supported = array('group', 'user');
+ if (!in_array($object_name, $supported)) {
+ return array();
}
- $sql_result = $this->db->query("SELECT * FROM group_types");
- $group_types = array();
+ $sql_result = $this->db->query("SELECT * FROM {$object_name}_types");
+ $object_types = array();
while ($row = $this->db->fetch_assoc($sql_result)) {
- $group_types[$row['id']] = array();
+ $object_types[$row['id']] = array();
foreach ($row as $key => $value) {
if ($key != "id") {
if ($key == "attributes") {
- $group_types[$row['id']][$key] = json_decode($value, true);
+ $object_types[$row['id']][$key] = json_decode($value, true);
}
else {
- $group_types[$row['id']][$key] = $value;
+ $object_types[$row['id']][$key] = $value;
}
}
}
}
- return $this->cache['group_types'] = $group_types;
+ return $this->cache['object_types'][$object_name] = $object_types;
}
+
}
diff --git a/lib/kolab_client_task.php b/lib/kolab_client_task.php
index 010e1ce..c6115e7 100644
--- a/lib/kolab_client_task.php
+++ b/lib/kolab_client_task.php
@@ -691,11 +691,11 @@ class kolab_client_task
$extra_fields = array_flip($extra_fields);
// Selected account type
- if (!empty($data[$name . '_type_id'])) {
- $type = $data[$name . '_type_id'];
+ if (!empty($data['type_id'])) {
+ $type = $data['type_id'];
}
else {
- $data[$name . '_type_id'] = $type = key($types);
+ $data['type_id'] = $type = key($types);
}
if ($type) {
@@ -815,6 +815,13 @@ class kolab_client_task
}
}
+ // Add object type hidden field
+ $fields['object_type'] = array(
+ 'section' => 'system',
+ 'type' => kolab_form::INPUT_HIDDEN,
+ 'value' => $name,
+ );
+
return array($fields, $types, $type);
}
diff --git a/lib/locale/en_US.php b/lib/locale/en_US.php
index 773810b..f156994 100644
--- a/lib/locale/en_US.php
+++ b/lib/locale/en_US.php
@@ -73,7 +73,7 @@ $LANG['user.quota'] = 'Quota';
$LANG['user.quota.desc'] = 'Leave blank for unlimited';
$LANG['user.fbinterval'] = 'Free-Busy interval';
$LANG['user.fbinterval.desc'] = 'Leave blank for default (60 days)';
-$LANG['user.user_type_id'] = 'Account type';
+$LANG['user.type_id'] = 'Account type';
$LANG['user.alias'] = 'Secondary Email Address(es)';
$LANG['user.mailalternateaddress'] = 'Secondary Email Address(es)';
$LANG['user.invitation-policy'] = 'Invitation policy';
@@ -102,7 +102,7 @@ $LANG['group.list'] = 'Groups List';
$LANG['group.list.records'] = '$1 to $2 of $3';
$LANG['group.cn'] = 'Common name';
$LANG['group.mail'] = 'Primary Email Address';
-$LANG['group.group_type_id'] = 'Group type';
+$LANG['group.type_id'] = 'Group type';
$LANG['group.add.success'] = 'Group created successfully.';
$LANG['group.delete.success'] = 'Group deleted successfully.';
$LANG['group.gidnumber'] = 'Primary group number';
diff --git a/public_html/js/kolab_admin.js b/public_html/js/kolab_admin.js
index dabf56c..d035b49 100644
--- a/public_html/js/kolab_admin.js
+++ b/public_html/js/kolab_admin.js
@@ -924,8 +924,9 @@ function kolab_admin()
{
var i, j, e, elem, name, elem_name,
form = $('#'+this.env.form_id),
- type_id = $('[name="user_type_id"]', form).val(),
- data = {user_type_id: type_id, attributes: []};
+ type_id = $('[name="type_id"]', form).val(),
+ object_type = $('[name="object_type"]', form).val(),
+ data = {type_id: type_id, object_type: object_type, attributes: []};
this.set_busy(true, 'loading');