commit 428fdd46a8f2ab849d47b17123cf6413d6cbfacc
Author: Marc Dequènes (Duck) <Duck@DuckCorp.org>
Date:   Sun Oct 25 14:53:32 2009 +0100

    [cleanup] reorganized config

diff --git a/conf/ldap_shadows/shadows/MilkyPond/aspects/fs.conf b/conf/ldap_shadows/shadows/MilkyPond/aspects/fs.conf
index 9fc17a7..749cedb 100644
--- a/conf/ldap_shadows/shadows/MilkyPond/aspects/fs.conf
+++ b/conf/ldap_shadows/shadows/MilkyPond/aspects/fs.conf
@@ -1,7 +1,6 @@
 ---
 mapping:
   classes: ['fsUser']
-presentation:
   associated_relations: ['primaryGroup', 'secondaryGroups']
 relations:
   primaryGroup:
diff --git a/conf/ldap_shadows/shadows/MilkyPond/aspects/primary.conf b/conf/ldap_shadows/shadows/MilkyPond/aspects/primary.conf
index 8d652a8..1c1bc4b 100644
--- a/conf/ldap_shadows/shadows/MilkyPond/aspects/primary.conf
+++ b/conf/ldap_shadows/shadows/MilkyPond/aspects/primary.conf
@@ -1,5 +1,4 @@
 ---
 mapping:
   classes: ['primaryAccount']
-presentation:
   associated_attributes: ['uid']
diff --git a/conf/ldap_shadows/shadows/MilkyPond/aspects/shell.conf b/conf/ldap_shadows/shadows/MilkyPond/aspects/shell.conf
index 5299105..4b2fd00 100644
--- a/conf/ldap_shadows/shadows/MilkyPond/aspects/shell.conf
+++ b/conf/ldap_shadows/shadows/MilkyPond/aspects/shell.conf
@@ -2,5 +2,4 @@
 mapping:
   classes: ['shellUser']
   depend_aspects: ['primary', 'fs']
-presentation:
   associated_attributes: ['loginShell']
diff --git a/conf/ldap_shadows/shadows/MilkyPond/objects/bot.conf b/conf/ldap_shadows/shadows/MilkyPond/objects/bot.conf
index 9f484a9..4234219 100644
--- a/conf/ldap_shadows/shadows/MilkyPond/objects/bot.conf
+++ b/conf/ldap_shadows/shadows/MilkyPond/objects/bot.conf
@@ -4,7 +4,7 @@ mapping:
   prefix: ''
   classes: ['bot']
   sort_by: uid
+  possible_aspects: ['primary', 'mail', 'fs', 'shell', 'ftp', 'web', 'jabber']
 presentation:
-  allowed_aspects: ['primary', 'mail', 'fs', 'shell', 'ftp', 'web', 'jabber']
   hidden_attributes: ['uid']
   expert_attributes: ['uidNumber', 'gidNumber', 'gecos']
diff --git a/conf/ldap_shadows/shadows/MilkyPond/objects/entity.conf b/conf/ldap_shadows/shadows/MilkyPond/objects/entity.conf
index 56b4dac..be8dafe 100644
--- a/conf/ldap_shadows/shadows/MilkyPond/objects/entity.conf
+++ b/conf/ldap_shadows/shadows/MilkyPond/objects/entity.conf
@@ -5,10 +5,10 @@ mapping:
   classes: ['entity']
   excluded_classes: ['dcObject']
   sort_by: o
+  associated_relations: ['foundersIndividuals', 'foundersEntities']
 presentation:
   name_attribute: o
   hidden_attributes: ['founder']
-  associated_relations: ['foundersIndividuals', 'foundersEntities']
 relations:
   foundersIndividuals:
     type: has_many
diff --git a/conf/ldap_shadows/shadows/MilkyPond/objects/group.conf b/conf/ldap_shadows/shadows/MilkyPond/objects/group.conf
index 5ea6a13..b10f739 100644
--- a/conf/ldap_shadows/shadows/MilkyPond/objects/group.conf
+++ b/conf/ldap_shadows/shadows/MilkyPond/objects/group.conf
@@ -4,10 +4,10 @@ mapping:
   prefix: ''
   classes: ['posixGroup', 'groupOfMembers']
   sort_by: cn
