Project

General

Profile

« Previous | Next » 

Revision 34cb4054

Added by Marc Dequènes over 15 years ago

  • ID 34cb4054ed129c8e27c84511e16f561438489d8b

[evol/fix] added support for read_only relations, improved result message, and fixed a regression where normal attributes could not be modified because of a regex mistake in the parsing code

View differences:

bin/shadowwalker
exit 2
end
modification_done = false
args.each do |mod_info|
mod_info =~ /^([a-zA-Z]+(?::[a-zA-Z]+))(=|\+=|-=)(.*)$/
mod_info =~ /^([a-zA-Z]+(?::[a-zA-Z]+)?)(=|\+=|-=)(.*)$/
key = $1
op = $2
val = $3
......
exit 2
end
# XXX: should we add a new parameter to enforce read-only relations ?
rel_info = item.info_for_relation(field)
if rel_info[:read_only]
STDERR.puts "The relation '#{field}' cannot be modified (read only), skipping."
next
end
# fetch remote object in relation, which will be the real 'val'
rel_info = item.info_for_relation(field)
foreign_item_list = rel_info[:foreign_klass].find(:all, val)
if foreign_item_list.empty?
STDERR.puts "Foreign item '#{val}' for relation '#{field}' not found."
......
STDERR.puts "Syntax error in modification parameters: wrong operator"
exit 1
end
modification_done = true
end
puts "Modified attributes:"
p item.modified_attributes
begin
item.save!
rescue ActiveLdap::OperationNotPermitted => e
STDERR.puts "You don't have enough rights to modify--at least--one of these attributes."
exit 3
rescue ActiveLdap::LdapError => e
STDERR.puts "LDAP error: " + e.to_s
exit 3
rescue ActiveLdap::EntryInvalid => e
STDERR.puts e.to_s
exit 3
end
if modification_done
puts "Modified attributes:"
p item.modified_attributes
begin
item.save!
rescue ActiveLdap::OperationNotPermitted => e
STDERR.puts "You don't have enough rights to modify--at least--one of these attributes."
exit 3
rescue ActiveLdap::LdapError => e
STDERR.puts "LDAP error: " + e.to_s
exit 3
rescue ActiveLdap::EntryInvalid => e
STDERR.puts e.to_s
exit 3
end
puts "Modification done"
puts "Modification done."
else
puts "Nothing to do."
end
end
cmdparser.add_command(cmd)
lib/ldap_shadows/controller.rb
obj_relations_info[field_name] = {
:foreign_klass => foreign_klass,
:single_value => ActiveLdap::Base.schema.attribute(rel[:foreign_key]).single_value?
:single_value => ActiveLdap::Base.schema.attribute(rel[:foreign_key]).single_value?,
:read_only => rel[:read_only] || false
}
end
klass.relations_info = obj_relations_info

Also available in: Unified diff