4 commits - lib/api lib/Auth lib/kolab_api_service.php public_html/js

Jeroen van Meeuwen vanmeeuwen at kolabsys.com
Thu Apr 5 21:43:32 CEST 2012


 lib/Auth/LDAP.php                  |   54 +++++++++++++++++++++----------------
 lib/api/kolab_api_service_user.php |    7 +++-
 lib/kolab_api_service.php          |   15 ++++++++--
 public_html/js/kolab_admin.js      |   34 +++++++++++++++--------
 4 files changed, 71 insertions(+), 39 deletions(-)

New commits:
commit 6f50b19d5b641638cb77df9dbaf71d4710d55a7d
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date:   Thu Apr 5 21:41:46 2012 +0200

    1) Populate the textarea element with an autocomplete widget with the original values.
    2) Push back the values in the textarea as well as the values that have been added to new (autocomplete) child nodes.

diff --git a/public_html/js/kolab_admin.js b/public_html/js/kolab_admin.js
index da01cd7..b775afb 100644
--- a/public_html/js/kolab_admin.js
+++ b/public_html/js/kolab_admin.js
@@ -690,24 +690,29 @@ function kolab_admin()
 
     // replace some textarea fields with pretty/smart input lists
     $('textarea[data-type="list"]', form).not('disabled').each(function() {
-      var i, v, value = [],
+      var i, k, v, value = [],
         re = RegExp('^' + RegExp.escape(this.name) + '\[[0-9-]+\]$');
 
       for (i in data.json) {
         if (i.match(re)) {
-          if (v = $('input[name="'+i+'"]', form).val())
-            value.push(v);
+          if (v = $('input[name="'+i+'"]', form).val()) {
+            pushed = 0;
+            if (kadm.env.assoc_fields[this.name]) {
+              for (k in kadm.env.assoc_fields[this.name]) {
+                if (kadm.env.assoc_fields[this.name][k] == v) {
+                  value.push(k);
+                  pushed = 1;
+                }
+              }
+            }
+            if (!pushed) {
+              value.push(v);
+            }
+          }
           delete data.json[i];
         }
       }
 
-      // autocompletion lists data is stored in env variable
-      if (kadm.env.assoc_fields[this.name]) {
-        value = [];
-        for (i in kadm.env.assoc_fields[this.name])
-          value.push(i);
-      }
-
       data.json[this.name] = value;
     });
 
@@ -779,11 +784,12 @@ function kolab_admin()
 
         elem.appendTo(area);
         this.ac_init(elem, {attribute: form_element.name, oninsert: this.form_element_oninsert});
-
+        
         area.addClass('autocomplete');
       }
 
       // add input rows
+      ac_value = []
       for (i in list) {
         elem = this.form_list_element(form_element.form, {
           value: list[i],
@@ -793,8 +799,14 @@ function kolab_admin()
           element: e
         }, j++);
 
+        if (autocomplete)
+            ac_value.push(list[i]);
+
         elem.appendTo(area);
       }
+
+      if (autocomplete)
+        e.val(ac_value.join("\n"));
     }
 
     area.appendTo(form_element.parentNode);


commit d2d8931736dc5a1e2bfc4b34f3f447f3cf4895a0
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date:   Thu Apr 5 21:41:13 2012 +0200

    Suppress console output.

diff --git a/lib/kolab_api_service.php b/lib/kolab_api_service.php
index 0a1f268..b99e780 100644
--- a/lib/kolab_api_service.php
+++ b/lib/kolab_api_service.php
@@ -100,7 +100,7 @@ abstract class kolab_api_service
         $type_score   = -1;
         $type_id      = null;
 
-        console("Data objectClasses: " . implode(", ", $object_class));
+        //console("Data objectClasses: " . implode(", ", $object_class));
 
         foreach ($object_types as $idx => $elem) {
             $ref_class = $elem['attributes']['fields']['objectclass'];
@@ -109,7 +109,7 @@ abstract class kolab_api_service
                 continue;
             }
 
-            console("Reference objectclasses for " . $elem['key'] . ": " . implode(", ", $ref_class));
+            //console("Reference objectclasses for " . $elem['key'] . ": " . implode(", ", $ref_class));
 
             // Eliminate the duplicates between the $data_ocs and $ref_ocs
             $_object_class = array_diff($object_class, $ref_class);
@@ -121,7 +121,7 @@ abstract class kolab_api_service
 
 //            console("\$object_class not in \$ref_class (" . $elem['key'] . "): " . implode(", ", $_object_class));
 //            console("\$ref_class not in \$object_class (" . $elem['key'] . "): " . implode(", ", $_ref_class));
