Revision e34242cc
Added by Marc Dequènes about 15 years ago
- ID e34242cc8b82ffc5af17cab2ed570334fa81d0ac
lib/ldap_shadows/object.rb | ||
---|---|---|
|
||
module LdapShadows
|
||
class LdapObject < ActiveLdap::Base
|
||
class_inheritable_accessor :handle, :presentation, :mapper, :relations_info
|
||
class_inheritable_accessor :handle, :presentation, :shadow, :relations_info
|
||
|
||
ldap_mapping :prefix => '', :classes => ['top'], :scope => :sub
|
||
|
||
... | ... | |
rel_list += self.class.presentation[:associated_relations] if self.class.presentation[:associated_relations]
|
||
|
||
aspects.each do |aspect|
|
||
aspect_data = self.class.mapper.get_aspect(aspect)
|
||
aspect_data = self.class.shadow.get_aspect(aspect)
|
||
if defined?(aspect_data[:presentation][:associated_relations]) and aspect_data[:presentation][:associated_relations]
|
||
rel_list += aspect_data[:presentation][:associated_relations]
|
||
end
|
||
... | ... | |
def aspects
|
||
present_aspects = []
|
||
(self.class.presentation[:allowed_aspects] || []).each do |aspect|
|
||
aspect_data = self.class.mapper.get_aspect(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]
|
||
end
|
||
... | ... | |
end
|
||
|
||
def self.possible_attributes_for_aspect(aspect)
|
||
aspect_data = self.mapper.get_aspect(aspect)
|
||
aspect_data = self.shadow.get_aspect(aspect)
|
||
self.objectclasses_attr_list(aspect_data[:mapping][:classes])
|
||
end
|
||
|
||
... | ... | |
end
|
||
|
||
def organized_data
|
||
ignored_attrs = self.mapper.get_shadow_config[:hidden_attributes] || []
|
||
ignored_attrs = self.shadow.get_shadow_config[:hidden_attributes] || []
|
||
ignored_attrs += self.class.presentation[:hidden_attributes] || []
|
||
attr_list = self.nonempty_attributes - ignored_attrs
|
||
|
||
... | ... | |
# first pass to take aspects forced relations into account
|
||
obj_aspects = {}
|
||
aspects.each do |aspect|
|
||
aspect_data = self.class.mapper.get_aspect(aspect)
|
||
aspect_data = self.class.shadow.get_aspect(aspect)
|
||
|
||
if defined?(aspect_data[:presentation][:associated_attributes]) and aspect_data[:presentation][:associated_attributes]
|
||
taken_attr_list = aspect_data[:presentation][:associated_attributes] & (attr_list + ignored_attrs)
|
||
... | ... | |
|
||
def self.ldap_search_string_aspects(field, op, val_list)
|
||
ldap_search_parts = val_list.split(",").collect do |val|
|
||
aspect_data = self.mapper.get_aspect(val)
|
||
aspect_data = self.shadow.get_aspect(val)
|
||
raise PreProcessingError, _("No such aspect '%s'") % val if aspect_data.nil?
|
||
|
||
ldap_classes = aspect_data[:mapping][:classes]
|
||
... | ... | |
end
|
||
|
||
def self.find_raw_item_object(raw_item)
|
||
self.mapper.objects.each do |obj_hdl|
|
||
self.shadow.objects.each do |obj_hdl|
|
||
obj_klass = $ldapctl.find_klass(obj_hdl)
|
||
ldap_classes = obj_klass.required_classes
|
||
return obj_hdl if raw_item.classes & ldap_classes == ldap_classes
|
||
... | ... | |
def add_aspect(aspect)
|
||
return unless self.class.possible_aspects.include?(aspect)
|
||
|
||
aspect_data = self.mapper.get_aspect(aspect)
|
||
aspect_data = self.shadow.get_aspect(aspect)
|
||
add_class(*aspect_data[:mapping][:classes])
|
||
|
||
# recursive dependency enforcement
|
||
... | ... | |
def remove_aspect(aspect)
|
||
return unless self.class.possible_aspects.include?(aspect)
|
||
|
||
aspect_data = self.mapper.get_aspect(aspect)
|
||
aspect_data = self.shadow.get_aspect(aspect)
|
||
remove_class(*aspect_data[:mapping][:classes])
|
||
end
|
||
|
||
... | ... | |
case action
|
||
when :save
|
||
if self.new_entry?
|
||
self.class.hook_before_create(self.class.mapper, self)
|
||
self.class.hook_before_create(self.class.shadow, self)
|
||
else
|
||
self.class.hook_before_modify(self.class.mapper, self)
|
||
self.class.hook_before_modify(self.class.shadow, self)
|
||
end
|
||
when :delete
|
||
self.class.hook_before_delete(self.class.mapper, self)
|
||
self.class.hook_before_delete(self.class.shadow, self)
|
||
end
|
||
|
||
self.aspects.each do |aspect|
|
||
aklass = self.class.mapper.get_aspect_klass(aspect)
|
||
aklass = self.class.shadow.get_aspect_klass(aspect)
|
||
next if aklass.nil?
|
||
|
||
case action
|
||
when :save
|
||
if self.new_entry?
|
||
aklass.hook_before_create(self.class.mapper, self)
|
||
aklass.hook_before_create(self.class.shadow, self)
|
||
else
|
||
aklass.hook_before_modify(self.class.mapper, self)
|
||
aklass.hook_before_modify(self.class.shadow, self)
|
||
end
|
||
when :delete
|
||
aklass.hook_before_delete(self.class.mapper, self)
|
||
aklass.hook_before_delete(self.class.shadow, self)
|
||
end
|
||
end
|
||
end
|
||
... | ... | |
|
||
def check_hooks_after(action)
|
||
self.aspects.each do |aspect|
|
||
aklass = self.class.mapper.get_aspect_klass(aspect)
|
||
aklass = self.class.shadow.get_aspect_klass(aspect)
|
||
next if aklass.nil?
|
||
|
||
case action
|
||
when :save
|
||
if self.new_entry?
|
||
aklass.hook_after_create(self.class.mapper, self)
|
||
aklass.hook_after_create(self.class.shadow, self)
|
||
else
|
||
aklass.hook_after_modify(self.class.mapper, self)
|
||
aklass.hook_after_modify(self.class.shadow, self)
|
||
end
|
||
when :delete
|
||
aklass.hook_after_delete(self.class.mapper, self)
|
||
aklass.hook_after_delete(self.class.shadow, self)
|
||
end
|
||
end
|
||
|
||
case action
|
||
when :save
|
||
if self.new_entry?
|
||
self.class.hook_after_create(self.class.mapper, self)
|
||
self.class.hook_after_create(self.class.shadow, self)
|
||
else
|
||
self.class.hook_after_modify(self.class.mapper, self)
|
||
self.class.hook_after_modify(self.class.shadow, self)
|
||
end
|
||
when :delete
|
||
self.class.hook_after_delete(self.class.mapper, self)
|
||
self.class.hook_after_delete(self.class.shadow, self)
|
||
end
|
||
end
|
||
|
lib/ldap_shadows/shadow.rb | ||
---|---|---|
def initialize(name)
|
||
@name = name
|
||
|
||
LdapShadows::LdapObject.mapper = self
|
||
LdapShadows::LdapObject.shadow = self
|
||
|
||
@config = Config.instance
|
||
|
||
... | ... | |
klass = find_klass(object_name)
|
||
klass.handle = object_name
|
||
klass.presentation = object_def[:presentation]
|
||
klass.mapper = self
|
||
klass.shadow = self
|
||
klass.ldap_mapping object_def[:mapping]
|
||
|
||
# store definition for later relations processing
|
Also available in: Unified diff
[cleanup] s/mapper/shadow/ for consistency