Project

General

Profile

« Previous | Next » 

Revision ed02e398

Added by Marc Dequènes over 15 years ago

  • ID ed02e3985f4e1887909846a88b8f18e134cdb753

[evol] associations are in fact relations, added primaryGroup relation

View differences:

config/test.conf
allowed_aspects: ['mail', 'fs', 'shell', 'ftp', 'web', 'jabber']
hidden_attributes: ['objectClass']
expert_attributes: ['uidNumber', 'gidNumber', 'gecos']
associations:
relations:
primaryGroup:
type: :has_many
object: group
foreign_key: gidNumber
primary_key: gidNumber
secondaryGroups:
type: :belongs_to
object: group
......
allowed_aspects: ['mail', 'fs', 'shell', 'ftp', 'web', 'jabber']
hidden_attributes: ['objectClass']
expert_attributes: ['uidNumber', 'gidNumber', 'gecos']
associations:
relations:
primaryGroup:
type: :has_many
object: group
foreign_key: gidNumber
primary_key: gidNumber
secondaryGroups:
type: :belongs_to
object: group
......
allowed_aspects: []
hidden_attributes: ['objectClass']
expert_attributes: ['gidNumber']
associations:
relations:
individuals:
type: :has_many
object: individual
......
mapping:
classes: ['emailUser']
presentation:
associations:
relations:
fs:
mapping:
classes: ['fsUser']
presentation:
associations:
relations:
shell:
mapping:
classes: ['shellUser']
presentation:
associated_attributes: ['loginShell']
associations:
relations:
ftp:
mapping:
classes: ['ftpUser']
presentation:
associations:
relations:
web:
mapping:
classes: ['webUser']
presentation:
associations:
relations:
jabber:
mapping:
classes: ['jabberUser']
presentation:
associations:
relations:
primary:
mapping:
classes: ['primaryAccount']
presentation:
associations:
relations:
locale/en.yml
uidNumber: "Identifier (numeric)"
uniqueMember: "Group member"
webVirtualHost: "Hosted Web Sites"
associations:
relations:
primaryGroup: "Primary Group"
secondaryGroups: "Secondary Groups"
aspects:
test.rb
return ""
end
alias :relations :associations
def aspects
present_aspects = []
self.class.presentation[:allowed_aspects].each do |aspect|
......
aspects = self.aspects
# first pass to take aspects forced associations into account
# first pass to take aspects forced relations into account
obj_aspects = {}
aspects.each do |aspect|
aspect_data = self.class.mapper.get_aspect(aspect)
......
klass.mapper = self
klass.ldap_mapping obj_mapping.reject {|key, val| not ActiveLdap::Base::VALID_LDAP_MAPPING_OPTIONS.include?(key) }
# store definition for later associations processing
# store definition for later relations processing
@object_definitions[obj_name] = obj_def
end
......
end
# run it _once_ when all objects are loaded
def load_associations
def load_relations
@object_definitions.each_pair do |obj_name, obj_def|
next unless obj_def.include?(:associations)
obj_assoc = obj_def[:associations]
next unless obj_def.include?(:relations)
obj_rel = obj_def[:relations]
klass = find_klass(obj_name)
obj_assoc.each_pair do |field_name, assoc|
foreign_klass = find_klass(assoc[:object])
assoc[:class_name] = foreign_klass.to_s
obj_rel.each_pair do |field_name, rel|
foreign_klass = find_klass(rel[:object])
rel[:class_name] = foreign_klass.to_s
case assoc[:type]
case rel[:type]
when :belongs_to
klass.belongs_to field_name, assoc.reject {|key, val| not ActiveLdap::Associations::ClassMethods::VALID_BELONGS_TO_OPTIONS.include?(key) }
klass.belongs_to field_name, rel.reject {|key, val| not ActiveLdap::Associations::ClassMethods::VALID_BELONGS_TO_OPTIONS.include?(key) }
when :has_many
klass.has_many field_name, assoc.reject {|key, val| not ActiveLdap::Associations::ClassMethods::VALID_HAS_MANY_OPTIONS.include?(key) }
klass.has_many field_name, rel.reject {|key, val| not ActiveLdap::Associations::ClassMethods::VALID_HAS_MANY_OPTIONS.include?(key) }
else
raise "bug in '#{obj_name}' object associations (wrong type)"
raise "bug in '#{obj_name}' object relations (wrong type)"
end
end
end
......
config[:objects].each_pair do |obj_name, obj_data|
ldapctl.load_object(obj_name, obj_data)
end
ldapctl.load_associations
ldapctl.load_relations
cmd = CmdParse::Command.new('list', false)
cmd.short_desc = "list objects"
......
end
end
puts "=== Associations ==="
item.associations.each do |assoc|
assoc_display_name = I18n.t(assoc, :scope => 'associations', :default => assoc.to_s)
puts "#{assoc_display_name}: " + item.send(assoc).collect{|g| g.name }.join(", ")
puts "=== Relations ==="
item.relations.each do |rel|
rel_display_name = I18n.t(rel, :scope => 'relations', :default => rel.to_s)
puts "#{rel_display_name}: " + item.send(rel).collect{|g| g.name }.join(", ")
end
end
cmdparser.add_command(cmd)

Also available in: Unified diff