-            console("Score for $object_name type " . $elem['name'] . ": " . $elem_score . "(" . $commonalities . "/" . $differences . ")");
+            //console("Score for $object_name type " . $elem['name'] . ": " . $elem_score . "(" . $commonalities . "/" . $differences . ")");
 
             if ($elem_score > $type_score) {
                 $type_id    = $idx;
@@ -259,15 +259,22 @@ abstract class kolab_api_service
     protected function parse_input_attributes($object_name, $attribs)
     {
         $type_attrs   = $this->object_type_attributes($object_name, $attribs['type_id']);
+
+        //console("parse_input_attributes", $type_attrs);
+
         $form_service = $this->controller->get_service('form_value');
         $result       = array();
 
         if (isset($type_attrs['form_fields'])) {
             foreach ($type_attrs['form_fields'] as $key => $value) {
+                //console("Running parse input attributes for key $key");
+
                 if (empty($attribs[$key]) && empty($value['optional'])) {
+                    //console("\$attribs['" . $key . "'] is empty, and the field is not optional");
                     throw new Exception("Missing input value for $key", 345);
                 }
                 else {
+                    //console("Either \$attribs['" . $key . "'] is empty or the field is optional");
                     $result[$key] = $attribs[$key];
                 }
             }
@@ -298,6 +305,8 @@ abstract class kolab_api_service
             }
         }
 
+        //console("parse_input_attributes result", $result);
+
         return $result;
     }
 


commit 4c22be3de4dab22bc41e3d9779a9c4f167cfa67f
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date:   Thu Apr 5 21:40:41 2012 +0200

    Suppress console output

diff --git a/lib/api/kolab_api_service_user.php b/lib/api/kolab_api_service_user.php
index 868374d..0c1ac4b 100644
--- a/lib/api/kolab_api_service_user.php
+++ b/lib/api/kolab_api_service_user.php
@@ -108,7 +108,7 @@ class kolab_api_service_user extends kolab_api_service
      */
     public function user_delete($getdata, $postdata)
     {
-        console("user_delete()", $getdata, $postdata);
+        //console("user_delete()", $getdata, $postdata);
         if (!isset($postdata['user'])) {
             return false;
         }
@@ -126,9 +126,12 @@ class kolab_api_service_user extends kolab_api_service
 
     public function user_edit($getdata, $postdata)
     {
-        console("\$postdata to user_edit()", $postdata);
+        //console("\$postdata to user_edit()", $postdata);
 
         $user_attributes = $this->parse_input_attributes('user', $postdata);
+
+        //console("\$user_attributes as result from parse_input_attributes", $user_attributes);
+
         $user            = $postdata['id'];
 
         $auth   = Auth::get_instance();


commit e4f73c77d197b1e117c9ba357f75810f809851d5
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date:   Thu Apr 5 21:37:53 2012 +0200

    Extend Auth::LDAP::group_info() and Auth::LDAP::user_info() with $attributes = array('*') parameter so all attributes we are interested in can be retrieved in one go.
    Use the correct group attributes array when passing group_edit() calls on to modify_entry().
    Suppress all console output.
    Correct new (parent) ou location detection.

diff --git a/lib/Auth/LDAP.php b/lib/Auth/LDAP.php
index 7699a33..b4ccbb7 100644
--- a/lib/Auth/LDAP.php
+++ b/lib/Auth/LDAP.php
@@ -514,12 +514,14 @@ class LDAP
         $_user = $this->entry_find_by_attribute(array($unique_attr => $attributes[$unique_attr]));
 
         if (!$_user) {
-            console("Could not find user");
+            //console("Could not find user");
             return false;
         }
 
         $_user_dn = key($_user);
-        $_user = $this->user_info($_user_dn, array());
+        $_user = $this->user_info($_user_dn, array_keys($attributes));
+
+        //console("user_edit \$_user", $_user);
 
         // We should start throwing stuff over the fence here.
         return $this->modify_entry($_user_dn, $_user[$_user_dn], $attributes);
@@ -541,14 +543,14 @@ class LDAP
      *
      *
      */
-    public function user_info($user)
+    public function user_info($user, $attributes = array('*'))
     {
         $user_dn = $this->entry_dn($user);
 
         if (!$user_dn)
             return false;
 
-        return self::normalize_result($this->_search($user_dn));
+        return self::normalize_result($this->_search($user_dn, '(objectclass=*)', $attributes));
     }
 
     public function user_find_by_attribute($attribute)
@@ -625,15 +627,15 @@ class LDAP
         $_group = $this->entry_find_by_attribute(array($unique_attr => $attributes[$unique_attr]));
 
         if (!$_group) {
-            console("Could not find group");
+            //console("Could not find group");
             return false;
         }
 
         $_group_dn = key($_group);
-        $_group = $this->group_info($_group_dn, array());
+        $_group = $this->group_info($_group_dn, array_keys($attributes));
 
         // We should start throwing stuff over the fence here.
-        return $this->modify_entry($_group_dn, $_group, $attributes);
+        return $this->modify_entry($_group_dn, $_group[$_group_dn], $attributes);
     }
 
     public function group_delete($group)
@@ -647,7 +649,7 @@ class LDAP
         return $this->_delete($group_dn);
     }
 
-    public function group_info($group)
+    public function group_info($group, $attributes = array('*'))
     {
         $group_dn = $this->entry_dn($group);
 
@@ -655,7 +657,7 @@ class LDAP
             return false;
         }
 
