summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2012-04-01 17:06:34 +0200
committerJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2012-04-01 17:06:34 +0200
commit3136ff4ecec60ea95554b45354abaf1a337a25dd (patch)
tree5066d0d02c156171fa6fbf4b5dd0b18ea6678d9a
parent687f5e1088d27fe5d8aad7478254f4281f347a84 (diff)
downloadwebadmin-3136ff4ecec60ea95554b45354abaf1a337a25dd.tar.gz
Supply the unique attribute to form submissions as data, so that form_value service methods such as generate_uid and generate_primary_mail can take into account whether the existing result found for a value generated is actually the same LDAP object as is being edited. Resolves #666.
-rw-r--r--lib/Auth/LDAP.php7
-rw-r--r--lib/api/kolab_api_service_form_value.php65
-rw-r--r--lib/kolab_api_service.php14
3 files changed, 76 insertions, 10 deletions
diff --git a/lib/Auth/LDAP.php b/lib/Auth/LDAP.php
index 506e3e5..e748347 100644
--- a/lib/Auth/LDAP.php
+++ b/lib/Auth/LDAP.php
@@ -245,8 +245,11 @@ class LDAP
public function get_attribute($subject_dn, $attribute)
{
- $result = ldap_read($this->conn, $subject_dn, '(objectclass=*)', (array)($attribute));
- console($result);
+ $result = $this->search($subject_dn, '(objectclass=*)', (array)($attribute));
+ $result = self::normalize_result($result);
+ $dn = key($result);
+ $attr = key($result[$dn]);
+ return $result[$dn][$attr];
}
public function get_attributes($subject_dn, $attributes)
diff --git a/lib/api/kolab_api_service_form_value.php b/lib/api/kolab_api_service_form_value.php
index 843792b..7e03140 100644
--- a/lib/api/kolab_api_service_form_value.php
+++ b/lib/api/kolab_api_service_form_value.php
@@ -198,10 +198,16 @@ 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])) {
+ if (!isset($postdata[$key]) && !($key == $unique_attr)) {
throw new Exception("Key not set: " . $key, 12356);
}
}
@@ -215,10 +221,16 @@ 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])) {
+ if (!isset($postdata[$key]) && !($key == $unique_attr)) {
throw new Exception("Key not set: " . $key, 12356);
}
}
@@ -284,10 +296,16 @@ 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])) {
+ if (!isset($postdata[$key]) && !($key == $unique_attr)) {
throw new Exception("Key not set: " . $key, 12356);
}
}
@@ -338,10 +356,16 @@ 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])) {
+ if (!isset($postdata[$key]) && !($key == $unique_attr)) {
throw new Exception("Key not set: " . $key, 12356);
}
}
@@ -360,10 +384,16 @@ 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])) {
+ if (!isset($postdata[$key]) && !($key == $unique_attr)) {
throw new Exception("Key not set: " . $key, 12356);
}
}
@@ -376,6 +406,12 @@ 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'])) {
@@ -388,7 +424,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])) {
+ if (!isset($postdata[$key]) && !($key == $unique_attr)) {
throw new Exception("Key not set: " . $key, 456789);
}
}
@@ -407,10 +443,16 @@ 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])) {
+ if (!isset($postdata[$key]) && !($key == $unique_attr)) {
throw new Exception("Key not set: " . $key, 12356);
}
}
@@ -432,7 +474,14 @@ class kolab_api_service_form_value extends kolab_api_service
$auth = Auth::get_instance($_SESSION['user']->get_domain());
$x = 2;
- while ($auth->user_find_by_attribute(array('uid' => $uid))) {
+ 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]) {
+ break;
+ }
+
$uid = $orig_uid . $x;
$x++;
}
diff --git a/lib/kolab_api_service.php b/lib/kolab_api_service.php
index f1b0b95..26d9e39 100644
--- a/lib/kolab_api_service.php
+++ b/lib/kolab_api_service.php
@@ -150,6 +150,12 @@ abstract class kolab_api_service
return $this->cache['object_types'][$object_name];
}
+ $conf = Conf::get_instance();
+ $unique_attr = $conf->get('unique_attribute');
+ if (!$unique_attr) {
+ $unique_attr = 'nsuniqueid';
+ }
+
$sql_result = $this->db->query("SELECT * FROM {$object_name}_types");
$object_types = array();
@@ -160,6 +166,14 @@ 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;