Branch 'dev/edit-existing-entries' - 6 commits - lib/api lib/Auth lib/Auth.php lib/client
Jeroen van Meeuwen
vanmeeuwen at kolabsys.com
Sat Mar 31 20:45:35 CEST 2012
lib/Auth.php | 5 -
lib/Auth/LDAP.php | 27 ++++++--
lib/api/kolab_api_service_form_value.php | 7 ++
lib/api/kolab_api_service_user.php | 97 ++++++++++++++++++++++++++++++-
lib/client/kolab_client_task_user.php | 1
5 files changed, 125 insertions(+), 12 deletions(-)
New commits:
commit 4b7bcf0bcd74ccfe367fdd12c2f7dbccfc1408c1
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date: Sat Mar 31 20:45:11 2012 +0200
Add nsroledn attribute to 'system' tab
diff --git a/lib/client/kolab_client_task_user.php b/lib/client/kolab_client_task_user.php
index f4ef0ea..1672136 100644
--- a/lib/client/kolab_client_task_user.php
+++ b/lib/client/kolab_client_task_user.php
@@ -233,6 +233,7 @@ class kolab_client_task_user extends kolab_client_task
'gidnumber' => 'system',
'homedirectory' => 'system',
'nsrole' => 'system',
+ 'nsroledn' => 'system',
'mailquota' => 'config',
'cyrususerquota' => 'config',
commit 4ed16adbfc19a22818341270e2fe1c862c27cdcf
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date: Sat Mar 31 20:44:52 2012 +0200
Add function user_edit()
diff --git a/lib/api/kolab_api_service_user.php b/lib/api/kolab_api_service_user.php
index 222d5a7..4695fdf 100644
--- a/lib/api/kolab_api_service_user.php
+++ b/lib/api/kolab_api_service_user.php
@@ -40,7 +40,7 @@ class kolab_api_service_user extends kolab_api_service
return array(
'add' => 'w',
'delete' => 'w',
-// 'edit' => 'w',
+ 'edit' => 'w',
// 'find' => 'r',
// 'find_by_any_attribute' => 'r',
// 'find_by_attribute' => 'r',
@@ -130,6 +130,99 @@ class kolab_api_service_user extends kolab_api_service
return false;
}
+ public function user_edit($getdata, $postdata)
+ {
+ $uta = $this->object_type_attributes('user', $postdata['type_id']);
+ $form_service = $this->controller->get_service('form_value');
+ $user_attributes = array();
+
+ // Get the type "key" string for the next few settings.
+ if ($postdata['type_id'] == null) {
+ $type_str = 'user';
+ }
+ else {
+ $db = SQL::get_instance();
+ $_key = $db->fetch_assoc($db->query("SELECT `key` FROM user_types WHERE id = ?", $postdata['type_id']));
+ $type_str = $_key['key'];
+ }
+
+ $conf = Conf::get_instance();
+
+ $unique_attr = $conf->get('unique_attribute');
+ if (!$unique_attr) {
+ $unique_attr = 'nsuniqueid';
+ }
+ // TODO: "rdn" is somewhat LDAP specific, but not used as something
+ // LDAP specific...?
+ $rdn_attr = $conf->get($type_str . '_user_name_attribute');
+ if (!$rdn_attr) {
+ $rdn_attr = $conf->get('user_name_attribute');
+ }
+ if (!$rdn_attr) {
+ $rdn_attr = 'uid';
+ }
+
+ if (isset($uta['form_fields'])) {
+ foreach ($uta['form_fields'] as $key => $value) {
+ if (!isset($postdata[$key]) || empty($postdata[$key])) {
+ throw new Exception("Missing input value for $key", 345);
+ }
+ else {
+ $user_attributes[$key] = $postdata[$key];
+ }
+ }
+ }
+
+ if (isset($uta['auto_form_fields'])) {
+ foreach ($uta['auto_form_fields'] as $key => $value) {
+ if (empty($postdata[$key])) {
+ $postdata['attributes'] = array($key);
+ $res = $form_service->generate($getdata, $postdata);
+ $postdata[$key] = $res[$key];
+ }
+ $user_attributes[$key] = $postdata[$key];
+ }
+ }
+
+ if (isset($uta['fields'])) {
+ foreach ($uta['fields'] as $key => $value) {
+ if (!isset($postdata[$key]) || empty($postdata[$key])) {
+ $user_attributes[$key] = $uta['fields'][$key];
+ } else {
+ $user_attributes[$key] = $postdata[$key];
+ }
+ }
+
+ $user_attributes[$unique_attr] = $postdata[$unique_attr];
+ }
+
+ $auth = Auth::get_instance();
+ $auth->connect();
+
+ // Now that values have been re-generated where necessary, compare
+ // the new group attributes to the original group attributes.
+ $_user = $auth->user_find_by_attribute(Array($unique_attr => $postdata[$unique_attr]));
+
+ if (!$_user) {
+ console("Could not find user");
+ return false;
+ }
+
+ $_user_dn = key($_user);
+ $_user = $this->user_info(Array('user' => $_user_dn), Array());
+
+
+
+ // We should start throwing stuff over the fence here.
+ $result = $auth->modify_entry($_user_dn, $_user, $user_attributes);
+
+ if ($result) {
+ return true;
+ }
+
+ return false;
+
+ }
/**
* User information.
*
@@ -189,6 +282,8 @@ class kolab_api_service_user extends kolab_api_service
}
}
+ console($result);
+
if ($result) {
return $result;
}
commit 3fac2ceac61e1b0f0c16ce124860cfbc4c36c2ef
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date: Sat Mar 31 20:44:04 2012 +0200
Inverse form_value.list_options for nsrole and nsroledn, and issue a warning when using 'nsrole'
diff --git a/lib/api/kolab_api_service_form_value.php b/lib/api/kolab_api_service_form_value.php
index d3aedd3..843792b 100644
--- a/lib/api/kolab_api_service_form_value.php
+++ b/lib/api/kolab_api_service_form_value.php
@@ -516,6 +516,12 @@ class kolab_api_service_form_value extends kolab_api_service
private function list_options_nsrole($postdata, $attribs = array())
{
+ error_log("Listing options for attribute 'nsrole', while the expected attribute to use is 'nsroledn'");
+ return $this->list_options_nsroledn($postdata, $attribs);
+ }
+
+ private function list_options_nsroledn($postdata, $attribs = Array())
+ {
$service = $this->controller->get_service('roles');
$keyword = array('value' => $postdata['search']);
@@ -540,8 +546,4 @@ class kolab_api_service_form_value extends kolab_api_service
return $list;
}
- private function list_options_nsroledn($postdata, $attribs = Array())
- {
- return $this->list_options_nsrole($postdata, $attribs);
- }
}
commit c6fcc6f7f6c40757e244485e16663e7b384ed08e
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date: Sat Mar 31 20:42:01 2012 +0200
'nsrole', as an attribute that can actually be added is called 'nsroledn' - provide that form_value.list_options function as well
diff --git a/lib/api/kolab_api_service_form_value.php b/lib/api/kolab_api_service_form_value.php
index f601bd9..d3aedd3 100644
--- a/lib/api/kolab_api_service_form_value.php
+++ b/lib/api/kolab_api_service_form_value.php
@@ -539,4 +539,9 @@ class kolab_api_service_form_value extends kolab_api_service
return $list;
}
+
+ private function list_options_nsroledn($postdata, $attribs = Array())
+ {
+ return $this->list_options_nsrole($postdata, $attribs);
+ }
}
commit 32cd43db6279424d14ebda304ed11356ef3d05b4
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date: Sat Mar 31 20:41:30 2012 +0200
Discover what the RDN is by using the old LDAP object
diff --git a/lib/Auth/LDAP.php b/lib/Auth/LDAP.php
index abf328b..2a26c0a 100644
--- a/lib/Auth/LDAP.php
+++ b/lib/Auth/LDAP.php
@@ -373,8 +373,17 @@ class LDAP
public function modify_entry($subject_dn, $old_attrs, $new_attrs)
{
+ console($old_attrs);
+
// TODO: Get $rdn_attr - we have type_id in $new_attrs
- $rdn_attr = 'cn';
+ $dn_components = ldap_explode_dn($subject_dn, 0);
+ $rdn_components = explode('=', $dn_components[0]);
+
+ $rdn_attr = $rdn_components[0];
+
+ console($rdn_attr);
+
+// return;
$mod_array = Array(
"add" => Array(), // For use with ldap_mod_add()
@@ -439,15 +448,19 @@ class LDAP
$result = ldap_mod_replace($this->conn, $subject_dn, $attributes['replace']);
}
- if (!$result)
+ if (!$result) {
+ console("Failed to replace the following attributes", $attributes['replace']);
return false;
+ }
if (is_array($attributes['add']) && !empty($attributes['add'])) {
$result = ldap_mod_add($this->conn, $subject_dn, $attributes['add']);
}
- if (!$result)
+ if (!$result) {
+ console("Failed to add the following attributes", $attributes['add']);
return false;
+ }
if (is_array($attributes['rename']) && !empty($attributes['rename'])) {
$olddn = key($attributes['rename']);
@@ -455,13 +468,15 @@ class LDAP
$result = ldap_rename($this->conn, $olddn, $newrdn, NULL, true);
}
- if (!$result)
+ if (!$result) {
return false;
+ }
- if ($result)
+ if ($result) {
return true;
- else
+ } else {
return false;
+ }
}
public function user_add($attrs, $type = null)
commit 857248878c83ac2a7a84ff43f1bafef403d4ad71
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date: Sat Mar 31 20:41:00 2012 +0200
Deprecate Auth::modify_entry_attributes
diff --git a/lib/Auth.php b/lib/Auth.php
index e4bbc8d..75e78e1 100644
--- a/lib/Auth.php
+++ b/lib/Auth.php
@@ -256,11 +256,6 @@ class Auth {
return $this->_auth[$_SESSION['user']->get_domain()]->modify_entry($subject, $attrs, $_attrs);
}
- public function modify_entry_attributes($subject, $mod_array)
- {
- return $this->_auth[$_SESSION['user']->get_domain()]->modify_entry_attributes($subject, $mod_array);
- }
-
public function primary_for_valid_domain($domain)
{
$this->domains = $this->list_domains();
More information about the commits
mailing list