lib/api lib/kolab_api_service.php lib/kolab_client_task.php

Aleksander Machniak machniak at kolabsys.com
Mon Apr 9 16:30:46 CEST 2012


 lib/api/kolab_api_service_form_value.php |   67 +++++++------------------------
 lib/kolab_api_service.php                |    8 ---
 lib/kolab_client_task.php                |    4 -
 3 files changed, 19 insertions(+), 60 deletions(-)

New commits:
commit 6a72d8db409e11077dd04c43b2600cc0a1a7e782
Author: Aleksander Machniak <machniak at kolabsys.com>
Date:   Mon Apr 9 16:29:12 2012 +0200

    Fix auto_form_fields re-generation on object type change (#690)

diff --git a/lib/api/kolab_api_service_form_value.php b/lib/api/kolab_api_service_form_value.php
index 00a6bdd..72e86a0 100644
--- a/lib/api/kolab_api_service_form_value.php
+++ b/lib/api/kolab_api_service_form_value.php
@@ -206,16 +206,10 @@ class kolab_api_service_form_value extends kolab_api_service
 
     private function generate_cn($postdata, $attribs = array())
     {
-        $conf = Conf::get_instance();
-        $unique_attr = $conf->get('unique_attribute');
-        if (!$unique_attr) {
-            $unique_attr = 'nsuniqueid';
-        }
-
         if (isset($attribs['auto_form_fields']) && isset($attribs['auto_form_fields']['cn'])) {
             // Use Data Please
             foreach ($attribs['auto_form_fields']['cn']['data'] as $key) {
-                if (!isset($postdata[$key]) && !($key == $unique_attr)) {
+                if (!isset($postdata[$key])) {
                     throw new Exception("Key not set: " . $key, 12356);
                 }
             }
@@ -229,16 +223,10 @@ class kolab_api_service_form_value extends kolab_api_service
 
     private function generate_displayname($postdata, $attribs = array())
     {
-        $conf = Conf::get_instance();
-        $unique_attr = $conf->get('unique_attribute');
-        if (!$unique_attr) {
-            $unique_attr = 'nsuniqueid';
-        }
-
         if (isset($attribs['auto_form_fields']) && isset($attribs['auto_form_fields']['displayname'])) {
             // Use Data Please
             foreach ($attribs['auto_form_fields']['displayname']['data'] as $key) {
-                if (!isset($postdata[$key]) && !($key == $unique_attr)) {
+                if (!isset($postdata[$key])) {
                     throw new Exception("Key not set: " . $key, 12356);
                 }
             }
@@ -304,16 +292,10 @@ class kolab_api_service_form_value extends kolab_api_service
 
     private function generate_homedirectory($postdata, $attribs = array())
     {
-        $conf = Conf::get_instance();
-        $unique_attr = $conf->get('unique_attribute');
-        if (!$unique_attr) {
-            $unique_attr = 'nsuniqueid';
-        }
-
         if (isset($attribs['auto_form_fields']) && isset($attribs['auto_form_fields']['homedirectory'])) {
             // Use Data Please
             foreach ($attribs['auto_form_fields']['homedirectory']['data'] as $key) {
-                if (!isset($postdata[$key]) && !($key == $unique_attr)) {
+                if (!isset($postdata[$key])) {
                     throw new Exception("Key not set: " . $key, 12356);
                 }
             }
@@ -364,16 +346,10 @@ class kolab_api_service_form_value extends kolab_api_service
 
     private function generate_primary_mail($postdata, $attribs = array())
     {
-        $conf = Conf::get_instance();
-        $unique_attr = $conf->get('unique_attribute');
-        if (!$unique_attr) {
-            $unique_attr = 'nsuniqueid';
-        }
-
         if (isset($attribs['auto_form_fields']) && isset($attribs['auto_form_fields']['mail'])) {
             // Use Data Please
             foreach ($attribs['auto_form_fields']['mail']['data'] as $key) {
-                if (!isset($postdata[$key]) && !($key == $unique_attr)) {
+                if (!isset($postdata[$key])) {
                     throw new Exception("Key not set: " . $key, 12356);
                 }
             }
@@ -392,16 +368,10 @@ class kolab_api_service_form_value extends kolab_api_service
 
     private function generate_primary_mail_group($postdata, $attribs = array())
     {
-        $conf = Conf::get_instance();
-        $unique_attr = $conf->get('unique_attribute');
-        if (!$unique_attr) {
-            $unique_attr = 'nsuniqueid';
-        }
-
         if (isset($attribs['auto_form_fields']) && isset($attribs['auto_form_fields']['mail'])) {
             // Use Data Please
             foreach ($attribs['auto_form_fields']['mail']['data'] as $key) {
-                if (!isset($postdata[$key]) && !($key == $unique_attr)) {
+                if (!isset($postdata[$key])) {
                     throw new Exception("Key not set: " . $key, 12356);
                 }
             }
@@ -414,12 +384,6 @@ class kolab_api_service_form_value extends kolab_api_service
 
     private function generate_secondary_mail($postdata, $attribs = array())
     {
-        $conf = Conf::get_instance();
-        $unique_attr = $conf->get('unique_attribute');
-        if (!$unique_attr) {
-            $unique_attr = 'nsuniqueid';
-        }
-
         $secondary_mail_address = Array();
 
         if (isset($attribs['auto_form_fields'])) {
@@ -432,7 +396,7 @@ class kolab_api_service_form_value extends kolab_api_service
             }
 
             foreach ($attribs['auto_form_fields'][$secondary_mail_key]['data'] as $key) {
-                if (!isset($postdata[$key]) && !($key == $unique_attr)) {
+                if (!isset($postdata[$key])) {
                     throw new Exception("Key not set: " . $key, 456789);
                 }
             }
@@ -451,16 +415,10 @@ class kolab_api_service_form_value extends kolab_api_service
 
     private function generate_uid($postdata, $attribs = array())
     {
-        $conf = Conf::get_instance();
-        $unique_attr = $conf->get('unique_attribute');
-        if (!$unique_attr) {
-            $unique_attr = 'nsuniqueid';
-        }
-
         if (isset($attribs['auto_form_fields']) && isset($attribs['auto_form_fields']['uid'])) {
             // Use Data Please
             foreach ($attribs['auto_form_fields']['uid']['data'] as $key) {
-                if (!isset($postdata[$key]) && !($key == $unique_attr)) {
+                if (!isset($postdata[$key])) {
                     throw new Exception("Key not set: " . $key, 12356);
                 }
             }
@@ -482,13 +440,19 @@ class kolab_api_service_form_value extends kolab_api_service
             $orig_uid = $uid;
 
             $auth = Auth::get_instance($_SESSION['user']->get_domain());
+            $conf = Conf::get_instance();
+            
+            $unique_attr = $conf->get('unique_attribute');
+            if (!$unique_attr) {
+                $unique_attr = 'nsuniqueid';
+            }
 
             $x = 2;
             while (($user_found = $auth->user_find_by_attribute(array('uid' => $uid)))) {
                 $user_found_dn = key($user_found);
                 $user_found_unique_attr = $auth->get_attribute($user_found_dn, $unique_attr);
                 //console("user that i found info", $user_found_unique_attr);
-                if ($user_found_unique_attr == $postdata[$unique_attr]) {
+                if ($user_found_unique_attr == $postdata['id']) {
                     break;
                 }
 
@@ -617,6 +581,9 @@ class kolab_api_service_form_value extends kolab_api_service
         $conf = Conf::get_instance();
 
         $unique_attr = $conf->get('unique_attribute');
+        if (!$unique_attr) {
+            $unique_attr = 'nsuniqueid';
+        }
 
         $base_dn = $conf->get('user_base_dn');
         if (!$base_dn) {
diff --git a/lib/kolab_api_service.php b/lib/kolab_api_service.php
index b99e780..d43aa67 100644
--- a/lib/kolab_api_service.php
+++ b/lib/kolab_api_service.php
@@ -166,14 +166,6 @@ abstract class kolab_api_service
                 if ($key != "id") {
                     if ($key == "attributes") {
                         $object_types[$row['id']][$key] = json_decode($value, true);
-                        // TODO: Insert unique_attr to attributes, auto_form_fields, $attribute, $data here.
-                        if (array_key_exists('auto_form_fields', $object_types[$row['id']][$key])) {
-                            foreach ($object_types[$row['id']][$key]['auto_form_fields'] as $attribute => $data) {
-                                if (array_key_exists('data', $data) && !in_array($unique_attr, $data['data'])) {
-                                    $object_types[$row['id']][$key]['auto_form_fields'][$attribute]['data'][] = $unique_attr;
-                                }
-                            }
-                        }
                     }
                     else {
                         $object_types[$row['id']][$key] = $value;
diff --git a/lib/kolab_client_task.php b/lib/kolab_client_task.php
index 14e644a..4521a99 100644
--- a/lib/kolab_client_task.php
+++ b/lib/kolab_client_task.php
@@ -789,7 +789,6 @@ class kolab_client_task
             //console("\$field value for \$auto_fields[\$idx] (idx: $idx)", $auto_fields[$idx]);
             if (!is_array($field)) {
                 //console("not an array... unsetting");
-
                 unset($auto_fields[$idx]);
                 continue;
             }
@@ -803,7 +802,7 @@ class kolab_client_task
             }
 
             $field['name'] = $idx;
-            $fields[$idx] = $this->form_element_type($field, $data);
+            $fields[$idx]  = $this->form_element_type($field, $data);
             $fields[$idx]['readonly'] = true;
 
             $extra_fields[$idx] = true;
@@ -896,6 +895,7 @@ class kolab_client_task
                     'attributes'  => $auto_attribs,
                     'object_type' => $name,
                 ));
+
                 $resp = $this->api->post('form_value.generate', null, $data);
                 $data = array_merge((array)$data, (array)$resp->get());
             }





More information about the commits mailing list