+  associated_relations: ['individualsPrimaryMembers', 'botsPrimaryMembers', 'individualsSecondaryMembers', 'botsSecondaryMembers']
 presentation:
   hidden_attributes: ['uniqueMember']
   expert_attributes: ['gidNumber']
-  associated_relations: ['individualsPrimaryMembers', 'botsPrimaryMembers', 'individualsSecondaryMembers', 'botsSecondaryMembers']
 relations:
   individualsPrimaryMembers:
     type: belongs_to
diff --git a/conf/ldap_shadows/shadows/MilkyPond/objects/individual.conf b/conf/ldap_shadows/shadows/MilkyPond/objects/individual.conf
index ae744b0..b37985d 100644
--- a/conf/ldap_shadows/shadows/MilkyPond/objects/individual.conf
+++ b/conf/ldap_shadows/shadows/MilkyPond/objects/individual.conf
@@ -4,7 +4,7 @@ mapping:
   prefix: ''
   classes: ['individual']
   sort_by: uid
+  possible_aspects: ['primary', 'mail', 'fs', 'shell', 'ftp', 'web', 'jabber']
 presentation:
-  allowed_aspects: ['primary', 'mail', 'fs', 'shell', 'ftp', 'web', 'jabber']
   hidden_attributes: ['uid']
   expert_attributes: ['uidNumber', 'gidNumber', 'gecos']
diff --git a/conf/ldap_shadows/shadows/MilkyPond/objects/secondary_account.conf b/conf/ldap_shadows/shadows/MilkyPond/objects/secondary_account.conf
index a5c9cb8..d8360c3 100644
--- a/conf/ldap_shadows/shadows/MilkyPond/objects/secondary_account.conf
+++ b/conf/ldap_shadows/shadows/MilkyPond/objects/secondary_account.conf
@@ -4,5 +4,4 @@ mapping:
   prefix: ''
   classes: ['secondaryAccount']
   sort_by: uid
-presentation:
-  allowed_aspects: ['mail', 'fs', 'shell', 'ftp', 'web', 'jabber']
+  possible_aspects: ['mail', 'fs', 'shell', 'ftp', 'web', 'jabber']
diff --git a/conf/ldap_shadows/shadows/MilkyPond/objects/system_account.conf b/conf/ldap_shadows/shadows/MilkyPond/objects/system_account.conf
index ce25a5f..905ef33 100644
--- a/conf/ldap_shadows/shadows/MilkyPond/objects/system_account.conf
+++ b/conf/ldap_shadows/shadows/MilkyPond/objects/system_account.conf
@@ -4,5 +4,5 @@ mapping:
   prefix: ''
   classes: ['systemAccount']
   sort_by: uid
-presentation:
-  allowed_aspects: ['mail', 'fs', 'shell', 'ftp', 'web', 'jabber']
+  possible_aspects: ['mail', 'fs', 'shell', 'ftp', 'web', 'jabber']
+presentation: {}
diff --git a/data/ldap_shadows/default_config/aspect.yaml b/data/ldap_shadows/default_config/aspect.yaml
index 736a159..d908da0 100644
--- a/data/ldap_shadows/default_config/aspect.yaml
+++ b/data/ldap_shadows/default_config/aspect.yaml
@@ -2,9 +2,8 @@
 mapping:
   classes: []
   depend_aspects: []
-presentation:
+  associated_relations: []
   associated_attributes: []
   associate_unclaimed_attributes: false
-  associated_relations: []
 relations: {}
 plugin: {}
diff --git a/data/ldap_shadows/default_config/object.yaml b/data/ldap_shadows/default_config/object.yaml
index 21b9cba..afeab6d 100644
--- a/data/ldap_shadows/default_config/object.yaml
+++ b/data/ldap_shadows/default_config/object.yaml
@@ -1,11 +1,11 @@
 ---
-mapping: {}
+mapping:
+  possible_aspects: []
+  associated_relations: []
+  associated_attributes: []
 presentation:
   name_attribute:
-  allowed_aspects: []
-  associated_attributes: []
   hidden_attributes: []
   expert_attributes: []
-  associated_relations: []
 relations: {}
 plugin: {}
diff --git a/data/ldap_shadows/schema/aspect.yaml b/data/ldap_shadows/schema/aspect.yaml
index b2f9c40..d52d836 100644
--- a/data/ldap_shadows/schema/aspect.yaml
+++ b/data/ldap_shadows/schema/aspect.yaml
@@ -15,18 +15,15 @@ mapping:
         type: seq
         sequence:
           - type: str
