Revision b52f0f7d
Added by Marc Dequènes almost 15 years ago
- ID b52f0f7dd2e38270b9d123a28907deeba34dd249
lib/ldap_shadows/object.rb | ||
---|---|---|
|
||
ldap_mapping :prefix => '', :classes => ['top'], :scope => :sub
|
||
|
||
OPERATIONAL_ATTRIBUTES = ['creatorsName', 'createTimestamp', 'modifiersName', 'modifyTimestamp', 'structuralObjectClass', 'entryUUID']
|
||
|
||
# temporary method until active_ldap is fixed: return a DN object (see activeldap#23932)
|
||
def dn_obj
|
||
ActiveLdap::DistinguishedName.parse(self.dn)
|
||
... | ... | |
has_attribute?(field)
|
||
end
|
||
|
||
def validate_required_ldap_values
|
||
_schema = nil
|
||
# Make sure all MUST attributes have a value
|
||
entry_attribute.object_classes.each do |object_class|
|
||
object_class.must.each do |required_attribute|
|
||
# Normalize to ensure we catch schema problems
|
||
# needed?
|
||
real_name = to_real_attribute_name(required_attribute.name, true)
|
||
raise UnknownAttribute.new(required_attribute) if real_name.nil?
|
||
|
||
next if required_attribute.read_only?
|
||
|
||
value = @data[real_name] || []
|
||
next unless self.class.blank_value?(value)
|
||
|
||
# workaround for activeldap#26720 (not sure it works in all cases)
|
||
next unless @initial_attribute_list.nil? or @initial_attribute_list.include?(real_name)
|
||
|
||
_schema ||= schema
|
||
aliases = required_attribute.aliases.collect do |name|
|
||
self.class.human_attribute_name(name)
|
||
end
|
||
args = [self.class.human_object_class_name(object_class)]
|
||
if aliases.empty?
|
||
format = _("%{fn} is required attribute by objectClass '%s'")
|
||
else
|
||
format = _("%{fn} is required attribute by objectClass " \
|
||
"'%s': aliases: %s")
|
||
args << aliases.join(', ')
|
||
end
|
||
unless ActiveLdap.get_text_supported?
|
||
format = format.sub(/^%\{fn\} /, '')
|
||
end
|
||
errors.add(real_name, format % args)
|
||
end
|
||
end
|
||
end
|
||
|
||
def human_name
|
||
attr_list = ['displayName', 'cn']
|
||
attr_list.unshift(self.class.presentation[:name_attribute]) if self.class.presentation.has_key?(:name_attribute)
|
||
... | ... | |
end
|
||
|
||
def organized_data
|
||
expert_attributes = (self.class.presentation[:expert_attributes] || []) + OPERATIONAL_ATTRIBUTES
|
||
|
||
ignored_attrs = self.mapper.get_global_config[:hidden_attributes] || []
|
||
ignored_attrs += self.class.presentation[:hidden_attributes] || []
|
||
attr_list = self.nonempty_attributes - ignored_attrs
|
||
|
||
expert_attributes = (self.class.presentation[:expert_attributes] || [])
|
||
admin_attributes = attr_list.select do |attr|
|
||
ActiveLdap::Base.schema.attribute(attr).operational?
|
||
end
|
||
|
||
aspects = self.aspects
|
||
rel_list = self.possible_relations
|
||
|
||
... | ... | |
taken_attr_list = aspect_data[:presentation][:associated_attributes] & (attr_list + ignored_attrs)
|
||
unless taken_attr_list.empty?
|
||
obj_aspects[aspect] ||= {}
|
||
obj_aspects[aspect].merge!(fetch_attributes_data(taken_attr_list, expert_attributes))
|
||
obj_aspects[aspect].merge!(fetch_attributes_data(taken_attr_list, expert_attributes, admin_attributes))
|
||
attr_list -= taken_attr_list
|
||
end
|
||
end
|
||
... | ... | |
if self.class.presentation[:associate_unclaimed_attributes]
|
||
taken_attr_list = attr_list
|
||
else
|
||
taken_attr_list = []
|
||
taken_attr_list = admin_attributes
|
||
if self.class.presentation.has_key?(:associated_attributes)
|
||
taken_attr_list += self.class.presentation[:associated_attributes]
|
||
end
|
||
taken_attr_list += self.class.possible_attributes
|
||
end
|
||
taken_attr_list = taken_attr_list.uniq & attr_list
|
||
obj_info = fetch_attributes_data(taken_attr_list, expert_attributes)
|
||
obj_info = fetch_attributes_data(taken_attr_list, expert_attributes, admin_attributes)
|
||
attr_list -= taken_attr_list
|
||
|
||
# manage general relations
|
||
... | ... | |
aspects.each do |aspect|
|
||
taken_attr_list = (self.class.possible_attributes_for_aspect(aspect) & attr_list)
|
||
obj_aspects[aspect] ||= {}
|
||
obj_aspects[aspect].merge!(fetch_attributes_data(taken_attr_list, expert_attributes))
|
||
obj_aspects[aspect].merge!(fetch_attributes_data(taken_attr_list, expert_attributes, admin_attributes))
|
||
attr_list -= taken_attr_list
|
||
|
||
break if attr_list.empty?
|
||
... | ... | |
end
|
||
end
|
||
|
||
def fetch_attributes_data(attr_list, expert_attributes)
|
||
def fetch_attributes_data(attr_list, expert_attributes, admin_attributes)
|
||
attr_data = self.attributes.collect do |key, val|
|
||
if attr_list.include?(key)
|
||
[key, {
|
||
:value => val,
|
||
:multiple => (val.is_a?(Array) ? val.size : 1),
|
||
:expert => expert_attributes.include?(key),
|
||
:admin => admin_attributes.include?(key),
|
||
:binary => ActiveLdap::Base.schema.attribute(key).binary?
|
||
}]
|
||
else
|
||
... | ... | |
:value => value,
|
||
:multiple => multiple,
|
||
:expert => expert_attributes.include?(rel_key),
|
||
:admin => false,
|
||
:binary => false
|
||
}]
|
||
end
|
||
end
|
||
Hash[rel_data.compact]
|
||
end
|
||
|
||
def load_initial_attribute_list
|
||
@initial_attribute_list ||= self.nonempty_attributes
|
||
end
|
||
end
|
||
end
|
||
|
Also available in: Unified diff
[evol] move all activeldap workarounds away, and properly manage operational attributes (using schema instead of a hardcoded list)