Project

General

Profile

« Previous | Next » 

Revision 3d58e226

Added by Marc Dequènes almost 15 years ago

  • ID 3d58e22672318af63b3682a7a89766525a7355fa

[fix] fs aspect primaryGroup corrected, and now handle single-valued relation data, and btw disallow adding the same value multiple times

View differences:

TODO
- find a way to restrict parent locations for new objects (regex for <obj>/<item> string ? regex for DN ? OR/AND with both ? ???)
- search by combination of objects/aspects/fields values
- aspect dependency support
- handle fields containing a DN (allowing either giving a DN string or something like <object>:<item>)
- display familly information (preliminary work done for debug mode done, but object type should be recognized and displayed properly)
- handle subtypes
bin/shadowwalker
raise WeirdError, _("Ambiguous item '%s' for relation '%s' (%s possible items)") %
[val, field, foreign_item_list.size]
end
old_val = item.send(field)
val = foreign_item_list.first
when ''
case field
......
if type == '' and field == 'aspects'
raise PreProcessingError, _("The equality operator is not possible for aspects")
end
item.send(field + "=", [val])
val = [val] if old_val.is_a? Enumerable
item.send(field + "=", val)
when '+='
case type
when nil
if attr_info.single_value?
raise PreProcessingError, _("The field '%s' cannot hold more than one value") % field
end
new_val = old_val << val
item.send(field + "=", new_val)
unless old_val.include?(val)
new_val = old_val << val
item.send(field + "=", new_val)
end
when 'rel'
if rel_info[:single_value]
raise PreProcessingError, _("The relation '%s' cannot hold more than one foreign item") % field
end
item.send(field) << val
unless old_val.include?(val)
item.send(field) << val
end
when ''
case field
when 'aspects'
......
if modification_done
missing_fields = item.missing_attributes
### temporarily deactivated
# It is needed to test preliminary work on hooks.
# This check should be moved into the save() method, raise an exception is any problem,
# and exceptions caught in a centralized place in this file.
missing_fields = []
unless missing_fields.empty?
miss_str = []
missing_fields.each do |field|
......
miss_str.join(", ")
end
$program_options[:skip_binary] = true
Display.display_item(item, $program_options)
item.save!
puts "Modification done."
else
puts "Nothing to do."
conf/ldap_shadows/hooks/aspects/fs.rb
DEFAULT_GROUP = 'dc-users'
def self.hook_mod(mapper, item)
# does not work, but why ?
unless item.attribute_present?('gidNumber')
item.primaryGroup = [mapper.find_klass(:group).find(:first, DEFAULT_GROUP)]
item.primaryGroup = mapper.find_klass(:group).find(:first, DEFAULT_GROUP)
end
unless item.attribute_present?('uidNumber')
conf/ldap_shadows/test.conf
associated_relations: ['primaryGroup', 'secondaryGroups']
relations:
primaryGroup:
type: :has_many
type: :belongs_to
object: group
foreign_key: gidNumber
primary_key: gidNumber
lib/ldap_shadows/display_utils.rb
puts "--- Relations ---"
item.relations.each do |rel|
puts "#{rel}: " + item.send(rel).collect{|g| g.name }.join(", ")
rel_data = item.send(rel)
if rel_data.is_a? Enumerable
next if rel_data.empty?
rel_value = rel_data.collect{|g| g.name }.join(", ")
else
next if rel_data.target.nil?
rel_value = rel_data.name
end
puts "#{rel}: " + rel_value
end
else
obj_info, obj_aspects = item.organized_data
lib/ldap_shadows/object.rb
def fetch_relations_data(rel_list, expert_attributes)
rel_data = rel_list.collect do |rel|
data = self.send(rel).collect{|g| g.name }
if data.empty?
data = self.send(rel)
if data.is_a? Enumerable
if data.empty?
value = nil
else
value = data.collect{|g| g.name }
multiple = true
end
else
if data.target.nil?
value = nil
else
value = data.name
end
multiple = false
end
if value.nil?
nil
else
["rel:" + rel, {
:value => data,
:multiple => (data.size > 1),
:expert => expert_attributes.include?("rel:" + rel),
rel_key = "rel:" + rel
[rel_key, {
:value => value,
:multiple => multiple,
:expert => expert_attributes.include?(rel_key),
:binary => false
}]
end

Also available in: Unified diff