Project

General

Profile

« Previous | Next » 

Revision 7b832340

Added by Marc Dequènes over 14 years ago

  • ID 7b8323404d9417cd4732eb199306b5fabbf82b84

[fix/evol] corrected before delete hook and added complete hook support for objects

View differences:

TODO
- find a way to restrict parent locations for new objects (regex for
<obj>/<item> string ? regex for DN ? OR/AND with both ? ???)
- search by family relationship ?
- whole hooks panoply for objects
- handle language subtypes ? (would need the RFC2798 preferredLanguage
parser out of the CyborgHood project)
- support X-ORDERED attributetypes ?
conf/ldap_shadows/shadows/MilkyPond/hooks/aspects/fs.rb
# should be in the configuration file
# TODO: should be in the configuration file, so find a way to get these parameters
MIN_UID = 10000
MAX_UID = 65535
STEP_UID = 100
conf/ldap_shadows/shadows/MilkyPond/hooks/objects/individual.rb
def self.hook_before_create(shadow, item)
unless item.attribute_present?('cn')
cn = item.surname || ""
cn = item.givenName + " " + cn if item.givenName
item.cn = cn
end
end
lib/ldap_shadows/object.rb
end
def delete
before_delete_job
before_delete_jobs
super
after_save_jobs
end
def delete_recursive
# TODO: recursive instanciation and reverse recursive hook calls
before_delete_job
before_delete_jobs
self.class.delete_all(nil, :scope => :sub, :base => self.dn)
after_delete_jobs
end
def self.hook_before_create(shadow, item)
end
def self.hook_before_modify(shadow, item)
end
def self.hook_before_delete(shadow, item)
end
def self.hook_after_create(shadow, item)
end
def self.hook_after_modify(shadow, item)
end
def self.hook_after_delete(shadow, item)
end
protected
def self.raise_error(msg)
raise ProcessingError, msg
end
def before_save_jobs
check_hooks_before(:save)
check_missing_attributes
......
end
def check_hooks_before(action)
case action
when :save
if self.new_entry?
self.class.hook_before_create(self.class.mapper, self)
else
self.class.hook_before_modify(self.class.mapper, self)
end
when :delete
self.class.hook_before_delete(self.class.mapper, self)
end
self.aspects.each do |aspect|
aklass = self.class.mapper.get_aspect_klass(aspect)
next if aklass.nil?
......
aklass.hook_after_delete(self.class.mapper, self)
end
end
case action
when :save
if self.new_entry?
self.class.hook_after_create(self.class.mapper, self)
else
self.class.hook_after_modify(self.class.mapper, self)
end
when :delete
self.class.hook_after_delete(self.class.mapper, self)
end
end
def fetch_attributes_data(attr_list, expert_attributes, admin_attributes)
lib/ldap_shadows/shadow.rb
object_name = object_name.to_sym
klass_name = self.class.object_name_to_klass_name(object_name)
klass_content = @config.load_hook_content(@name, 'object', object_name)
# create class
Objects.module_eval(<<-EOS)
class #{klass_name} < LdapObject; end
class #{klass_name} < LdapObject
#{klass_content}
end
EOS
# configure class

Also available in: Unified diff