4 commits - lib/api lib/kolab_api_controller.php lib/kolab_api_service.php

Aleksander Machniak machniak at kolabsys.com
Fri Sep 21 15:33:30 CEST 2012


 lib/api/kolab_api_service_domain_types.php |   86 ++++++++++++++
 lib/api/kolab_api_service_group.php        |    2 
 lib/api/kolab_api_service_type.php         |  174 +++++++++++++++++++++++++++++
 lib/kolab_api_controller.php               |    2 
 lib/kolab_api_service.php                  |    2 
 5 files changed, 265 insertions(+), 1 deletion(-)

New commits:
commit f6e00b0283c4eea26c6a0e3f2ab405a42e646074
Author: Aleksander Machniak <alec at alec.pl>
Date:   Fri Sep 21 15:23:29 2012 +0200

    Add 'type' service skeleton

diff --git a/lib/api/kolab_api_service_type.php b/lib/api/kolab_api_service_type.php
new file mode 100644
index 0000000..54d1464
--- /dev/null
+++ b/lib/api/kolab_api_service_type.php
@@ -0,0 +1,174 @@
+<?php
+/*
+ +--------------------------------------------------------------------------+
+ | This file is part of the Kolab Web Admin Panel                           |
+ |                                                                          |
+ | Copyright (C) 2011-2012, Kolab Systems AG                                |
+ |                                                                          |
+ | This program is free software: you can redistribute it and/or modify     |
+ | it under the terms of the GNU Affero General Public License as published |
+ | by the Free Software Foundation, either version 3 of the License, or     |
+ | (at your option) any later version.                                      |
+ |                                                                          |
+ | This program is distributed in the hope that it will be useful,          |
+ | but WITHOUT ANY WARRANTY; without even the implied warranty of           |
+ | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the             |
+ | GNU Affero General Public License for more details.                      |
+ |                                                                          |
+ | You should have received a copy of the GNU Affero General Public License |
+ | along with this program. If not, see <http://www.gnu.org/licenses/>      |
+ +--------------------------------------------------------------------------+
+ | Author: Aleksander Machniak <machniak at kolabsys.com>                      |
+ | Author: Jeroen van Meeuwen <vanmeeuwen at kolabsys.com>                     |
+ +--------------------------------------------------------------------------+
+*/
+
+/**
+ * Service providing user data management
+ */
+class kolab_api_service_type extends kolab_api_service
+{
+    /**
+     * Returns service capabilities.
+     *
+     * @param string $domain Domain name
+     *
+     * @return array Capabilities list
+     */
+    public function capabilities($domain)
+    {
+        $auth = Auth::get_instance();
+
+        //$effective_rights = $auth->list_rights('user');
+
+        $rights = array();
+
+        // @TODO: set rights according to user group or sth
+        if ($_SESSION['user']->get_userid() == 'cn=Directory Manager') {
+            $rights['add'] = "w";
+            $rights['delete'] = "w";
+            $rights['edit'] = "w";
+        }
+
+        $rights['effective_rights'] = "r";
+
+        return $rights;
+    }
+
+    /**
+     * Create user.
+     *
+     * @param array $get   GET parameters
+     * @param array $post  POST parameters
+     *
+     * @return array|bool User attributes or False on error.
+     */
+    public function type_add($getdata, $postdata)
+    {
+        //console("type_add()", $postdata);
+
+        $type_attributes = $this->parse_input_attributes('type', $postdata);
+
+        //console("type_add()", $type_attributes);
+
+//        $auth   = Auth::get_instance();
+//        $result = $auth->type_add($type_attributes, $postdata['type_id']);
+
+        if ($result) {
+            return $type_attributes;
+        }
+
+        return false;
+    }
+
+    /**
+     * Detete type.
+     *
+     * @param array $get  GET parameters
+     * @param array $post POST parameters
+     *
+     * @return bool True on success, False on failure
+     */
+    public function type_delete($getdata, $postdata)
+    {
+        //console("type_delete()", $getdata, $postdata);
+        if (!isset($postdata['type'])) {
+            return false;
+        }
+
+        // TODO: Input validation
+//        $auth   = Auth::get_instance();
+//        $result = $auth->type_delete($postdata['type']);
+
+        if ($result) {
+            return $result;
+        }
+
+        return false;
+    }
+
+    /**
+     * Update type.
+     *
+     * @param array $get  GET parameters
+     * @param array $post POST parameters
+     *
+     * @return bool True on success, False on failure
+     */
+    public function type_edit($getdata, $postdata)
+    {
+        //console("\$postdata to type_edit()", $postdata);
+
+        $type_attributes = $this->parse_input_attributes('type', $postdata);
+        $type            = $postdata['id'];
+
+//        $auth   = Auth::get_instance();
+//        $result = $auth->type_edit($type, $type_attributes, $postdata['type_id']);
+
+        // Return the $mod_array
+        if ($result) {
+            return $result;
+        }
+
+        return false;
+
+    }
+
+    public function type_effective_rights($getdata, $postdata)
+    {
+//        $auth = Auth::get_instance();
+//        $effective_rights = $auth->list_rights(empty($getdata['user']) ? 'user' : $getdata['user']);
+//        return $effective_rights;
+        return array();
+    }
+
+    /**
+     * User information.
+     *
+     * @param array $get  GET parameters
+     * @param array $post POST parameters
+     *
+     * @return array|bool User attributes, False on error
+     */
+    public function type_info($getdata, $postdata)
+    {
+        if (!isset($getdata['type'])) {
+            return false;
+        }
+
+//        $auth   = Auth::get_instance();
+//        $result = $auth->type_info($getdata['type']);
+
+//        Log::trace("type.info on " . $getdata['type'] . " result: " . var_export($result, TRUE));
+        // normalize result
+//        $result = $this->parse_result_attributes('type', $result);
+
+//        Log::trace("type.info on " . $getdata['type'] . " parsed result: " . var_export($result, TRUE));
+
+        if ($result) {
+            return $result;
+        }
+
+        return false;
+    }
+}
diff --git a/lib/kolab_api_controller.php b/lib/kolab_api_controller.php
index 3cfa54f..8e9fc30 100644
--- a/lib/kolab_api_controller.php
+++ b/lib/kolab_api_controller.php
@@ -57,6 +57,7 @@ class kolab_api_controller
 
         // TODO: register services based on config or whatsoever
         $this->add_service('domain',            'kolab_api_service_domain');