-        return self::normalize_result($this->_search($group_dn));
+        return self::normalize_result($this->_search($group_dn, '(objectclass=*)', $attributes));
     }
 
     public function group_members_list($group)
@@ -1054,7 +1056,7 @@ class LDAP
                 }
 
                 if (!($new_attrs[$attr] === $old_attr_value) && !($_sort1 === $_sort2)) {
-                    console("Attribute $attr changed from", $old_attr_value, "to", $new_attrs[$attr]);
+                    //console("Attribute $attr changed from", $old_attr_value, "to", $new_attrs[$attr]);
                     if ($attr === $rdn_attr) {
                         $mod_array['rename']['dn'] = $subject_dn;
                         $mod_array['rename']['new_rdn'] = $rdn_attr . '=' . $new_attrs[$attr];
@@ -1064,22 +1066,22 @@ class LDAP
                                 case "userpassword":
                                     break;
                                 default:
-                                    console("Adding to del: $attr");
+                                    //console("Adding to del: $attr");
                                     $mod_array['del'][$attr] = (array)($old_attr_value);
                                     break;
                             }
                         } else {
-                            console("Adding to replace: $attr");
+                            //console("Adding to replace: $attr");
                             $mod_array['replace'][$attr] = (array)($new_attrs[$attr]);
                         }
                     }
                 } else {
-                    console("Attribute $attr unchanged");
+                    //console("Attribute $attr unchanged");
                 }
             } else {
                 // TODO: Since we're not shipping the entire object back and forth, and only post
                 // part of the data... we don't know what is actually removed (think modifiedtimestamp, etc.)
-                console("Group attribute $attr not mentioned in \$new_attrs..., but not explicitly removed... by assumption");
+                //console("Group attribute $attr not mentioned in \$new_attrs..., but not explicitly removed... by assumption");
             }
         }
 
@@ -1091,7 +1093,7 @@ class LDAP
                             case "userpassword":
                                 break;
                             default:
-                                console("Adding to del(2): $attr");
+                                //console("Adding to del(2): $attr");
                                 $mod_array['del'][$attr] = (array)($old_attrs[$attr]);
                                 break;
                         }
@@ -1099,7 +1101,7 @@ class LDAP
                 } else {
                     if (!($old_attrs[$attr] === $value) && !($attr === $rdn_attr)) {
                         if (!array_key_exists($attr, $mod_array['replace'])) {
-                            console("Adding to replace(2): $attr");
+                            //console("Adding to replace(2): $attr");
                             $mod_array['replace'][$attr] = $value;
                         }
                     }
@@ -1111,7 +1113,14 @@ class LDAP
             }
         }
 
-        if (!($old_ou === $new_ou)) {
+        if (empty($old_ou)) {
+            $subject_dn_components = ldap_explode_dn($subject_dn, 0);
+            unset($subject_dn_components["count"]);
+            $subject_rdn = array_shift($subject_dn_components);
+            $old_ou = implode(',', $subject_dn_components);
+        }
+
+        if (!(strtolower($old_ou) === strtolower($new_ou))) {
             $mod_array['rename']['new_parent'] = $new_ou;
             if (empty($mod_array['rename']['dn']) || empty($mod_array['rename']['new_rdn'])) {
                 $mod_array['rename']['dn'] = $subject_dn;
@@ -1141,7 +1150,7 @@ class LDAP
         }
 
         if (!$result) {
-            console("Failed to replace the following attributes", $attributes['replace']);
+            //console("Failed to replace the following attributes", $attributes['replace']);
             return false;
         }
 
@@ -1150,7 +1159,7 @@ class LDAP
         }
 
         if (!$result) {
-            console("Failed to delete the following attributes", $attributes['del']);
+            //console("Failed to delete the following attributes", $attributes['del']);
             return false;
         }
 
@@ -1160,7 +1169,7 @@ class LDAP
         }
 
         if (!$result) {
-            console("Failed to add the following attributes", $attributes['add']);
+            //console("Failed to add the following attributes", $attributes['add']);
             return false;
         }
 
@@ -1173,7 +1182,7 @@ class LDAP
                 $new_parent = null;
             }
 
-            console("Attempt to rename $olddn to $newrdn,$new_parent");
+            //console("Attempt to rename $olddn to $newrdn,$new_parent");
 
             $result = ldap_rename($this->conn, $olddn, $newrdn, $new_parent, true);
         }
@@ -1460,8 +1469,7 @@ class LDAP
 
         $attributes = (array)($attributes);
 
-        error_log("Searching $base_dn with filter: $search_filter");
-//        error_log("Searching with user: " . $_SESSION['user']->user_bind_dn);
+        //console("Searching $base_dn with filter: $search_filter, attempting to get attributes", $attributes);
 
         $this->_bind($_SESSION['user']->user_bind_dn, $_SESSION['user']->user_bind_pw);
 





More information about the commits mailing list