-  "presentation":
-    type: map
-    mapping:
-      "associated_attributes":
+      "associated_relations":
         type: seq
         sequence:
           - type: str
-      "associate_unclaimed_attributes": {type: bool}
-      "associated_relations":
+      "associated_attributes":
         type: seq
         sequence:
           - type: str
+      "associate_unclaimed_attributes": {type: bool}
   "relations":
     type: map
     mapping:
diff --git a/data/ldap_shadows/schema/object.yaml b/data/ldap_shadows/schema/object.yaml
index 8b2599a..e8c7c15 100644
--- a/data/ldap_shadows/schema/object.yaml
+++ b/data/ldap_shadows/schema/object.yaml
@@ -6,15 +6,15 @@ mapping:
     required: true
     name: ObjectMapping
     mapping:
+      "possible_aspects":
+        type: seq
+        sequence:
+          - type: str
       =: {type: any}
   "presentation":
     type: map
     mapping:
       "name_attribute": {type: str}
-      "allowed_aspects":
-        type: seq
-        sequence:
-          - type: str
       "hidden_attributes":
         type: seq
         sequence:
diff --git a/lib/ldap_shadows/config.rb b/lib/ldap_shadows/config.rb
index e8fbed3..4e3168d 100644
--- a/lib/ldap_shadows/config.rb
+++ b/lib/ldap_shadows/config.rb
@@ -116,7 +116,7 @@ module LdapShadows
       @shadows[shadow_name]
     end
 
-    def parse(def_name, type, def_data_raw, validate = true)
+    def parse(def_name, type, def_data_raw, validate = true, extra_data = nil)
       schema = load_schema(type)
 
       if validate
@@ -128,9 +128,10 @@ module LdapShadows
         when 'aspect'
           AspectValidator
         else
-          Kwalify::Validator
+          LdapShadowsValidator
         end
         validator = validator_klass.new(schema)
+        validator.extra_data = extra_data
       else
         validator = nil
       end
@@ -212,6 +213,8 @@ module LdapShadows
     end
 
     class LdapShadowsValidator < Kwalify::Validator
+      attr_accessor :extra_data
+
       ## hook method called by Validator#validate()
       def validate_hook(value, rule, path, errors)
         msg_list = []
@@ -223,6 +226,9 @@ module LdapShadows
         end
       end
 
+      def validate_hook_in(value, rule, path, msg_list)
+      end
+
       def validate_hook_relation(value, rule, path, msg_list)
         extra_params = [:type, :object]
 
@@ -261,7 +267,8 @@ module LdapShadows
         case rule.name
         when 'ObjectMapping'
           ne_params = value.keys.collect{|k| k.to_sym } -
-            ActiveLdap::Base::VALID_LDAP_MAPPING_OPTIONS
+            ActiveLdap::Base::VALID_LDAP_MAPPING_OPTIONS -
+            @extra_data[:default_parameters][:mapping].keys
           unless ne_params.empty?
             msg_list << _("nonexisting object mapping parameters (%s)") % ne_params.join(", ")
           end
diff --git a/lib/ldap_shadows/elements/object.rb b/lib/ldap_shadows/elements/object.rb
index 7c2a65d..435247e 100755
--- a/lib/ldap_shadows/elements/object.rb
+++ b/lib/ldap_shadows/elements/object.rb
@@ -44,7 +44,7 @@ module Elements
     def self.cast
       super
 
-      ldap_mapping self.parameters[:mapping]
+      ldap_mapping self.parameters[:mapping].reject {|key, val| self.default_parameters[:mapping].keys.include?(key)}
     end
 
     def self.cast_relations
@@ -124,17 +124,17 @@ module Elements
     end
 
     def relations
-      rel_list = self.class.parameters[:presentation][:associated_relations]
+      rel_list = self.class.parameters[:mapping][:associated_relations]
 
       aspects.values.each do |aspect|
-        rel_list += aspect.parameters[:presentation][:associated_relations]
+        rel_list += aspect.parameters[:mapping][:associated_relations]
       end
 
       rel_list & possible_relations
     end
 
     def self.possible_aspects
