summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Machniak <alec@alec.pl>2012-03-21 10:00:46 (GMT)
committerAleksander Machniak <alec@alec.pl>2012-03-21 10:00:46 (GMT)
commit5246c66ba6a80334d9d0c8860cf89b204fe92e48 (patch)
tree8bdbeea6864bb8517c68b9e70c39141a1f5fe8bb
parent964e16aed776930b935a5c2b4cec4e2a03960d59 (diff)
parent0d80bf0aa037051de17f9e6a1a412530da83028c (diff)
downloadkolab-wap-5246c66ba6a80334d9d0c8860cf89b204fe92e48.tar.gz
Merge branch 'master' of ssh://git.kolab.org/git/kolab-wap
-rw-r--r--lib/Auth/LDAP.php85
-rw-r--r--lib/api/kolab_api_service_form_value.php78
-rw-r--r--lib/api/kolab_api_service_group.php8
3 files changed, 123 insertions, 48 deletions
diff --git a/lib/Auth/LDAP.php b/lib/Auth/LDAP.php
index 6e4fab7..b5bd9c9 100644
--- a/lib/Auth/LDAP.php
+++ b/lib/Auth/LDAP.php
@@ -1107,7 +1107,6 @@ class LDAP
{
$group_members = array();
-
if (is_array($entry) && in_array('objectclass', $entry)) {
if (!in_array(array('groupofnames', 'groupofuniquenames', 'groupofurls'), $entry['objectclass'])) {
error_log("Called _list_groups_members on a non-group!");
@@ -1124,7 +1123,7 @@ class LDAP
continue;
}
- foreach ( $entry['objectclass'] as $num => $objectclass) {
+ foreach ($entry['objectclass'] as $objectclass) {
switch ($objectclass) {
case "groupofnames":
$group_members = array_merge($group_members, $this->_list_group_member($entry_dn, $entry));
@@ -1146,16 +1145,28 @@ class LDAP
{
error_log("Called _list_group_member(" . $dn . ")");
+ $group_members = array();
+ if (empty($entry['member'])) {
+ return $group_members;
+ }
+
// Use the member attributes to return an array of member ldap objects
// NOTE that the member attribute is supposed to contain a DN
- $group_members = array();
- for ($i = 0; $i < (count($entry['member'])-1); $i++) {
- $result = @ldap_read($this->_connection, $entry['member'][$i], '(objectclass=*)');
- $members = @ldap_get_entries($this->_connection, $result);
+ foreach ($entry['member'] as $member) {
+ $result = @ldap_read($this->_connection, $member, '(objectclass=*)');
+
+ if (!$result) {
+ continue;
+ }
+
+ $member_entry = $this->normalize_result(@ldap_get_entries($this->_connection, $result));
+ $group_members[$member] = array_pop($member_entry);
// Nested groups
- $group_group_members = $this->list_group_members($entry['member'][$i]);
- $group_members[] = array_filter(array_merge($group_group_members, $members));
+// $group_group_members = $this->_list_group_members($member, $member_entry);
+// if ($group_group_members) {
+// $group_members = array_merge($group_group_members, $group_members);
+// }
}
return array_filter($group_members);
@@ -1168,20 +1179,28 @@ class LDAP
// Use the member attributes to return an array of member ldap objects
// NOTE that the member attribute is supposed to contain a DN
$group_members = array();
- if (!isset($entry['uniquemember'])) {
+ if (empty($entry['uniquemember'])) {
return $group_members;
}
- for ($i = 0; $i < (count($entry['uniquemember'])-1); $i++) {
- $result = @ldap_read($this->_connection, $entry['uniquemember'][$i], '(objectclass=*)');
- $members = @ldap_get_entries($this->_connection, $result);
+ foreach ($entry['uniquemember'] as $member) {
+ $result = @ldap_read($this->_connection, $member, '(objectclass=*)');
+
+ if (!$result) {
+ continue;
+ }
+
+ $member_entry = $this->normalize_result(@ldap_get_entries($this->_connection, $result));
+ $group_members[$member] = array_pop($member_entry);
// Nested groups
- $group_group_members = $this->list_group_members($entry['uniquemember'][$i]);
- $group_members[] = array_filter(array_merge($group_group_members, $members));
+// $group_group_members = $this->_list_group_members($member, $member_entry);
+// if ($group_group_members) {
+// $group_members = array_merge($group_group_members, $group_members);
+// }
}
- return $group_members;
+ return array_filter($group_members);
}
private function _list_group_memberurl($dn, $entry)
@@ -1193,37 +1212,17 @@ class LDAP
$group_members = array();
- if (is_array($entry['memberurl'])) {
- foreach ($entry['memberurl'] as $url) {
- $ldap_uri_components = $this->_parse_memberurl($url);
- $entries = $this->normalize_result($this->search($ldap_uri_components[3], $ldap_uri_components[6]));
- foreach ($entries as $entry_dn => $_entry) {
- error_log("Found " . $entry_dn);
- $group_group_members = $this->_list_group_members($entry_dn);
-
- if ($group_group_members) {
- $group_members = array_merge($group_members, $group_group_members);
- }
- else {
- $group_members[] = $entry_dn;
- }
- }
- }
- }
- else {
- $ldap_uri_components = $this->_parse_memberurl($entry['memberurl']);
+ foreach ((array)$entry['memberurl'] as $url) {
+ $ldap_uri_components = $this->_parse_memberurl($url);
$entries = $this->normalize_result($this->search($ldap_uri_components[3], $ldap_uri_components[6]));
-
foreach ($entries as $entry_dn => $_entry) {
+ $group_members[$entry_dn] = $_entry;
error_log("Found " . $entry_dn);
- $group_group_members = $this->_list_group_members($entry_dn);
-
- if ($group_group_members) {
- $group_members = array_merge($group_members, $group_group_members);
- }
- else {
- $group_members[] = $entry_dn;
- }
+ // Nested group
+// $group_group_members = $this->_list_group_members($entry_dn, $_entry);
+// if ($group_group_members) {
+// $group_members = array_merge($group_members, $group_group_members);
+// }
}
}
diff --git a/lib/api/kolab_api_service_form_value.php b/lib/api/kolab_api_service_form_value.php
index ed226d7..6c7223e 100644
--- a/lib/api/kolab_api_service_form_value.php
+++ b/lib/api/kolab_api_service_form_value.php
@@ -32,7 +32,10 @@ class kolab_api_service_form_value extends kolab_api_service
public function capabilities($domain)
{
return array(
- 'generate' => 'r',
+ 'generate' => 'r',
+ 'validate' => 'r',
+ 'select_options' => 'r',
+ 'list_options' => 'r',
);
}
@@ -165,6 +168,50 @@ class kolab_api_service_form_value extends kolab_api_service
return $result;
}
+ /**
+ * Generation of values for fields of type LIST.
+ *
+ * @param array $getdata GET parameters
+ * @param array $postdata POST parameters. Required parameters:
+ * - attribute: attribute name
+ * - user_type_id or group_type_id: Type identifier
+ *
+ * @return array Response with attribute name as a key
+ */
+ public function list_options($getdata, $postdata)
+ {
+ if (isset($postdata['user_type_id'])) {
+ $attribs = $this->user_type_attributes($postdata['user_type_id']);
+ }
+ else if (isset($postdata['group_type_id'])) {
+ $attribs = $this->group_type_attributes($postdata['group_type_id']);
+ }
+ else {
+ $attribs = array();
+ }
+
+ $attr_name = $postdata['attribute'];
+ $result = array(
+ // return search value, so client can match response to request
+ 'search' => $postdata['search'],
+ 'list' => array(),
+ );
+
+ if (empty($attr_name)) {
+ return $result;
+ }
+
+ $method_name = 'list_options_' . strtolower($attr_name);
+
+ if (!method_exists($this, $method_name)) {
+ return $result;
+ }
+
+ $result['list'] = $this->{$method_name}($postdata, $attribs);
+
+ return $result;
+ }
+
private function generate_alias($postdata, $attribs = array())
{
return $this->generate_secondary_mail($postdata, $attribs);
@@ -370,4 +417,33 @@ class kolab_api_service_form_value extends kolab_api_service
return json_decode($attribute['option_values']);
}
+
+ private function list_options_uniquemember($postdata, $attribs = array())
+ {
+ $service = $this->controller->get_service('users');
+
+ $keyword = array('value' => $postdata['search']);
+ $data = array(
+ 'attributes' => array('displayname', 'mail'),
+ 'page_size' => 15,
+ 'search' => array(
+ 'displayname' => $keyword,
+ 'cn' => $keyword,
+ 'mail' => $keyword,
+ ),
+ );
+
+ $result = $service->users_list(null, $data);
+ $list = $result['list'];
+
+ // convert to key=>value array
+ foreach ($list as $idx => $value) {
+ $list[$idx] = $value['displayname'];
+ if (!empty($value['mail'])) {
+ $list[$idx] .= ' <' . $value['mail'] . '>';
+ }
+ }
+
+ return $list;
+ }
}
diff --git a/lib/api/kolab_api_service_group.php b/lib/api/kolab_api_service_group.php
index 9cf7b22..34843d9 100644
--- a/lib/api/kolab_api_service_group.php
+++ b/lib/api/kolab_api_service_group.php
@@ -130,9 +130,9 @@ class kolab_api_service_group extends kolab_api_service
$result = $auth->group_members_list($getdata['group']);
- if ($result) {
- return $result;
- }
- return FALSE;
+ return array(
+ 'list' => $result,
+ 'count' => count($result),
+ );
}
}