«
Previous
|
Next
»
Revision 4b490148
Added by Marc Dequènes over 13 years ago
- ID 4b4901484110005c790cb4af539f8da533ed4972
bin/shadowwalker | ||
---|---|---|
field_info = args.shift
|
||
field_name, file_no = field_info.split("#")
|
||
|
||
unless item.has_field?(field_name)
|
||
# TODO: not so beautiful…
|
||
obj_info, obj_aspects = item.organized_data
|
||
fields_info = obj_info.merge(obj_aspects.values.inject{|d1, d2| d1.merge(d2) } || {})
|
||
val = fields_info[field_name]
|
||
|
||
if val.nil?
|
||
raise PreProcessingError, _("No such field '%s' in object '%s'") % [field_name, obj_klass.handle]
|
||
end
|
||
|
||
field_data = item.send(field_name, true)
|
||
if ['write_only', 'forbidden'].include? val[:access]
|
||
raise PreProcessingError, _("Viewing field '%s' in object '%s' is forbidden") % [field_name, obj_klass.handle]
|
||
end
|
||
|
||
result_is_binary = false
|
||
nb_files = val[:multiple] ? val[:value].size : 1
|
||
if file_no == "?"
|
||
result = field_data.size
|
||
result = nb_files
|
||
else
|
||
file_no_i = file_no.to_i
|
||
file_no = (file_no_i.to_s == file_no) ? file_no_i : nil
|
||
|
||
attr_info = ActiveLdap::Base.schema.attribute(field_name)
|
||
|
||
field_single = attr_info.single_value?
|
||
if file_no.nil? and not field_single
|
||
if file_no.nil? and not val[:single_value]
|
||
raise PreProcessingError, _("Field '%s' in object '%s' has multiple values, but you didn't select one") %
|
||
[field_name, obj_klass.handle]
|
||
end
|
||
|
||
file_no = 0 if file_no.nil?
|
||
if file_no > 0 and field_single
|
||
if file_no > 0 and val[:single_value]
|
||
raise PreProcessingError, _("Field '%s' in object '%s' has only a single value") %
|
||
[field_name, obj_klass.handle]
|
||
end
|
||
if file_no < 0 or file_no >= field_data.size
|
||
if file_no < 0 or file_no >= nb_files
|
||
raise PreProcessingError, _("Field '%s' in object '%s' doesn't have such file number '%s' (select in range [0, %s])") %
|
||
[field_name, obj_klass.handle, file_no, field_data.size - 1]
|
||
[field_name, obj_klass.handle, file_no, nb_files - 1]
|
||
end
|
||
|
||
result = field_data[file_no]
|
||
result_is_binary = attr_info.binary?
|
||
result = val[:multiple] ? val[:value][file_no] : val[:value]
|
||
result_is_binary = val[:binary]
|
||
|
||
unless result_is_binary or $program_options[:debug]
|
||
result = LdapShadows::Manipulation.interpret_field_value(@shadow, attr_info.syntax.to_param, result)
|
||
result = LdapShadows::Manipulation.interpret_field_value(@shadow, val[:syntax], result)
|
||
if result.nil?
|
||
raise PreProcessingError, _("Field '%s' in object '%s' has a weird value") % [field_name, obj_klass.handle]
|
||
end
|
Also available in: Unified diff
[evol] attributes parameters rework §10 (access support for show operation on a single value)(changes also bring relation support to this operation btw) (closes #142)