Project

General

Profile

« Previous | Next » 

Revision 473b6a8b

Added by Marc Dequènes over 15 years ago

  • ID 473b6a8bb051eb24513b023eb07cfa44ba536162

[evol] attributes classification finished, added a few translations

View differences:

locale/en.yml
---
en:
attribute_types:
cn: "FullName"
allowGlobalDirectory: "Disclose Own Contact Information in GLobal Directory"
cn: "Full Name"
birthday: "Birthday"
birthlocation: "Birth Location"
description: "Description"
gecos: "GECOS"
gidNumber: "Primary Group (numeric)"
givenName: "FirstName"
homeDirectory: "Home Directory"
homePostalAddress: "Home Postal Address"
host: "Shell Allowed Hosts"
jid: "Jabber ID"
jpegPhoto: "Photo"
keyFingerPrint: "GPG/PGP Key Fingerprint"
labeledURI: "Web Site"
loginShell: "Shell Interpreter"
mail: "eMail address(es)"
mailForward: "eMail Forward Adress(es)"
mailQuota: "Maximum Mailbox Size"
manager: "Manager(s)"
mobile: "Mobile Phone"
occupation: "Job / Studies"
o: "Organization(s)"
owner: "Owner(s)"
preferredLanguage: "Language Preference"
sn: "Surname"
sshAuthKey: "SSH Public Key(s)"
uid: "Identifier"
uidNumber: "Identifier (numeric)"
uniqueMember: "Group member"
test.rb
end
def aspects
present_aspects = {}
present_aspects = []
self.class.presentation[:allowed_aspects].each do |aspect|
aspect_data = self.class.mapper.get_aspect(aspect)
aspect_mapping = aspect_data[:mapping]
present_aspects[aspect] = aspect_data if self.classes & aspect_mapping[:classes] == aspect_mapping[:classes]
present_aspects << aspect if self.classes & aspect_mapping[:classes] == aspect_mapping[:classes]
end
present_aspects
......
list
end
def organized_attributes(expert = false)
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 = {})
options.symbolize_keys!
options[:expert] ||= false;
options[:skip_binary] ||= false;
ignored_attrs = self.class.presentation[:hidden_attributes] || []
ignored_attrs += (self.class.presentation[:expert_attributes] || []) unless expert
ignored_attrs += (self.class.presentation[:expert_attributes] || []) unless options[:expert]
attr_list = self.attributes.keys - ignored_attrs
aspects = self.aspects
# first pass to take aspects forced associations into account
obj_aspects = {}
present_aspects_data = self.aspects
self.class.presentation[:allowed_aspects].each do |aspect|
aspect_data = present_aspects_data[aspect]
next unless aspect_data.has_key?(:presentation) and aspect_data[:presentation] and aspect_data[:presentation].has_key?(:associated_attributes)
aspects.each do |aspect|
aspect_data = self.class.mapper.get_aspect(aspect)
next unless defined?(aspect_data[:presentation][:associated_attributes])
taken_attr_list = aspect_data[:presentation][:associated_attributes] & attr_list
taken_attr_data = self.attributes.select {|key, val| taken_attr_list.include?(key) }
obj_aspects[aspect] = Hash[taken_attr_data]
obj_aspects[aspect] = fetch_attributes_data(taken_attr_list, options)
attr_list -= taken_attr_list
end
# manage general attributes
obj_info = {}
if self.class.presentation.has_key?(:associated_attributes)
taken_attr_list = self.class.presentation[:associated_attributes] & attr_list
elsif self.class.presentation[:associate_unclaimed_attributes]
if self.class.presentation[:associate_unclaimed_attributes]
taken_attr_list = attr_list
else
taken_attr_list = (objectclasses_attr_list(self.required_classes + (self.class.presentation[:optional_classes] || [])) & attr_list)
taken_attr_list = []
if self.class.presentation.has_key?(:associated_attributes)
taken_attr_list += self.class.presentation[:associated_attributes]
end
taken_attr_list += objectclasses_attr_list(self.required_classes + (self.class.presentation[:optional_classes] || []))
end
taken_attr_list = taken_attr_list.uniq & attr_list
obj_info = fetch_attributes_data(taken_attr_list, options)
attr_list -= taken_attr_list
# second pass to dispath the remaining attributes
unless attr_list.empty?
aspects.each do |aspect|
aspect_data = self.class.mapper.get_aspect(aspect)
taken_attr_list = (objectclasses_attr_list(aspect_data[:mapping][:classes]) & attr_list)
obj_aspects[aspect] ||= {}
obj_aspects[aspect].merge!(fetch_attributes_data(taken_attr_list, options))
attr_list -= taken_attr_list
break if attr_list.empty?
end
end
taken_attr_data = self.attributes.select {|key, val| taken_attr_list.include?(key) }
obj_info = Hash[taken_attr_data]
[obj_info, obj_aspects]
end
......
list
end
def display_attributes(item, attr_list = nil)
attr_list = item.attributes.keys.sort if attr_list.nil?
attr_list.each do |key|
next if item.class.presentation[:hidden_attributes].include?(key)
next if not $expert_opt and item.class.presentation[:expert_attributes].include?(key)
att = ActiveLdap::Base.schema.attribute(key)
next if att.binary?
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)
end
val = item[key]
item_name = I18n.t(att.human_attribute_name, :scope => 'attribute_types', :default => att.human_attribute_description)
def display_attributes2(attr_data)
attr_data.each_pair do |key, val|
item_name = translate_attribute_type(key)
puts item_name + ": " + (val.is_a?(Array) ? val.sort.collect{|v| v.to_s }.join(", ") : val.to_s)
end
end
......
exit 2
end
aspects = item.aspects
if $debug_opt
puts item.to_s
puts "=== Detected Info ==="
puts "aspects: " + aspects.keys.sort.join(", ")
puts "aspects: " + item.aspects.sort.join(", ")
else
used_attributes = []
obj_info, obj_aspects = item.organized_attributes(:expert => $expert_opt, :skip_binary => true)
attr_list = (objectclasses_attr_list(item.required_classes + item.class.presentation[:optional_classes]) & item.attributes.keys).sort
display_attributes(item, attr_list)
display_attributes2(obj_info)
used_attributes += attr_list
aspects.keys.sort.each do |r|
aspect_display_name = I18n.t(r, :scope => 'aspects', :default => "Aspect: #{r}")
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} ==="
attr_list = ((objectclasses_attr_list(aspects[r][:mapping][:classes]) & item.attributes.keys) - used_attributes).sort
display_attributes(item, attr_list)
used_attributes += attr_list
display_attributes2(aspect_data)
end
end
......
assoc_display_name = I18n.t(assoc, :scope => 'associations', :default => assoc.to_s)
puts "#{assoc_display_name}: " + item.send(assoc).collect{|g| g.name }.join(", ")
end
p item.organized_attributes($expert_opt)
end
cmdparser.add_command(cmd)

Also available in: Unified diff