summaryrefslogtreecommitdiff
path: root/lib/kolab_api_service.php
diff options
context:
space:
mode:
authorAleksander Machniak <alec@alec.pl>2012-10-25 10:32:48 (GMT)
committerAleksander Machniak <alec@alec.pl>2012-10-25 10:32:48 (GMT)
commitf221c0def33046dc0aedbfe69256ccd350744227 (patch)
treed21cde9fae7dce435ac1fd2b055acf724acdf2c0 /lib/kolab_api_service.php
parent2cc2f49aaf644b6c32ad8eba3e3c375780ff2422 (diff)
downloadkolab-wap-f221c0def33046dc0aedbfe69256ccd350744227.tar.gz
Exclude attributes not listed in object type definition
Diffstat (limited to 'lib/kolab_api_service.php')
-rw-r--r--lib/kolab_api_service.php47
1 files changed, 26 insertions, 21 deletions
diff --git a/lib/kolab_api_service.php b/lib/kolab_api_service.php
index 7d9da8b..ac590d1 100644
--- a/lib/kolab_api_service.php
+++ b/lib/kolab_api_service.php
@@ -410,33 +410,35 @@ abstract class kolab_api_service
$dn = key($attrs);
$attrs = $attrs[$dn];
$extra_attrs = array();
-
- // add group type id to the result
- $attrs['type_id'] = $this->object_type_id($object_name, $attrs);
-
- if (empty($attrs['type_id'])) {
- if ($object_name == 'domain') {
- $attrs['type_id'] = 1;
- }
- }
+ $type_id = $this->object_type_id($object_name, $attrs);
+ $unique_attr = $this->unique_attribute();
// Search for attributes associated with the type_id that are not part
- // of the results returned earlier. Example: nsrole / nsroledn / aci, etc.
+ // of the result returned earlier. Example: nsrole / nsroledn / aci, etc.
// @TODO: this should go to LDAP class
- if ($attrs['type_id']) {
- $uta = $this->object_type_attributes($object_name, $attrs['type_id']);
-
- foreach ((array)$uta as $field_type => $attributes) {
- foreach ($attributes as $attribute => $data) {
- if (!array_key_exists($attribute, $attrs)) {
- $extra_attrs[] = $attribute;
- }
- }
- }
+ if ($type_id) {
+ $uta = $this->object_type_attributes($object_name, $type_id);
+
+ $attributes = array_merge(
+ array_keys((array) $uta['auto_form_fields']),
+ array_keys((array) $uta['form_fields']),
+ array_keys((array) $uta['fields'])
+ );
+ $attributes = array_filter($attributes);
+ $attributes = array_unique($attributes);
+
+ $object_attributes = array_keys($attrs);
+
+ // extra attributes
+ $extra_attrs = array_diff($attributes, $object_attributes);
+
+ // remove attributes not listed in object type definition
+ // @TODO: make this optional?
+ $attributes = array_flip(array_merge($attributes, array($unique_attr)));
+ $attrs = array_intersect_key($attrs, $attributes);
}
// Insert the persistent, unique attribute
- $unique_attr = $this->unique_attribute();
if (!array_key_exists($unique_attr, $attrs)) {
$extra_attrs[] = $unique_attr;
}
@@ -453,6 +455,9 @@ abstract class kolab_api_service
$attrs['id'] = $attrs[$unique_attr];
unset($attrs[$unique_attr]);
+ // add object type id to the result
+ $attrs['type_id'] = $type_id;
+
return $attrs;
}