-      self.parameters[:presentation][:allowed_aspects].sort
+      self.parameters[:mapping][:possible_aspects].sort
     end
 
     def aspects
@@ -165,8 +165,8 @@ module Elements
       self.aspects.values.each do |aspect|
         aspect_data = aspect.parameters
 
-        unless aspect_data[:presentation][:associated_attributes].empty?
-          taken_attr_list = aspect_data[:presentation][:associated_attributes] & (attr_list + ignored_attrs)
+        unless aspect_data[:mapping][:associated_attributes].empty?
+          taken_attr_list = aspect_data[:mapping][:associated_attributes] & (attr_list + ignored_attrs)
           unless taken_attr_list.empty?
             obj_aspects[aspect.handle] ||= {}
             obj_aspects[aspect.handle].merge!(fetch_attributes_data(taken_attr_list, expert_attributes, admin_attributes))
@@ -174,8 +174,8 @@ module Elements
           end
         end
 
-        unless aspect_data[:presentation][:associated_relations].empty?
-          taken_rel_list = aspect_data[:presentation][:associated_relations] & rel_list
+        unless aspect_data[:mapping][:associated_relations].empty?
+          taken_rel_list = aspect_data[:mapping][:associated_relations] & rel_list
           unless taken_rel_list.empty?
             obj_aspects[aspect.handle] ||= {}
             obj_aspects[aspect.handle].merge!(fetch_relations_data(taken_rel_list, expert_attributes))
@@ -186,11 +186,11 @@ module Elements
 
       # manage general attributes
       obj_info = {}
-      if self.class.parameters[:presentation][:associate_unclaimed_attributes]
+      if self.class.parameters[:mapping][:associate_unclaimed_attributes]
         taken_attr_list = attr_list
       else
         taken_attr_list = admin_attributes
-        taken_attr_list += self.class.parameters[:presentation][:associated_attributes]
+        taken_attr_list += self.class.parameters[:mapping][:associated_attributes]
         taken_attr_list += self.class.possible_attributes
       end
       taken_attr_list = taken_attr_list.uniq & attr_list
@@ -198,8 +198,8 @@ module Elements
       attr_list -= taken_attr_list
 
       # manage general relations
-      if self.class.parameters[:presentation][:associated_relations]
-        taken_rel_list = self.class.parameters[:presentation][:associated_relations] & rel_list
+      if self.class.parameters[:mapping][:associated_relations]
+        taken_rel_list = self.class.parameters[:mapping][:associated_relations] & rel_list
         unless taken_rel_list.empty?
           obj_info.merge!(fetch_relations_data(taken_rel_list, expert_attributes))
           rel_list -= taken_rel_list
diff --git a/lib/ldap_shadows/shadow.rb b/lib/ldap_shadows/shadow.rb
index 57c9880..b94d80b 100755
--- a/lib/ldap_shadows/shadow.rb
+++ b/lib/ldap_shadows/shadow.rb
@@ -185,8 +185,8 @@ module LdapShadows
         raise PreProcessingError, _("Element '%s' for model '%s' as already been defined") % [e_name, e_type]
       end
 
-      e_def = @config.parse(e_name, e_type, e_def_raw)
       e_default_parameters = @config.load_default_config(e_type)
+      e_def = @config.parse(e_name, e_type, e_def_raw, true, {:default_parameters => e_default_parameters})
       e_config = e_default_parameters.recursive_merge(e_def)
 
       klass = @container.module_eval(<<-EOS)
@@ -195,9 +195,10 @@ module LdapShadows
       klass.instance_variable_set(:@handle, e_name)
       klass.instance_variable_set(:@shadow, self)
       klass.instance_variable_set(:@config, @config)
+      klass.instance_variable_set(:@default_parameters, e_default_parameters)
       klass.instance_variable_set(:@parameters, e_config)
       klass.meta_eval do
-        attr_reader :handle, :shadow, :config, :parameters
+        attr_reader :handle, :shadow, :config, :default_parameters, :parameters
       end
 
       begin
@@ -212,7 +213,7 @@ module LdapShadows
 
       klass
     rescue
-      raise PreProcessingError, _("Could not create element '%s' for model '%s': %s") % [e_type, e_name, $!]
+      raise PreProcessingError, _("Could not create element '%s' for model '%s': %s") % [e_name, e_type, $!]
     end
   end
 end
