commit 7b8323404d9417cd4732eb199306b5fabbf82b84
Author: Marc Dequènes (Duck) <Duck@DuckCorp.org>
Date:   Sat Oct 17 13:34:59 2009 +0200

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

diff --git a/TODO b/TODO
index ced2279..1b4889a 100644
--- a/TODO
+++ b/TODO
@@ -6,7 +6,6 @@
 - 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 ?
diff --git a/conf/ldap_shadows/shadows/MilkyPond/hooks/aspects/fs.rb b/conf/ldap_shadows/shadows/MilkyPond/hooks/aspects/fs.rb
index ab5d1a8..e32fe6b 100644
--- a/conf/ldap_shadows/shadows/MilkyPond/hooks/aspects/fs.rb
+++ b/conf/ldap_shadows/shadows/MilkyPond/hooks/aspects/fs.rb
@@ -1,5 +1,5 @@
 
-# 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
diff --git a/conf/ldap_shadows/shadows/MilkyPond/hooks/objects/individual.rb b/conf/ldap_shadows/shadows/MilkyPond/hooks/objects/individual.rb
new file mode 100644
index 0000000..652126f
--- /dev/null
+++ b/conf/ldap_shadows/shadows/MilkyPond/hooks/objects/individual.rb
@@ -0,0 +1,9 @@
+
+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
+
diff --git a/lib/ldap_shadows/object.rb b/lib/ldap_shadows/object.rb
index 7533565..dc69c08 100755
--- a/lib/ldap_shadows/object.rb
+++ b/lib/ldap_shadows/object.rb
@@ -570,20 +570,42 @@ module LdapShadows
     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
@@ -594,6 +616,17 @@ module LdapShadows
     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?
@@ -649,6 +682,17 @@ module LdapShadows
           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)
diff --git a/lib/ldap_shadows/shadow.rb b/lib/ldap_shadows/shadow.rb
index 2a22bb1..d4dc17f 100755
--- a/lib/ldap_shadows/shadow.rb
+++ b/lib/ldap_shadows/shadow.rb
@@ -90,10 +90,13 @@ module LdapShadows
 
       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
