summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Machniak <alec@alec.pl>2012-10-24 10:53:17 (GMT)
committerJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2012-11-26 13:29:47 (GMT)
commitd41fd23fdc80f48c27e70caa7b083c5b7e8396aa (patch)
tree732298dcc18a944f6ce32c04f443d8b052edfc68
parent2a405d0483013bceac13e49c9f8a32dd0b7d0f2c (diff)
downloadkolab-wap-d41fd23fdc80f48c27e70caa7b083c5b7e8396aa.tar.gz
Code improvements
-rw-r--r--lib/api/kolab_api_service_domain.php9
-rw-r--r--lib/api/kolab_api_service_form_value.php65
-rw-r--r--lib/api/kolab_api_service_role.php9
-rw-r--r--lib/kolab_api_service.php23
4 files changed, 42 insertions, 64 deletions
diff --git a/lib/api/kolab_api_service_domain.php b/lib/api/kolab_api_service_domain.php
index 636c230..2d91358 100644
--- a/lib/api/kolab_api_service_domain.php
+++ b/lib/api/kolab_api_service_domain.php
@@ -145,14 +145,11 @@ class kolab_api_service_domain extends kolab_api_service
public function domain_effective_rights($getdata, $postdata)
{
$auth = Auth::get_instance();
- $conf = Conf::get_instance();
if (!empty($getdata['domain'])) {
- $entry_dn = $getdata['domain'];
-
- $unique_attr = $conf->get('ldap', 'unique_attribute');
-
- $domain = $auth->domain_find_by_attribute(array($unique_attr => $entry_dn));
+ $entry_dn = $getdata['domain'];
+ $unique_attr = $this->unique_attribute();
+ $domain = $auth->domain_find_by_attribute(array($unique_attr => $entry_dn));
if (!empty($domain)) {
$entry_dn = key($domain);
diff --git a/lib/api/kolab_api_service_form_value.php b/lib/api/kolab_api_service_form_value.php
index 1443a1b..70aa8b9 100644
--- a/lib/api/kolab_api_service_form_value.php
+++ b/lib/api/kolab_api_service_form_value.php
@@ -260,15 +260,9 @@ class kolab_api_service_form_value extends kolab_api_service
}
}
- $auth = Auth::get_instance($_SESSION['user']->get_domain());
- $conf = Conf::get_instance();
-
- $unique_attr = $conf->get('unique_attribute');
- if (!$unique_attr) {
- $unique_attr = 'nsuniqueid';
- }
-
- $cn = $postdata['cn'];
+ $auth = Auth::get_instance($_SESSION['user']->get_domain());
+ $unique_attr = $this->unique_attribute();
+ $cn = $postdata['cn'];
$x = 2;
while (($resource_found = $auth->resource_find_by_attribute(array('cn' => $cn)))) {
@@ -430,19 +424,11 @@ class kolab_api_service_form_value extends kolab_api_service
//console("normalized resource data", $resourcedata);
// TODO: Normalize $postdata
- $mail_local = 'resource-' . $object_type_key . '-' . strtolower($resourcedata['cn']);
+ $mail_local = 'resource-' . $object_type_key . '-' . strtolower($resourcedata['cn']);
$mail_domain = $_SESSION['user']->get_domain();
- $mail = $mail_local . '@' . $mail_domain;
-
- $orig_mail = $mail;
-
- $auth = Auth::get_instance($_SESSION['user']->get_domain());
- $conf = Conf::get_instance();
-
- $unique_attr = $conf->get('unique_attribute');
- if (!$unique_attr) {
- $unique_attr = 'nsuniqueid';
- }
+ $mail = $mail_local . '@' . $mail_domain;
+ $auth = Auth::get_instance($_SESSION['user']->get_domain());
+ $unique_attr = $this->unique_attribute();
$x = 2;
while (($resource_found = $auth->resource_find_by_attribute(array('mail' => $mail)))) {
@@ -461,8 +447,6 @@ class kolab_api_service_form_value extends kolab_api_service
}
return $mail;
-
-
}
}
@@ -594,13 +578,8 @@ 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';
- }
+ $auth = Auth::get_instance($_SESSION['user']->get_domain());
+ $unique_attr = $this->unique_attribute();
$x = 2;
while (($user_found = $auth->user_find_by_attribute(array('uid' => $uid)))) {
@@ -625,18 +604,17 @@ class kolab_api_service_form_value extends kolab_api_service
private function generate_uidnumber($postdata, $attribs = array())
{
if (isset($attribs['auto_form_fields']) && isset($attribs['auto_form_fields']['uidnumber'])) {
- $auth = Auth::get_instance($_SESSION['user']->get_domain());
- $conf = Conf::get_instance();
-
- $search = Array(
- 'params' => Array(
- 'objectclass' => Array(
- 'type' => 'exact',
- 'value' => 'posixaccount',
- ),
- ),
- );
+ $search = array(
+ 'params' => array(
+ 'objectclass' => array(
+ 'type' => 'exact',
+ 'value' => 'posixaccount',
+ ),
+ ),
+ );
+ $auth = Auth::get_instance($_SESSION['user']->get_domain());
+ $conf = Conf::get_instance();
$users = $auth->list_users(NULL, Array('uidnumber'), $search);
$highest_uidnumber = $conf->get('uidnumber_lower_barrier');
@@ -803,10 +781,7 @@ class kolab_api_service_form_value extends kolab_api_service
$auth = Auth::get_instance();
$conf = Conf::get_instance();
- $unique_attr = $conf->get('unique_attribute');
- if (!$unique_attr) {
- $unique_attr = 'nsuniqueid';
- }
+ $unique_attr = $this->unique_attribute();
$base_dn = $conf->get('user_base_dn');
if (!$base_dn) {
diff --git a/lib/api/kolab_api_service_role.php b/lib/api/kolab_api_service_role.php
index 18ebf19..cf1e339 100644
--- a/lib/api/kolab_api_service_role.php
+++ b/lib/api/kolab_api_service_role.php
@@ -137,16 +137,11 @@ class kolab_api_service_role extends kolab_api_service
public function role_effective_rights($getdata, $postdata)
{
$auth = Auth::get_instance();
- $conf = Conf::get_instance();
// Roles are special in that they are ldapsubentries.
if (!empty($getdata['role'])) {
- $unique_attr = $conf->get('unique_attribute');
- if (empty($unique_attr)) {
- $unique_attr = 'nsuniqueid';
- }
-
- $role = $auth->role_find_by_attribute(Array($unique_attr => $getdata['role']));
+ $unique_attr = $this->unique_attribute();
+ $role = $auth->role_find_by_attribute(Array($unique_attr => $getdata['role']));
if (is_array($role) && count($role) == 1) {
$role_dn = key($role);
diff --git a/lib/kolab_api_service.php b/lib/kolab_api_service.php
index e90aa87..3293bb5 100644
--- a/lib/kolab_api_service.php
+++ b/lib/kolab_api_service.php
@@ -403,7 +403,6 @@ abstract class kolab_api_service
return $attrs;
}
- $conf = Conf::get_instance();
$auth = Auth::get_instance();
$dn = key($attrs);
$attrs = $attrs[$dn];
@@ -434,11 +433,7 @@ abstract class kolab_api_service
}
// Insert the persistent, unique attribute
- $unique_attr = $conf->get('unique_attribute');
- if (!$unique_attr) {
- $unique_attr = 'nsuniqueid';
- }
-
+ $unique_attr = $this->unique_attribute();
if (!array_key_exists($unique_attr, $attrs)) {
$extra_attrs[] = $unique_attr;
}
@@ -458,4 +453,20 @@ abstract class kolab_api_service
return $attrs;
}
+ /**
+ * Returns name of unique attribute
+ *
+ * @return string Unique attribute name
+ */
+ protected function unique_attribute()
+ {
+ $conf = Conf::get_instance();
+ $unique_attr = $conf->get('unique_attribute');
+
+ if (!$unique_attr) {
+ $unique_attr = 'nsuniqueid';
+ }
+
+ return $unique_attr;
+ }
}