Revision 0032f05d
Added by Marc Dequènes about 15 years ago
- ID 0032f05db9b80b9b70babf66433dcf9c6a458182
lib/ldap_shadows/elements/object.rb | ||
---|---|---|
@relations_info = {}
|
||
|
||
class << self
|
||
attr_accessor :relations_info
|
||
protected :relations_info
|
||
attr_reader :relations_info
|
||
end
|
||
|
||
# default
|
||
... | ... | |
:read_only => rel[:read_only] || false
|
||
}
|
||
end
|
||
self.relations_info = object_relations_info
|
||
instance_variable_set(:@relations_info, object_relations_info)
|
||
end
|
||
|
||
# temporary method until active_ldap is fixed: return a DN object (see activeldap#23932)
|
||
... | ... | |
|
||
def human_name
|
||
attr_list = ['displayName', 'cn']
|
||
attr_list.unshift(self.class.presentation[:name_attribute]) if self.class.presentation.has_key?(:name_attribute)
|
||
attr_list.unshift(self.class.parameters[:presentation][:name_attribute]) if self.class.parameters[:presentation].has_key?(:name_attribute)
|
||
attr_list.each do |attr|
|
||
if attr == 'dn'
|
||
return self.dn
|
||
... | ... | |
|
||
def human_description
|
||
attr_list = ['description']
|
||
attr_list.unshift(self.class.presentation[:desc_attribute]) if self.class.presentation.has_key?(:desc_attribute)
|
||
attr_list.unshift(self.class.parameters[:presentation][:desc_attribute]) if self.class.parameters[:presentation].has_key?(:desc_attribute)
|
||
attr_list.each do |attr|
|
||
if self.attribute_present?(attr)
|
||
return self[attr].is_a?(Array) ? self[attr][0] : self[attr]
|
||
... | ... | |
def relations
|
||
rel_list = []
|
||
|
||
rel_list += self.class.presentation[:associated_relations] if self.class.presentation[:associated_relations]
|
||
rel_list += self.class.parameters[:presentation][:associated_relations] if self.class.parameters[:presentation][:associated_relations]
|
||
|
||
aspects.each do |aspect|
|
||
aspect_data = self.class.shadow.get_aspect(aspect)
|
||
... | ... | |
end
|
||
|
||
def self.possible_aspects
|
||
return [] unless self.presentation[:allowed_aspects]
|
||
self.presentation[:allowed_aspects].collect{|key| key.to_s }.sort
|
||
return [] unless self.parameters[:presentation][:allowed_aspects]
|
||
self.parameters[:presentation][:allowed_aspects].collect{|key| key.to_s }.sort
|
||
end
|
||
|
||
def aspects
|
||
present_aspects = []
|
||
(self.class.presentation[:allowed_aspects] || []).each do |aspect|
|
||
(self.class.parameters[:presentation][:allowed_aspects] || []).each do |aspect|
|
||
aspect_data = self.class.shadow.get_aspect(aspect)
|
||
aspect_mapping = aspect_data[:mapping]
|
||
present_aspects << aspect if self.classes & aspect_mapping[:classes] == aspect_mapping[:classes]
|
||
... | ... | |
def info_for_relation(rel)
|
||
return nil unless self.relations.include?(rel)
|
||
|
||
self.relations_info[rel.to_sym]
|
||
self.class.relations_info[rel.to_sym]
|
||
end
|
||
|
||
def organized_data
|
||
ignored_attrs = self.class.shadow.get_config[:presentation][:hidden_attributes] || []
|
||
ignored_attrs += self.class.presentation[:hidden_attributes] || []
|
||
ignored_attrs += self.class.parameters[:presentation][:hidden_attributes] || []
|
||
attr_list = self.nonempty_attributes - ignored_attrs
|
||
|
||
expert_attributes = (self.class.presentation[:expert_attributes] || [])
|
||
expert_attributes = (self.class.parameters[:presentation][:expert_attributes] || [])
|
||
admin_attributes = attr_list.select do |attr|
|
||
ActiveLdap::Base.schema.attribute(attr).operational?
|
||
end
|
||
... | ... | |
|
||
# manage general attributes
|
||
obj_info = {}
|
||
if self.class.presentation[:associate_unclaimed_attributes]
|
||
if self.class.parameters[:presentation][:associate_unclaimed_attributes]
|
||
taken_attr_list = attr_list
|
||
else
|
||
taken_attr_list = admin_attributes
|
||
if self.class.presentation.has_key?(:associated_attributes)
|
||
taken_attr_list += self.class.presentation[:associated_attributes]
|
||
if self.class.parameters[:presentation].has_key?(:associated_attributes)
|
||
taken_attr_list += self.class.parameters[:presentation][:associated_attributes]
|
||
end
|
||
taken_attr_list += self.class.possible_attributes
|
||
end
|
||
... | ... | |
attr_list -= taken_attr_list
|
||
|
||
# manage general relations
|
||
if self.class.presentation[:associated_relations]
|
||
taken_rel_list = self.class.presentation[:associated_relations] & rel_list
|
||
if self.class.parameters[:presentation][:associated_relations]
|
||
taken_rel_list = self.class.parameters[:presentation][:associated_relations] & rel_list
|
||
unless taken_rel_list.empty?
|
||
obj_info.merge!(fetch_relations_data(taken_rel_list, expert_attributes))
|
||
rel_list -= taken_rel_list
|
lib/ldap_shadows/shadow.rb | ||
---|---|---|
klass.instance_variable_set(:@parameters, e_def)
|
||
klass.meta_eval do
|
||
attr_reader :handle, :shadow, :parameters
|
||
protected :parameters
|
||
end
|
||
|
||
begin
|
Also available in: Unified diff
[cleanup] internal rework #3