+        $this->add_service('domain_types',      'kolab_api_service_domain_types');
         $this->add_service('domains',           'kolab_api_service_domains');
         $this->add_service('form_value',        'kolab_api_service_form_value');
         $this->add_service('group_types',       'kolab_api_service_group_types');
@@ -68,6 +69,7 @@ class kolab_api_controller
         $this->add_service('roles',             'kolab_api_service_roles');
         $this->add_service('role',              'kolab_api_service_role');
         $this->add_service('role_types',        'kolab_api_service_role_types');
+        $this->add_service('type',              'kolab_api_service_type');
         $this->add_service('user_types',        'kolab_api_service_user_types');
         $this->add_service('user',              'kolab_api_service_user');
         $this->add_service('users',             'kolab_api_service_users');


commit 717b927bdacbed0a5eb8008fad8a6ad27a973812
Author: Aleksander Machniak <alec at alec.pl>
Date:   Fri Sep 21 15:01:55 2012 +0200

    Sort object types list by name

diff --git a/lib/kolab_api_service.php b/lib/kolab_api_service.php
index ad5c051..3fcefda 100644
--- a/lib/kolab_api_service.php
+++ b/lib/kolab_api_service.php
@@ -201,7 +201,7 @@ abstract class kolab_api_service
             $unique_attr = 'nsuniqueid';
         }
 
