2 commits - lib/api
Aleksander Machniak
machniak at kolabsys.com
Fri Apr 12 12:26:18 CEST 2013
lib/api/kolab_api_service_domain.php | 7 ----
lib/api/kolab_api_service_group.php | 46 +++++++++++++++++++++++++----
lib/api/kolab_api_service_resource.php | 51 ++++++++++++++++++++++++++-------
lib/api/kolab_api_service_role.php | 46 +++++++++++++++++++++++++----
lib/api/kolab_api_service_type.php | 7 +++-
lib/api/kolab_api_service_user.php | 43 +++++++++++++++++++++++++--
6 files changed, 167 insertions(+), 33 deletions(-)
New commits:
commit 5a9a69958ddf0428cf4a6c2333715e254e6a83d6
Author: Aleksander Machniak <alec at alec.pl>
Date: Fri Apr 12 12:25:41 2013 +0200
Implemented user.find, role.find, resource.find and group.find actions
diff --git a/lib/api/kolab_api_service_group.php b/lib/api/kolab_api_service_group.php
index 35c9739..c9406ac 100644
--- a/lib/api/kolab_api_service_group.php
+++ b/lib/api/kolab_api_service_group.php
@@ -57,6 +57,7 @@ class kolab_api_service_group extends kolab_api_service
if (in_array('read', $effective_rights['entryLevelRights'])) {
$rights['info'] = "r";
+ $rights['find'] = "r";
$rights['members_list'] = "r";
}
@@ -167,6 +168,43 @@ class kolab_api_service_group extends kolab_api_service
}
/**
+ * Find group and return its data.
+ * It is a combination of group.info and groups.list with search capabilities
+ * If the search returns only one record we'll return group data.
+ *
+ * @param array $get GET parameters
+ * @param array $post POST parameters
+ *
+ * @return array|bool Group attributes, False on error
+ */
+ public function group_find($get, $post)
+ {
+ $auth = Auth::get_instance();
+ $attributes = array('');
+ $params = array('page_size' => 2);
+ $search = $this->parse_list_search($post);
+
+ // find group(s)
+ $groups = $auth->list_groups(null, $attributes, $search, $params);
+
+ if (empty($groups) || empty($groups['list']) || $groups['count'] > 1) {
+ return false;
+ }
+
+ // get group data
+ $result = $auth->group_info(key($groups['list']));
+
+ // normalize result
+ $result = $this->parse_result_attributes('group', $result);
+
+ if ($result) {
+ return $result;
+ }
+
+ return false;
+ }
+
+ /**
* Group members listing.
*
* @param array $get GET parameters
diff --git a/lib/api/kolab_api_service_resource.php b/lib/api/kolab_api_service_resource.php
index 8474de2..29b2b33 100644
--- a/lib/api/kolab_api_service_resource.php
+++ b/lib/api/kolab_api_service_resource.php
@@ -57,6 +57,7 @@ class kolab_api_service_resource extends kolab_api_service
if (in_array('read', $effective_rights['entryLevelRights'])) {
$rights['info'] = "r";
+ $rights['find'] = "r";
}
$rights['effective_rights'] = "r";
@@ -174,4 +175,42 @@ class kolab_api_service_resource extends kolab_api_service
return false;
}
+
+ /**
+ * Find resource and return its data.
+ * It is a combination of resource.info and resources.list with search capabilities
+ * If the search returns only one record we'll return resource data.
+ *
+ * @param array $get GET parameters
+ * @param array $post POST parameters
+ *
+ * @return array|bool Resource attributes, False on error
+ */
+ public function resource_find($get, $post)
+ {
+ $auth = Auth::get_instance();
+ $attributes = array('');
+ $params = array('page_size' => 2);
+ $search = $this->parse_list_search($post);
+
+ // find resource(s)
+ $resources = $auth->list_resources(null, $attributes, $search, $params);
+
+ if (empty($resources) || empty($resources['list']) || $resources['count'] > 1) {
+ return false;
+ }
+
+ // get resource data
+ $result = $auth->resource_info(key($resources['list']));
+
+ // normalize result
+ $result = $this->parse_result_attributes('resource', $result);
+
+ if ($result) {
+ return $result;
+ }
+
+ return false;
+ }
+
}
diff --git a/lib/api/kolab_api_service_role.php b/lib/api/kolab_api_service_role.php
index fc15d0b..05808c7 100644
--- a/lib/api/kolab_api_service_role.php
+++ b/lib/api/kolab_api_service_role.php
@@ -57,6 +57,7 @@ class kolab_api_service_role extends kolab_api_service
if (in_array('read', $effective_rights['entryLevelRights'])) {
$rights['info'] = "r";
+ $rights['find'] = "r";
$rights['members_list'] = "r";
}
@@ -179,6 +180,43 @@ class kolab_api_service_role extends kolab_api_service
}
/**
+ * Find role and return its data.
+ * It is a combination of role.info and roles.list with search capabilities
+ * If the search returns only one record we'll return role data.
+ *
+ * @param array $get GET parameters
+ * @param array $post POST parameters
+ *
+ * @return array|bool Role attributes, False on error
+ */
+ public function role_find($get, $post)
+ {
+ $auth = Auth::get_instance();
+ $attributes = array('');
+ $params = array('page_size' => 2);
+ $search = $this->parse_list_search($post);
+
+ // find role(s)
+ $roles = $auth->list_roles(null, $attributes, $search, $params);
+
+ if (empty($roles) || empty($roles['list']) || $roles['count'] > 1) {
+ return false;
+ }
+
+ // get role data
+ $result = $auth->role_info(key($roles['list']));
+
+ // normalize result
+ $result = $this->parse_result_attributes('role', $result);
+
+ if ($result) {
+ return $result;
+ }
+
+ return false;
+ }
+
+ /**
* Group members listing.
*
* @param array $get GET parameters
diff --git a/lib/api/kolab_api_service_user.php b/lib/api/kolab_api_service_user.php
index a8b286d..ffe6637 100644
--- a/lib/api/kolab_api_service_user.php
+++ b/lib/api/kolab_api_service_user.php
@@ -61,6 +61,7 @@ class kolab_api_service_user extends kolab_api_service
if (in_array('read', $effective_rights['entryLevelRights'])) {
$rights['info'] = "r";
+ $rights['find'] = "r";
}
$rights['effective_rights'] = "r";
@@ -177,4 +178,42 @@ class kolab_api_service_user extends kolab_api_service
return false;
}
+
+ /**
+ * Find user and return his data.
+ * It is a combination of user.info and users.list with search capabilities
+ * If the search returns only one record we'll return user data.
+ *
+ * @param array $get GET parameters
+ * @param array $post POST parameters
+ *
+ * @return array|bool User attributes, False on error
+ */
+ public function user_find($get, $post)
+ {
+ $auth = Auth::get_instance();
+ $attributes = array('');
+ $params = array('page_size' => 2);
+ $search = $this->parse_list_search($post);
+
+ // find user(s)
+ $users = $auth->list_users(null, $attributes, $search, $params);
+
+ if (empty($users) || empty($users['list']) || $users['count'] > 1) {
+ return false;
+ }
+
+ // get user data
+ $result = $auth->user_info(key($users['list']));
+
+ // normalize result
+ $result = $this->parse_result_attributes('user', $result);
+
+ if ($result) {
+ return $result;
+ }
+
+ return false;
+ }
+
}
commit d1b909c124910576a6b22cca11ebd08344e10e3c
Author: Aleksander Machniak <alec at alec.pl>
Date: Fri Apr 12 10:26:48 2013 +0200
Remove not implemented find* capabilities, some code cleanup
diff --git a/lib/api/kolab_api_service_domain.php b/lib/api/kolab_api_service_domain.php
index 2d91358..0234832 100644
--- a/lib/api/kolab_api_service_domain.php
+++ b/lib/api/kolab_api_service_domain.php
@@ -48,8 +48,7 @@ class kolab_api_service_domain extends kolab_api_service
}
$effective_rights = $auth->list_rights($domain_base_dn);
-
- $rights = array();
+ $rights = array();
if (in_array('add', $effective_rights['entryLevelRights'])) {
$rights['add'] = "w";
@@ -64,10 +63,6 @@ class kolab_api_service_domain extends kolab_api_service
}
if (in_array('read', $effective_rights['entryLevelRights'])) {
- $rights['find'] = "r";
- $rights['find_by_any_attribute'] = "r";
- $rights['find_by_attribute'] = "r";
- $rights['find_by_attributes'] = "r";
$rights['info'] = "r";
}
diff --git a/lib/api/kolab_api_service_group.php b/lib/api/kolab_api_service_group.php
index 9357e74..35c9739 100644
--- a/lib/api/kolab_api_service_group.php
+++ b/lib/api/kolab_api_service_group.php
@@ -39,13 +39,9 @@ class kolab_api_service_group extends kolab_api_service
{
//console("kolab_api_service_group::capabilities");
- $auth = Auth::get_instance();
-
+ $auth = Auth::get_instance();
$effective_rights = $auth->list_rights('group');
-
- //console("effective_rights", $effective_rights);
-
- $rights = array();
+ $rights = array();
if (in_array('add', $effective_rights['entryLevelRights'])) {
$rights['add'] = "w";
diff --git a/lib/api/kolab_api_service_resource.php b/lib/api/kolab_api_service_resource.php
index 48b3a88..8474de2 100644
--- a/lib/api/kolab_api_service_resource.php
+++ b/lib/api/kolab_api_service_resource.php
@@ -39,13 +39,9 @@ class kolab_api_service_resource extends kolab_api_service
{
//console("kolab_api_service_group::capabilities");
- $auth = Auth::get_instance();
-
+ $auth = Auth::get_instance();
$effective_rights = $auth->list_rights('resource');
-
- //console("effective_rights", $effective_rights);
-
- $rights = array();
+ $rights = array();
if (in_array('add', $effective_rights['entryLevelRights'])) {
$rights['add'] = "w";
@@ -60,10 +56,6 @@ class kolab_api_service_resource extends kolab_api_service
}
if (in_array('read', $effective_rights['entryLevelRights'])) {
- $rights['find'] = "r";
- $rights['find_by_any_attribute'] = "r";
- $rights['find_by_attribute'] = "r";
- $rights['find_by_attributes'] = "r";
$rights['info'] = "r";
}
diff --git a/lib/api/kolab_api_service_role.php b/lib/api/kolab_api_service_role.php
index cf1e339..fc15d0b 100644
--- a/lib/api/kolab_api_service_role.php
+++ b/lib/api/kolab_api_service_role.php
@@ -39,13 +39,9 @@ class kolab_api_service_role extends kolab_api_service
{
//console("kolab_api_service_role::capabilities");
- $auth = Auth::get_instance();
-
+ $auth = Auth::get_instance();
$effective_rights = $auth->list_rights('role');
-
- //console("effective_rights", $effective_rights);
-
- $rights = array();
+ $rights = array();
if (in_array('add', $effective_rights['entryLevelRights'])) {
$rights['add'] = "w";
diff --git a/lib/api/kolab_api_service_type.php b/lib/api/kolab_api_service_type.php
index 0c47c89..9faeff1 100644
--- a/lib/api/kolab_api_service_type.php
+++ b/lib/api/kolab_api_service_type.php
@@ -43,14 +43,19 @@ class kolab_api_service_type extends kolab_api_service
if (in_array('add', (array)$effective_rights['entryLevelRights'])) {
$rights['add'] = "w";
}
+
if (in_array('delete', (array)$effective_rights['entryLevelRights'])) {
$rights['delete'] = "w";
}
+
if (in_array('modrdn', (array)$effective_rights['entryLevelRights'])) {
$rights['edit'] = "w";
}
- $rights['info'] = "r";
+ if (in_array('read', (array)$effective_rights['entryLevelRights'])) {
+ $rights['info'] = "r";
+ }
+
$rights['effective_rights'] = "r";
return $rights;
diff --git a/lib/api/kolab_api_service_user.php b/lib/api/kolab_api_service_user.php
index 578e102..a8b286d 100644
--- a/lib/api/kolab_api_service_user.php
+++ b/lib/api/kolab_api_service_user.php
@@ -60,10 +60,6 @@ class kolab_api_service_user extends kolab_api_service
}
if (in_array('read', $effective_rights['entryLevelRights'])) {
- $rights['find'] = "r";
- $rights['find_by_any_attribute'] = "r";
- $rights['find_by_attribute'] = "r";
- $rights['find_by_attributes'] = "r";
$rights['info'] = "r";
}
More information about the commits
mailing list