lib/api lib/client public_html/js

Jeroen van Meeuwen vanmeeuwen at kolabsys.com
Thu Apr 18 15:34:33 CEST 2013


 lib/api/kolab_api_service_domain.php          |   74 ++++++++++++++++----------
 lib/api/kolab_api_service_group.php           |   18 +++---
 lib/api/kolab_api_service_resource.php        |   10 +--
 lib/api/kolab_api_service_role.php            |   18 +++---
 lib/api/kolab_api_service_sharedfolder.php    |   10 +--
 lib/api/kolab_api_service_user.php            |   14 ++--
 lib/client/kolab_client_task_domain.php       |    2 
 lib/client/kolab_client_task_group.php        |    2 
 lib/client/kolab_client_task_resource.php     |    2 
 lib/client/kolab_client_task_role.php         |    2 
 lib/client/kolab_client_task_sharedfolder.php |    2 
 lib/client/kolab_client_task_user.php         |    2 
 public_html/js/kolab_admin.js                 |   26 ++++-----
 13 files changed, 100 insertions(+), 82 deletions(-)

New commits:
commit a5f265e17831b38d4a956feaefad909f9899d689
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date:   Thu Apr 18 15:33:38 2013 +0200

    Make the API parameters more consistent, and therefore easier to document

diff --git a/lib/api/kolab_api_service_domain.php b/lib/api/kolab_api_service_domain.php
index 0234832..e66cae3 100644
--- a/lib/api/kolab_api_service_domain.php
+++ b/lib/api/kolab_api_service_domain.php
@@ -81,7 +81,8 @@ class kolab_api_service_domain extends kolab_api_service
         }
 
         if (empty($postdata[$dna])) {
-            return;
+            Log::error("domain.add called without '" . $dna . "' specified");
+            return false;
         }
 
         $auth = Auth::get_instance($conf->get('kolab', 'primary_domain'));
@@ -94,24 +95,6 @@ class kolab_api_service_domain extends kolab_api_service
         }
     }
 