-        $sql_result   = $this->db->query("SELECT * FROM {$object_name}_types");
+        $sql_result   = $this->db->query("SELECT * FROM {$object_name}_types ORDER BY name");
         $object_types = array();
 
         while ($row = $this->db->fetch_assoc($sql_result)) {


commit 64d056ad9cc59502cc8c5b943cc63e0c68b52fe9
Author: Aleksander Machniak <alec at alec.pl>
Date:   Fri Sep 21 14:10:57 2012 +0200

    Create domain_types service, @TODO: move types array into database

diff --git a/lib/api/kolab_api_service_domain_types.php b/lib/api/kolab_api_service_domain_types.php
new file mode 100644
index 0000000..a84cf82
--- /dev/null
+++ b/lib/api/kolab_api_service_domain_types.php
@@ -0,0 +1,86 @@
+<?php
+/*
+ +--------------------------------------------------------------------------+
+ | This file is part of the Kolab Web Admin Panel                           |
+ |                                                                          |
+ | Copyright (C) 2011-2012, Kolab Systems AG                                |
+ |                                                                          |
+ | This program is free software: you can redistribute it and/or modify     |
+ | it under the terms of the GNU Affero General Public License as published |
+ | by the Free Software Foundation, either version 3 of the License, or     |
+ | (at your option) any later version.                                      |
+ |                                                                          |
+ | This program is distributed in the hope that it will be useful,          |
+ | but WITHOUT ANY WARRANTY; without even the implied warranty of           |
+ | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the             |
+ | GNU Affero General Public License for more details.                      |
+ |                                                                          |
+ | You should have received a copy of the GNU Affero General Public License |
+ | along with this program. If not, see <http://www.gnu.org/licenses/>      |
+ +--------------------------------------------------------------------------+
+ | Author: Aleksander Machniak <machniak at kolabsys.com>                      |
+ | Author: Jeroen van Meeuwen <vanmeeuwen at kolabsys.com>                     |
+ +--------------------------------------------------------------------------+
+*/
+
+/**
+ *
+ */
+class kolab_api_service_domain_types extends kolab_api_service
+{
+    /**
+     * Returns service capabilities.
+     *
+     * @param string $domain Domain name
+     *
+     * @return array Capabilities list
+     */
+    public function capabilities($domain)
+    {
+        return array(
+            'list' => 'r',
+        );
+    }
+
+    /**
+     * Domain types listing.
+     *
+     * @param array $get  GET parameters
+     * @param array $post POST parameters
+     *
+     * @return array List result with 'list' and 'count' items
+     */
+    public function domain_types_list($get, $post)
+    {
+        // @TODO: move to database
+        $types = array(
+            1 => array(
+                'key' => 'standard',
+                'name' => 'Standard domain',
+                'description' => 'A standard domain name space',
+                'attributes' => array(
+                    'auto_form_fields' => array(),
+                    'form_fields' => array(
+                        'associateddomain' => array(
+                            'type' => 'list',
+                        ),
+                        'inetdomainbasedn' => array(
+                            'optional' => 'true',
+                        ),
+                    ),
+                    'fields' => array(
+                        'objectclass' => array(
+                            'top',
+                            'domainrelatedobject',
+                        ),
+                    ),
+                ),
+            ),
+        );
+
+        return array(
+            'list'  => $types,
+            'count' => count($types),
+        );
+    }
+}


commit 4732af0f18a9011d58305a73a0035c7b198a81ac
Author: Aleksander Machniak <alec at alec.pl>
Date:   Fri Sep 21 12:15:52 2012 +0200

    Enable effective_rights API command for group and role

diff --git a/lib/api/kolab_api_service_group.php b/lib/api/kolab_api_service_group.php
index c41dd3c..9357e74 100644
--- a/lib/api/kolab_api_service_group.php
+++ b/lib/api/kolab_api_service_group.php
@@ -64,6 +64,8 @@ class kolab_api_service_group extends kolab_api_service
             $rights['members_list'] = "r";
         }
 
+        $rights['effective_rights'] = "r";
+
         return $rights;
     }
 





More information about the commits mailing list