Project

General

Profile

« Previous | Next » 

Revision fa116a1b

Added by Marc Dequènes about 15 years ago

  • ID fa116a1b44076e29791348378683a16b2085a71e

[fix/evol] correct a bug in the item creation when handling the parent parameter, allow specifying a default parent per object, and provides a new find_by_full_handle() handy method

View differences:

lib/ldap_shadows/elements/object.rb
class LdapObject < ActiveLdap::Base
include LdapElement
attr_reader :parent_changed
@relations_info = {}
class << self
......
# default
ldap_mapping :prefix => '', :classes => ['top'], :scope => :sub
def initialize(attributes = nil)
super(attributes)
@parent_changed = false
end
def handle
name = self[dn_attribute] || self.attributes[dn_attribute] || self.dn
name = name.first if name.is_a? Array
......
def modify_parent(op, parent_full_handle)
case op
when '='
when '+=', '-='
raise PreProcessingError, _("This operator is not possible for parent")
else
raise SyntaxError, _("Unknown operator '%s'") % op
end
# TODO: provide such facilities elsewhere
raise SyntaxError, _("Bad handle '%s' for parent") % name unless parent_full_handle =~ /^([a-zA-Z]+)\/(.+)$/
parent_obj_hdl = $1.downcase.singularize
parent_item_hdl = $2
parent_obj_klass = self.class.shadow.get_object(parent_obj_hdl)
raise PreProcessingError, _("No such object '%s'") % parent_obj_hdl if parent_obj_klass.nil?
begin
parent_item = parent_obj_klass.find(parent_item_hdl, :attributes => attr_list)
rescue ActiveLdap::EntryNotFound
raise PreProcessingError, _("No such item '%s/%s'") % [parent_obj_klass.handle, parent_item_hdl]
end
parent_item = self.class.find_by_full_handle(parent_full_handle)
p_hdl_restr = self.class.parameters[:mapping][:parent_handle_restrictions]
unless p_hdl_restr.nil? or parent_full_handle =~ Regexp.new(p_hdl_restr)
......
end
if self.new_entry?
self.base = parent_item.dn_obj - parent_obj_klass.base_obj
self.base = parent_item.dn_obj - parent_item.class.base_obj
else
raise PreProcessingError, _("Moving items is not yet implemented")
end
@parent_changed = true
end
def self.find_by_full_handle(full_handle)
raise PreProcessingError, _("Bad handle '%s'") % name unless full_handle =~ /^([a-zA-Z]+)\/(.+)$/
obj_hdl = $1.downcase.singularize
item_hdl = $2
obj_klass = self.shadow.get_object(obj_hdl)
raise PreProcessingError, _("No such object '%s'") % obj_hdl if obj_klass.nil?
begin
obj_klass.find(item_hdl, :attributes => [""])
rescue ActiveLdap::EntryNotFound
raise PreProcessingError, _("No such item '%s/%s'") % [obj_klass.handle, item_hdl]
end
end
def add_aspect(aspect_name)
......
check_hooks_before(:save)
check_missing_attributes
check_password
check_parent
end
def before_delete_jobs
......
self.userPassword = ActiveLdap::UserPassword.send(hash_func, self.userPassword)
end
def check_parent
if self.new_entry? and not self.parent_changed
parent_full_handle = self.class.parameters[:mapping][:default_parent]
if parent_full_handle
begin
parent_item = self.class.find_by_full_handle(parent_full_handle)
self.base = parent_item.dn_obj - parent_item.class.base_obj
rescue
raise PreProcessingError, _("Cannot create the item: bad default parent for this kind of object: %s") % $!
end
else
raise PreProcessingError, _("Cannot create the item: parent not specified and no default for such object")
end
end
end
def after_save_jobs
check_hooks_after(:save)
@parent_changed = false
end
def after_delete_jobs

Also available in: Unified diff