-    public function domain_edit($getdata, $postdata)
-    {
-        //console("domain_edit \$postdata", $postdata);
-
-        $domain_attributes  = $this->parse_input_attributes('domain', $postdata);
-        $domain             = $postdata['id'];
-
-        $auth   = Auth::get_instance();
-        $result = $auth->domain_edit($postdata['id'], $domain_attributes, $postdata['type_id']);
-
-        // @TODO: return unique attribute or all attributes as domain_add()
-        if ($result) {
-            return true;
-        }
-
-        return false;
-    }
-
     /**
      * Domain delete.
      *
@@ -122,13 +105,16 @@ class kolab_api_service_domain extends kolab_api_service
      */
     public function domain_delete($getdata, $postdata)
     {
-        if (empty($postdata['domain'])) {
+        Log::trace("domain.delete(\$getdata = '" . var_export($getdata, TRUE) . "', \$postdata = '" . var_export($postdata, TRUE) . "')");
+
+        if (empty($postdata['id'])) {
+            Log::error("domain.delete called without a Domain ID");
             return false;
         }
 
         // TODO: Input validation
         $auth   = Auth::get_instance();
-        $result = $auth->domain_delete($postdata['domain']);
+        $result = $auth->domain_delete($postdata['id']);
 
         if ($result) {
             return $result;
@@ -137,12 +123,43 @@ class kolab_api_service_domain extends kolab_api_service
         return false;
     }
 
+    public function domain_edit($getdata, $postdata)
+    {
+        Log::trace("domain.edit(\$getdata = '" . var_export($getdata, TRUE) . "', \$postdata = '" . var_export($postdata, TRUE) . "')");
+
+        if (empty($postdata['id'])) {
+            Log::error("domain.edit called without a Domain ID");
+            return false;
+        }
+
+        $domain_attributes  = $this->parse_input_attributes('domain', $postdata);
+        $domain             = $postdata['id'];
+
+        $auth   = Auth::get_instance();
+        $result = $auth->domain_edit($postdata['id'], $domain_attributes, $postdata['type_id']);
+
+        // @TODO: return unique attribute or all attributes as domain_add()
+        if ($result) {
+            return true;
+        }
+
+        return false;
+    }
+
     public function domain_effective_rights($getdata, $postdata)
     {
         $auth = Auth::get_instance();
 
-        if (!empty($getdata['domain'])) {
-            $entry_dn    = $getdata['domain'];
+        $conf = Conf::get_instance();
+        $dna = $conf->get('domain_name_attribute');
+
+        if (empty($dna)) {
+            $dna = 'associateddomain';
+        }
+
+        // TODO: Input validation
+        if (!empty($getdata[$dna])) {
+            $entry_dn    = $getdata[$dna];
             $unique_attr = $this->unique_attribute();
             $domain      = $auth->domain_find_by_attribute(array($unique_attr => $entry_dn));
 
@@ -172,22 +189,23 @@ class kolab_api_service_domain extends kolab_api_service
      */
     public function domain_info($getdata, $postdata)
     {
-        if (!isset($getdata['domain'])) {
+        Log::trace("domain.info(\$getdata = '" . var_export($getdata, TRUE) . "', \$postdata = '" . var_export($postdata, TRUE) . "')");
+
+        if (empty($getdata['id'])) {
+            Log::error("domain.info called without a Domain ID");
             return false;
         }
 
         $auth   = Auth::get_instance();
-        $result = $auth->domain_info($getdata['domain']);
+        $result = $auth->domain_info($getdata['id']);
 
         // normalize result
         $result = $this->parse_result_attributes('domain', $result);
 
         if (empty($result['id'])) {
-            $result['id'] = $getdata['domain'];
+            $result['id'] = $getdata[$dna];
         }
 
-        //console("API/domain.info() \$result:", $result);
-
         if ($result) {
             return $result;
         }
diff --git a/lib/api/kolab_api_service_group.php b/lib/api/kolab_api_service_group.php
index c9406ac..e7d7c2b 100644
--- a/lib/api/kolab_api_service_group.php
+++ b/lib/api/kolab_api_service_group.php
@@ -98,13 +98,13 @@ class kolab_api_service_group extends kolab_api_service
      */
     public function group_delete($getdata, $postdata)
     {
-        if (empty($postdata['group'])) {
+        if (empty($postdata['id'])) {
             return FALSE;
         }
 
         // TODO: Input validation
         $auth   = Auth::get_instance();
-        $result = $auth->group_delete($postdata['group']);
+        $result = $auth->group_delete($postdata['id']);
 
         if ($result) {
             return $result;
@@ -134,7 +134,7 @@ class kolab_api_service_group extends kolab_api_service
     public function group_effective_rights($getdata, $postdata)
     {
         $auth = Auth::get_instance();
-        $effective_rights = $auth->list_rights(empty($getdata['group']) ? 'group' : $getdata['group']);
+        $effective_rights = $auth->list_rights(empty($getdata['id']) ? 'group' : $getdata['id']);
         return $effective_rights;
     }
 
@@ -148,12 +148,12 @@ class kolab_api_service_group extends kolab_api_service
      */
     public function group_info($getdata, $postdata)
     {
-        if (empty($getdata['group'])) {
+        if (empty($getdata['id'])) {
             return false;
         }
 
         $auth   = Auth::get_instance();
-        $result = $auth->group_info($getdata['group']);
+        $result = $auth->group_info($getdata['id']);
 
         // normalize result
         $result = $this->parse_result_attributes('group', $result);
@@ -214,15 +214,15 @@ class kolab_api_service_group extends kolab_api_service
      */
     public function group_members_list($getdata, $postdata)
     {
-        Log::trace("group_members_list() for group " . $getdata['group']);
+        Log::trace("group_members_list() for group " . $getdata['id']);
         $auth = Auth::get_instance();
 
-        if (empty($getdata['group'])) {
-            //console("Empty \$getdata['group']");
+        if (empty($getdata['id'])) {
+            //console("Empty \$getdata['id']");
             return FALSE;
         }
 
-        $result = $auth->group_members_list($getdata['group'], false);
+        $result = $auth->group_members_list($getdata['id'], false);
 
         Log::trace("group_members_list() result: " . var_export($result, TRUE));
 
diff --git a/lib/api/kolab_api_service_resource.php b/lib/api/kolab_api_service_resource.php
index 29b2b33..b496bca 100644
--- a/lib/api/kolab_api_service_resource.php
+++ b/lib/api/kolab_api_service_resource.php
@@ -103,13 +103,13 @@ class kolab_api_service_resource extends kolab_api_service
     public function resource_delete($getdata, $postdata)
     {
         //console("resource_delete()", $getdata, $postdata);
-        if (!isset($postdata['resource'])) {
+        if (!isset($postdata['id'])) {
             return false;
         }
 
         // TODO: Input validation
         $auth   = Auth::get_instance();
-        $result = $auth->resource_delete($postdata['resource']);
+        $result = $auth->resource_delete($postdata['id']);
 
         if ($result) {
             return $result;
@@ -143,7 +143,7 @@ class kolab_api_service_resource extends kolab_api_service
     public function resource_effective_rights($getdata, $postdata)
     {
         $auth = Auth::get_instance();
-        $effective_rights = $auth->list_rights(empty($getdata['resource']) ? 'resource' : $getdata['resource']);
+        $effective_rights = $auth->list_rights(empty($getdata['id']) ? 'resource' : $getdata['id']);
         return $effective_rights;
     }
 
@@ -157,12 +157,12 @@ class kolab_api_service_resource extends kolab_api_service
      */
     public function resource_info($getdata, $postdata)
     {
-        if (!isset($getdata['resource'])) {
+        if (!isset($getdata['id'])) {
             return false;
         }
 
         $auth   = Auth::get_instance();
-        $result = $auth->resource_info($getdata['resource']);
+        $result = $auth->resource_info($getdata['id']);
 
         // normalize result
         $result = $this->parse_result_attributes('resource', $result);
diff --git a/lib/api/kolab_api_service_role.php b/lib/api/kolab_api_service_role.php
index 05808c7..c0e672a 100644
--- a/lib/api/kolab_api_service_role.php
+++ b/lib/api/kolab_api_service_role.php
@@ -98,13 +98,13 @@ class kolab_api_service_role extends kolab_api_service
      */
     public function role_delete($getdata, $postdata)
     {
-        if (empty($postdata['role'])) {
+        if (empty($postdata['id'])) {
             return FALSE;
         }
 
         // TODO: Input validation
         $auth   = Auth::get_instance();
-        $result = $auth->role_delete($postdata['role']);
+        $result = $auth->role_delete($postdata['id']);
 
         if ($result) {
             return $result;
@@ -136,9 +136,9 @@ class kolab_api_service_role extends kolab_api_service
         $auth = Auth::get_instance();
 
         // Roles are special in that they are ldapsubentries.
-        if (!empty($getdata['role'])) {
+        if (!empty($getdata['id'])) {
             $unique_attr = $this->unique_attribute();
-            $role        = $auth->role_find_by_attribute(Array($unique_attr => $getdata['role']));
+            $role        = $auth->role_find_by_attribute(Array($unique_attr => $getdata['id']));
 
             if (is_array($role) && count($role) == 1) {
                 $role_dn = key($role);
@@ -162,12 +162,12 @@ class kolab_api_service_role extends kolab_api_service
     {
         //console("api::role.info \$getdata, \$postdata", $getdata, $postdata);
 
-        if (empty($getdata['role'])) {
+        if (empty($getdata['id'])) {
             return false;
         }
 
         $auth   = Auth::get_instance();
-        $result = $auth->role_info($getdata['role']);
+        $result = $auth->role_info($getdata['id']);
 
         // normalize result
         $result = $this->parse_result_attributes('role', $result);
@@ -228,12 +228,12 @@ class kolab_api_service_role extends kolab_api_service
     {
         $auth = Auth::get_instance();
 
-        if (empty($getdata['role'])) {
-            //console("Empty \$getdata['role']");
+        if (empty($getdata['id'])) {
+            //console("Empty \$getdata['id']");
             return FALSE;
         }
 
-        $result = $auth->role_members_list($getdata['role'], false);
+        $result = $auth->role_members_list($getdata['id'], false);
 
         return array(
             'list'  => $result,
diff --git a/lib/api/kolab_api_service_sharedfolder.php b/lib/api/kolab_api_service_sharedfolder.php
index 3213536..55b060b 100644
--- a/lib/api/kolab_api_service_sharedfolder.php
+++ b/lib/api/kolab_api_service_sharedfolder.php
@@ -103,13 +103,13 @@ class kolab_api_service_sharedfolder extends kolab_api_service
     public function sharedfolder_delete($getdata, $postdata)
     {
         //console("sharedfolder_delete()", $getdata, $postdata);
-        if (!isset($postdata['sharedfolder'])) {
+        if (!isset($postdata['id'])) {
             return false;
         }
 
         // TODO: Input validation
         $auth   = Auth::get_instance();
-        $result = $auth->sharedfolder_delete($postdata['sharedfolder']);
+        $result = $auth->sharedfolder_delete($postdata['id']);
 
         if ($result) {
             return $result;
@@ -143,7 +143,7 @@ class kolab_api_service_sharedfolder extends kolab_api_service
     public function sharedfolder_effective_rights($getdata, $postdata)
     {
         $auth = Auth::get_instance();
-        $effective_rights = $auth->list_rights(empty($getdata['sharedfolder']) ? 'sharedfolder' : $getdata['sharedfolder']);
+        $effective_rights = $auth->list_rights(empty($getdata['id']) ? 'sharedfolder' : $getdata['id']);
         return $effective_rights;
     }
 
@@ -157,12 +157,12 @@ class kolab_api_service_sharedfolder extends kolab_api_service
      */
     public function sharedfolder_info($getdata, $postdata)
     {
-        if (!isset($getdata['sharedfolder'])) {
+        if (!isset($getdata['id'])) {
             return false;
         }
 
         $auth   = Auth::get_instance();
-        $result = $auth->sharedfolder_info($getdata['sharedfolder']);
+        $result = $auth->sharedfolder_info($getdata['id']);
 
         // normalize result
         $result = $this->parse_result_attributes('sharedfolder', $result);
diff --git a/lib/api/kolab_api_service_user.php b/lib/api/kolab_api_service_user.php
index ffe6637..9e4cdde 100644
--- a/lib/api/kolab_api_service_user.php
+++ b/lib/api/kolab_api_service_user.php
@@ -106,13 +106,13 @@ class kolab_api_service_user extends kolab_api_service
     public function user_delete($getdata, $postdata)
     {
         //console("user_delete()", $getdata, $postdata);
-        if (!isset($postdata['user'])) {
+        if (!isset($postdata['id'])) {
             return false;
         }
 
         // TODO: Input validation
         $auth   = Auth::get_instance();
-        $result = $auth->user_delete($postdata['user']);
+        $result = $auth->user_delete($postdata['id']);
 
         if ($result) {
             return $result;
@@ -145,7 +145,7 @@ class kolab_api_service_user extends kolab_api_service
     public function user_effective_rights($getdata, $postdata)
     {
         $auth = Auth::get_instance();
-        $effective_rights = $auth->list_rights(empty($getdata['user']) ? 'user' : $getdata['user']);
+        $effective_rights = $auth->list_rights(empty($getdata['id']) ? 'user' : $getdata['id']);
         return $effective_rights;
     }
 
@@ -159,18 +159,18 @@ class kolab_api_service_user extends kolab_api_service
      */
     public function user_info($getdata, $postdata)
     {
-        if (!isset($getdata['user'])) {
+        if (!isset($getdata['id'])) {
             return false;
         }
 
         $auth   = Auth::get_instance();
-        $result = $auth->user_info($getdata['user']);
+        $result = $auth->user_info($getdata['id']);
 
-        Log::trace("user.info on " . $getdata['user'] . " result: " . var_export($result, TRUE));
+        Log::trace("user.info on " . $getdata['id'] . " result: " . var_export($result, TRUE));
         // normalize result
         $result = $this->parse_result_attributes('user', $result);
 
-        Log::trace("user.info on " . $getdata['user'] . " parsed result: " . var_export($result, TRUE));
+        Log::trace("user.info on " . $getdata['id'] . " parsed result: " . var_export($result, TRUE));
 
         if ($result) {
             return $result;
diff --git a/lib/client/kolab_client_task_domain.php b/lib/client/kolab_client_task_domain.php
index 25dc711..9cf1e14 100644
--- a/lib/client/kolab_client_task_domain.php
+++ b/lib/client/kolab_client_task_domain.php
@@ -189,7 +189,7 @@ class kolab_client_task_domain extends kolab_client_task
         $id     = $this->get_input('id', 'POST');
         //console("action_info() on", $id);
 
-        $result = $this->api_get('domain.info', array('domain' => $id));
+        $result = $this->api_get('domain.info', array('id' => $id));
         //console("action_info() \$result", $result);
 
         $domain  = $result->get();
diff --git a/lib/client/kolab_client_task_group.php b/lib/client/kolab_client_task_group.php
index 81c1fe4..2367efa 100644
--- a/lib/client/kolab_client_task_group.php
+++ b/lib/client/kolab_client_task_group.php
@@ -179,7 +179,7 @@ class kolab_client_task_group extends kolab_client_task
     public function action_info()
     {
         $id     = $this->get_input('id', 'POST');
-        $result = $this->api_get('group.info', array('group' => $id));
+        $result = $this->api_get('group.info', array('id' => $id));
         $group  = $result->get();
         $output = $this->group_form(null, $group);
 
diff --git a/lib/client/kolab_client_task_resource.php b/lib/client/kolab_client_task_resource.php
index 15caf6f..94be4c1 100644
--- a/lib/client/kolab_client_task_resource.php
+++ b/lib/client/kolab_client_task_resource.php
@@ -192,7 +192,7 @@ class kolab_client_task_resource extends kolab_client_task
     public function action_info()
     {
         $id         = $this->get_input('id', 'POST');
-        $result     = $this->api_get('resource.info', array('resource' => $id));
+        $result     = $this->api_get('resource.info', array('id' => $id));
         $resource   = $result->get();
 
         //console("action_info()", $resource);
diff --git a/lib/client/kolab_client_task_role.php b/lib/client/kolab_client_task_role.php
index bae4585..46772a8 100644
--- a/lib/client/kolab_client_task_role.php
+++ b/lib/client/kolab_client_task_role.php
@@ -179,7 +179,7 @@ class kolab_client_task_role extends kolab_client_task
     public function action_info()
     {
         $id     = $this->get_input('id', 'POST');
-        $result = $this->api_get('role.info', array('role' => $id));
+        $result = $this->api_get('role.info', array('id' => $id));
         $role  = $result->get();
         $output = $this->role_form(null, $role);
 
diff --git a/lib/client/kolab_client_task_sharedfolder.php b/lib/client/kolab_client_task_sharedfolder.php
index cf55602..b277410 100644
--- a/lib/client/kolab_client_task_sharedfolder.php
+++ b/lib/client/kolab_client_task_sharedfolder.php
@@ -192,7 +192,7 @@ class kolab_client_task_sharedfolder extends kolab_client_task
     public function action_info()
     {
         $id             = $this->get_input('id', 'POST');
-        $result         = $this->api_get('sharedfolder.info', array('sharedfolder' => $id));
+        $result         = $this->api_get('sharedfolder.info', array('id' => $id));
         $sharedfolder   = $result->get();
 
         //console("action_info()", $sharedfolder);
diff --git a/lib/client/kolab_client_task_user.php b/lib/client/kolab_client_task_user.php
index 85b58e7..d9a2227 100644
--- a/lib/client/kolab_client_task_user.php
+++ b/lib/client/kolab_client_task_user.php
@@ -179,7 +179,7 @@ class kolab_client_task_user extends kolab_client_task
     public function action_info()
     {
         $id     = $this->get_input('id', 'POST');
-        $result = $this->api_get('user.info', array('user' => $id));
+        $result = $this->api_get('user.info', array('id' => $id));
         $user   = $result->get();
         $output = $this->user_form(null, $user);
 
diff --git a/public_html/js/kolab_admin.js b/public_html/js/kolab_admin.js
index b448530..0f93fcf 100644
--- a/public_html/js/kolab_admin.js
+++ b/public_html/js/kolab_admin.js
@@ -1373,10 +1373,10 @@ function kolab_admin()
     this.list_handler('domain', props);
   };
 
-  this.domain_delete = function(domainid)
+  this.domain_delete = function(id)
   {
     this.set_busy(true, 'deleting');
-    this.api_post('domain.delete', {domain: domainid}, 'domain_delete_response');
+    this.api_post('domain.delete', {'id': id}, 'domain_delete_response');
   };
 
   this.domain_save = function(reload, section)
@@ -1418,7 +1418,7 @@ function kolab_admin()
 
   this.user_info = function(id)
   {
-    this.http_post('user.info', {id: id});
+    this.http_post('user.info', {'id': id});
   };
 
   this.user_list = function(props)
@@ -1426,10 +1426,10 @@ function kolab_admin()
     this.list_handler('user', props);
   };
 
-  this.user_delete = function(userid)
+  this.user_delete = function(id)
   {
     this.set_busy(true, 'deleting');
-    this.api_post('user.delete', {user: userid}, 'user_delete_response');
+    this.api_post('user.delete', {'id': id}, 'user_delete_response');
   };
 
   this.user_save = function(reload, section)
@@ -1487,10 +1487,10 @@ function kolab_admin()
     this.list_handler('group', props);
   };
 
-  this.group_delete = function(groupid)
+  this.group_delete = function(id)
   {
     this.set_busy(true, 'deleting');
-    this.api_post('group.delete', {group: groupid}, 'group_delete_response');
+    this.api_post('group.delete', {'id': id}, 'group_delete_response');
   };
 
   this.group_save = function(reload, section)
@@ -1540,10 +1540,10 @@ function kolab_admin()
     this.list_handler('resource', props);
   };
 
-  this.resource_delete = function(resourceid)
+  this.resource_delete = function(id)
   {
     this.set_busy(true, 'deleting');
-    this.api_post('resource.delete', {resource: resourceid}, 'resource_delete_response');
+    this.api_post('resource.delete', {'id': id}, 'resource_delete_response');
   };
 
   this.resource_save = function(reload, section)
@@ -1593,10 +1593,10 @@ function kolab_admin()
     this.list_handler('role', props);
   };
 
-  this.role_delete = function(roleid)
+  this.role_delete = function(id)
   {
     this.set_busy(true, 'deleting');
-    this.api_post('role.delete', {role: roleid}, 'role_delete_response');
+    this.api_post('role.delete', {'id': id}, 'role_delete_response');
   };
 
   this.role_save = function(reload, section)
@@ -1646,10 +1646,10 @@ function kolab_admin()
     this.list_handler('sharedfolder', props);
   };
 
-  this.sharedfolder_delete = function(sharedfolderid)
+  this.sharedfolder_delete = function(id)
   {
     this.set_busy(true, 'deleting');
-    this.api_post('sharedfolder.delete', {sharedfolder: sharedfolderid}, 'sharedfolder_delete_response');
+    this.api_post('sharedfolder.delete', {'id': id}, 'sharedfolder_delete_response');
   };
 
   this.sharedfolder_save = function(reload, section)





More information about the commits mailing list