Branch 'kolab-webadmin-3.1' - lib/kolab_api_controller.php

Aleksander Machniak machniak at kolabsys.com
Wed Jun 18 13:54:01 CEST 2014


 lib/kolab_api_controller.php |   59 ++++++++++++++++++++++++-------------------
 1 file changed, 34 insertions(+), 25 deletions(-)

New commits:
commit b0bfd9a24f2ec4e0600d98a789badad264bbf215
Author: Aleksander Machniak <machniak at kolabsys.com>
Date:   Wed Jun 18 13:44:22 2014 +0200

    Add possibility to limit system.capabilities response to one domain

diff --git a/lib/kolab_api_controller.php b/lib/kolab_api_controller.php
index 1105235..43daeab 100644
--- a/lib/kolab_api_controller.php
+++ b/lib/kolab_api_controller.php
@@ -34,7 +34,6 @@ class kolab_api_controller
     private $uid;
     private $request  = array();
     private $services = array();
-    private $domains  = array('localhost.localdomain');
     private static $translation = array();
 
     public function __construct()
@@ -341,35 +340,46 @@ class kolab_api_controller
 
     /**
      * Provide a list of capabilities the backend provides to the current user
+     *
+     * @param array GET request parameters
+     * @param array POST data
+     *
+     * @param array Capabilities indexed by domain name
      */
-    private function capabilities()
+    private function capabilities($request, $postdata)
     {
-        Log::debug("system.capabilities called");
+        $result  = array();
+        $domains = array();
 
-        $auth = Auth::get_instance();
-
-        // Get the domain name attribute
-        $dna = $this->config->get('ldap', 'domain_name_attribute');
-        if (empty($dna)) {
-            $dna = 'associateddomain';
+        // specified domain
+        if (!empty($request['domain'])) {
+            $domains[] = $request['domain'];
         }
+        // get all domains
+        else {
+            $auth = Auth::get_instance();
+
+            // Get the domain name attribute
+            $dna = $this->config->get('ldap', 'domain_name_attribute');
+            if (empty($dna)) {
+                $dna = 'associateddomain';
+            }
 
-        $_domains = $auth->list_domains();
-        $this->domains = $_domains['list'];
+            $_domains = $auth->list_domains();
+            $domains = $_domains['list'];
 
-        $result = array();
+            foreach ($domains as $idx => $attrs) {
+                $domains[$idx] = is_array($attrs) ? (is_array($attrs[$dna]) ? $attrs[$dna][0] : $attrs[$dna]) : $attrs;
+            }
 
-        // Should we have no permissions to list domain name spaces,
-        // we should always return our own.
-        if (count($this->domains) < 1) {
-            //console("As there is but one domain, we insert our own");
-            $this->domains[] = Array($dna => $_SESSION['user']->get_domain());
+            // Should we have no permissions to list domain name spaces,
+            // we should always return our own.
+            if (count($domains) < 1) {
+                $domains[] = $_SESSION['user']->get_domain();
+            }
         }
 
-        // add capabilities of all registered services
-        foreach ($this->domains as $domain_dn => $domain_attrs) {
-            $domain_name = is_array($domain_attrs) ? (is_array($domain_attrs[$dna]) ? $domain_attrs[$dna][0] : $domain_attrs[$dna]) : $domain_attrs;
-
+        foreach ($domains as $domain_name) {
             // define our very own capabilities
             $actions = array(
                 'system.quit'      => array('type' => 'w'),
@@ -387,10 +397,9 @@ class kolab_api_controller
         }
 
         return array(
-                'list'  => $result,
-                'count' => count($result),
-            );
-
+            'list'  => $result,
+            'count' => count($result),
+        );
     }
 
     private function get_domain() {




More information about the commits mailing list