Revision 98217996
Added by Marc Dequènes almost 14 years ago
- ID 9821799643b84c1515f3c342036686bd3a266f73
lib/ldap_shadows/activeldap_fixes.rb | ||
---|---|---|
#++
|
||
|
||
module ActiveLdap
|
||
# patch for activeldap#26824
|
||
class Schema
|
||
class Attribute
|
||
# operational?
|
||
#
|
||
# Returns true if an attribute is operational
|
||
# USAGE contains directoryOperation
|
||
# Duck: new method
|
||
def operational?
|
||
@operational
|
||
end
|
||
|
||
def collect_info
|
||
@description = attribute("DESC")[0]
|
||
@super_attribute = attribute("SUP")[0]
|
||
if @super_attribute
|
||
@super_attribute = @schema.attribute(@super_attribute)
|
||
@super_attribute = nil if @super_attribute.id.nil?
|
||
end
|
||
@read_only = attribute('NO-USER-MODIFICATION')[0] == 'TRUE'
|
||
@single_value = attribute('SINGLE-VALUE')[0] == 'TRUE'
|
||
@syntax = attribute("SYNTAX")[0]
|
||
@syntax = @schema.ldap_syntax(@syntax) if @syntax
|
||
if @syntax
|
||
@binary_required = @syntax.binary_transfer_required?
|
||
@binary = (@binary_required or !@syntax.human_readable?)
|
||
@derived_syntax = @syntax
|
||
else
|
||
@binary_required = false
|
||
@binary = false
|
||
@derived_syntax = nil
|
||
@derived_syntax = @super_attribute.syntax if @super_attribute
|
||
end
|
||
# Duck: newly collected data
|
||
@operational = attribute("USAGE").include?("directoryOperation")
|
||
end
|
||
end
|
||
end
|
||
|
||
class Base
|
||
# temporary method until active_ldap is fixed: return a DN object (see activeldap#23932)
|
||
def dn_obj
|
||
ActiveLdap::DistinguishedName.parse(self.dn)
|
||
end
|
||
|
||
# temporary method until active_ldap is fixed: return a DN object (see activeldap#23932)
|
||
def self.base_obj
|
||
ActiveLdap::DistinguishedName.parse(self.base)
|
||
end
|
||
|
||
# patch for activeldap#26745
|
||
def collect_modified_attributes(ldap_data, data)
|
||
attributes = []
|
||
# Now that all the options will be treated as unique attributes
|
||
# we can see what's changed and add anything that is brand-spankin'
|
||
# new.
|
||
ldap_data.each do |k, v|
|
||
next if schema.attribute(k).read_only?
|
||
|
||
value = data[k] || []
|
||
|
||
next if v == value
|
||
|
||
x = value
|
||
value = self.class.remove_blank_value(value) || []
|
||
next if v == value
|
||
|
||
# Create mod entries
|
||
if self.class.blank_value?(value)
|
||
# Since some types do not have equality matching rules,
|
||
# delete doesn't work
|
||
# Replacing with nothing is equivalent.
|
||
if !data.has_key?(k) and schema.attribute(k).binary_required?
|
||
value = [{'binary' => []}]
|
||
end
|
||
else
|
||
# Ditched delete then replace because attribs with no equality
|
||
# match rules will fails
|
||
end
|
||
attributes.push([:replace, k, value])
|
||
end
|
||
data.each do |k, v|
|
||
value = v || []
|
||
next if ldap_data.has_key?(k)
|
||
|
||
value = self.class.remove_blank_value(value) || []
|
||
next if self.class.blank_value?(value)
|
||
|
||
|
||
# Detect subtypes and account for them
|
||
# REPLACE will function like ADD, but doesn't hit EQUALITY problems
|
||
# TODO: Added equality(attr) to Schema
|
||
attributes.push([:replace, k, value])
|
||
end
|
||
|
||
attributes
|
||
end
|
||
end
|
||
|
||
module Validations
|
||
# unfinished workaround for activeldap#26720 (not sure it would work in all cases)
|
||
def validate_required_ldap_values
|
Also available in: Unified diff
[evol] switched to a higher activeldap library (closes #27)