Revision 8519224c
Added by Marc Dequènes over 15 years ago
- ID 8519224cb860a585d04e0a8861d31f0ca0a04048
config/test.conf | ||
---|---|---|
desc_attribute: description
|
||
optional_classes: []
|
||
allowed_aspects: []
|
||
hidden_attributes: ['objectClass']
|
||
hidden_attributes: ['objectClass', 'uniqueMember']
|
||
expert_attributes: ['gidNumber']
|
||
relations:
|
||
individuals:
|
||
individualsPrimaryMembers:
|
||
type: :belongs_to
|
||
object: individual
|
||
many: gidNumber
|
||
foreign_key: gidNumber
|
||
botsPrimaryMembers:
|
||
type: :belongs_to
|
||
object: bot
|
||
many: gidNumber
|
||
foreign_key: gidNumber
|
||
individualsSecondaryMembers:
|
||
type: :has_many
|
||
object: individual
|
||
foreign_key: uniqueMember
|
||
primary_key: dn
|
||
bots:
|
||
botsSecondaryMembers:
|
||
type: :has_many
|
||
object: bot
|
||
foreign_key: uniqueMember
|
||
... | ... | |
mapping:
|
||
classes: ['fsUser']
|
||
presentation:
|
||
associated_relations: ['primaryGroup', 'secondaryGroups']
|
||
relations:
|
||
shell:
|
||
mapping:
|
locale/en.yml | ||
---|---|---|
relations:
|
||
primaryGroup: "Primary Group"
|
||
secondaryGroups: "Secondary Groups"
|
||
individualsPrimaryMembers: "Primary Members Individuals"
|
||
botsPrimaryMembers: "Primary Members Bots"
|
||
individualsSecondaryMembers: "Secondary Members Individuals"
|
||
botsSecondaryMembers: "Secondary Members Bots"
|
||
aspects:
|
||
ftp: "FTP Account"
|
||
web: "Web Account"
|
test.rb | ||
---|---|---|
return ""
|
||
end
|
||
|
||
alias :relations :associations
|
||
def relations
|
||
self.associations.collect {|assoc| assoc.to_s }
|
||
end
|
||
|
||
def aspects
|
||
present_aspects = []
|
||
... | ... | |
list
|
||
end
|
||
|
||
def fetch_attributes_data(attr_list, options = {})
|
||
attr_data = self.attributes.select {|key, val| attr_list.include?(key) and not (options[:skip_binary] and ActiveLdap::Base.schema.attribute(key).binary?) }
|
||
Hash[attr_data]
|
||
end
|
||
|
||
def organized_attributes(options = {})
|
||
def organized_data(options = {})
|
||
options.symbolize_keys!
|
||
options[:expert] ||= false;
|
||
options[:skip_binary] ||= false;
|
||
... | ... | |
|
||
aspects = self.aspects
|
||
|
||
# ignore children at the moment
|
||
rel_list = self.relations - ['children']
|
||
|
||
# first pass to take aspects forced relations into account
|
||
obj_aspects = {}
|
||
aspects.each do |aspect|
|
||
aspect_data = self.class.mapper.get_aspect(aspect)
|
||
|
||
next unless defined?(aspect_data[:presentation][:associated_attributes])
|
||
if defined?(aspect_data[:presentation][:associated_attributes]) and aspect_data[:presentation][:associated_attributes]
|
||
taken_attr_list = aspect_data[:presentation][:associated_attributes] & attr_list
|
||
unless taken_attr_list.empty?
|
||
obj_aspects[aspect] ||= {}
|
||
obj_aspects[aspect].merge!(fetch_attributes_data(taken_attr_list, options))
|
||
attr_list -= taken_attr_list
|
||
end
|
||
end
|
||
|
||
taken_attr_list = aspect_data[:presentation][:associated_attributes] & attr_list
|
||
obj_aspects[aspect] = fetch_attributes_data(taken_attr_list, options)
|
||
attr_list -= taken_attr_list
|
||
if defined?(aspect_data[:presentation][:associated_relations]) and aspect_data[:presentation][:associated_relations]
|
||
taken_rel_list = aspect_data[:presentation][:associated_relations] & rel_list
|
||
unless taken_rel_list.empty?
|
||
obj_aspects[aspect] ||= {}
|
||
obj_aspects[aspect].merge!(fetch_relations_data(taken_rel_list, options))
|
||
rel_list -= taken_rel_list
|
||
end
|
||
end
|
||
end
|
||
|
||
# manage general attributes
|
||
... | ... | |
taken_attr_list = taken_attr_list.uniq & attr_list
|
||
obj_info = fetch_attributes_data(taken_attr_list, options)
|
||
attr_list -= taken_attr_list
|
||
obj_info.merge!(fetch_relations_data(rel_list, options)) unless rel_list.empty?
|
||
|
||
# second pass to dispath the remaining attributes
|
||
unless attr_list.empty?
|
||
... | ... | |
|
||
[obj_info, obj_aspects]
|
||
end
|
||
|
||
protected
|
||
|
||
def fetch_attributes_data(attr_list, options = {})
|
||
attr_data = self.attributes.select {|key, val| attr_list.include?(key) and not (options[:skip_binary] and ActiveLdap::Base.schema.attribute(key).binary?) }
|
||
Hash[attr_data]
|
||
end
|
||
|
||
def fetch_relations_data(rel_list, options = {})
|
||
rel_data = rel_list.collect do |rel|
|
||
data = self.send(rel).collect{|g| g.name }
|
||
data.empty? ? nil : ["rel:" + rel, data]
|
||
end
|
||
Hash[rel_data.compact]
|
||
end
|
||
end
|
||
|
||
class Controller
|
||
... | ... | |
list
|
||
end
|
||
|
||
def self.translate_attribute_type(name)
|
||
att = ActiveLdap::Base.schema.attribute(name)
|
||
I18n.t(att.human_attribute_name, :scope => 'attribute_types', :default => att.human_attribute_description)
|
||
def self.translate_data_key(name)
|
||
if name.index(":")
|
||
type, key = name.split(":")
|
||
case type
|
||
when 'rel'
|
||
I18n.t(key, :scope => 'relations', :default => name)
|
||
else
|
||
raise "Cannot translate unknown data key type"
|
||
end
|
||
else
|
||
att = ActiveLdap::Base.schema.attribute(name)
|
||
I18n.t(att.human_attribute_name, :scope => 'attribute_types', :default => att.human_attribute_description)
|
||
end
|
||
end
|
||
|
||
def display_attributes2(attr_data)
|
||
def display_data(attr_data)
|
||
attr_data.each_pair do |key, val|
|
||
item_name = translate_attribute_type(key)
|
||
item_name = translate_data_key(key)
|
||
puts item_name + ": " + (val.is_a?(Array) ? val.sort.collect{|v| v.to_s }.join(", ") : val.to_s)
|
||
end
|
||
end
|
||
... | ... | |
puts item.to_s
|
||
puts "=== Detected Info ==="
|
||
puts "aspects: " + item.aspects.sort.join(", ")
|
||
|
||
puts "=== Relations ==="
|
||
item.relations.each do |rel|
|
||
puts "#{rel}: " + item.send(rel).collect{|g| g.name }.join(", ")
|
||
end
|
||
else
|
||
obj_info, obj_aspects = item.organized_attributes(:expert => $expert_opt, :skip_binary => true)
|
||
obj_info, obj_aspects = item.organized_data(:expert => $expert_opt, :skip_binary => true)
|
||
|
||
display_attributes2(obj_info)
|
||
display_data(obj_info)
|
||
|
||
obj_aspects.each_pair do |aspect_name, aspect_data|
|
||
aspect_display_name = I18n.t(aspect_name, :scope => 'aspects', :default => "Aspect: #{aspect_name}")
|
||
puts "=== #{aspect_display_name} ==="
|
||
display_attributes2(aspect_data)
|
||
display_data(aspect_data)
|
||
end
|
||
end
|
||
|
||
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
[evol] relations are now organized like attributes, added missing group relations