Project

General

Profile

« Previous | Next » 

Revision 020c18fe

Added by Marc Dequènes over 14 years ago

  • ID 020c18fef17a781c2687cf73c9fcf02865432fb0

[fix/cleanup] handle the 'root' element better (even if ActiveLdap seems not to behave properly with the root DSA)

View differences:

lib/ldap_shadows/elements/object.rb
#++
require 'ldap_shadows/manipulation_helper'
module LdapShadows
module Elements
class LdapObject < ActiveLdap::Base
include LdapElement
FULL_HANDLE_PATTERN = /^([a-zA-Z_]+)\/(.+)$/
FULL_HANDLE_PATTERN = /^(?:root|([a-zA-Z_]+)\/(.+))$/
attr_reader :parent_changed
......
"#{self.class.handle}/#{self.handle}"
end
def self.looks_like_full_handle?(full_handle)
full_handle =~ FULL_HANDLE_PATTERN
$~
end
def self.cast
super
......
raise SyntaxError, _("Unknown operator '%s'") % op
end
parent_item = self.class.find_by_full_handle(parent_full_handle)
unless Manipulation.looks_like_full_handle?(parent_full_handle)
raise PreProcessingError, _("Parent for the item is not a full handle")
end
parent_item = Manipulation.find_item_by_full_handle(self.class.shadow, parent_full_handle)
if self.new_entry?
self.base = parent_item.dn_obj - parent_item.class.base_obj
......
@latest_parent_full_handle = parent_full_handle
end
def self.find_by_full_handle(full_handle)
if full_handle == "root" and LdapShadows.const_defined?('Manipulation')
raw_item_dn = ActiveLdap::Base.base.to_s
raw_item = ActiveLdap::Base.find(:first, :base => raw_item_dn, :scope => :base)
info = LdapShadows::Manipulation.raw_item_info(self.shadow, raw_item, raw_item_dn)
if info.nil?
raise PreProcessingError, _("No such item 'root'")
elsif info[:object].nil?
raise PreProcessingError, _("Root item found, but no corresponding object defined")
else
full_handle = info[:full_handle]
end
end
raise SyntaxError, _("Bad handle '%s'") % full_handle unless full_handle =~ FULL_HANDLE_PATTERN
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)
return unless self.class.possible_aspects.include?(aspect_name)
......
if self.new_entry? and not self.parent_changed
parent_full_handle = self.class.parameters[:mapping][:default_parent]
if parent_full_handle
unless Manipulation.looks_like_full_handle?(parent_full_handle)
raise PreProcessingError, _("Default parent for the item is not a full handle")
end
begin
parent_item = self.class.find_by_full_handle(parent_full_handle)
parent_item = Manipulation.find_item_by_full_handle(self.class.shadow, 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") % $!

Also available in: Unified diff