|
#--
|
|
# LdapShadows, a Medium-level LDAP Access Library and Tool.
|
|
# Copyright (c) 2009-2010 Marc Dequènes (Duck) <Duck@DuckCorp.org>
|
|
#
|
|
# This program is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
#++
|
|
|
|
# for Rails
|
|
class Hash
|
|
def recursive_symbolize_keys!
|
|
symbolize_keys!
|
|
values.select { |v| v.is_a?(Hash) }.each { |h| h.recursive_symbolize_keys! }
|
|
self
|
|
end
|
|
end
|
|
|
|
# for ActiveLDAP
|
|
module ActiveLdap
|
|
class Base
|
|
def family_parent_dn
|
|
self.dn.parent
|
|
end
|
|
|
|
def family_parent
|
|
ActiveLdap::Base.find(:first, :base => self.family_parent_dn, :scope => :base)
|
|
end
|
|
|
|
def family_children
|
|
ActiveLdap::Base.find(:all, :base => self.dn, :scope => :one)
|
|
end
|
|
|
|
def family_children_dn
|
|
self.family_children.collect {|obj| obj.dn }
|
|
end
|
|
|
|
def family_siblings
|
|
ActiveLdap::Base.find(:all, :base => self.family_parent_dn, :scope => :one).select{|obj| obj.dn != self.dn }
|
|
end
|
|
|
|
def family_siblings_dn
|
|
self.family_siblings.collect {|obj| obj.dn }
|
|
end
|
|
|
|
def modified_attributes(op_types = nil, att_only = false)
|
|
list = []
|
|
prepare_data_for_saving do |data, ldap_data|
|
|
list = collect_modified_attributes(ldap_data, data)
|
|
false
|
|
end
|
|
|
|
unless op_types.nil?
|
|
list.reject! do |mod_info|
|
|
op_type, att, new_val = mod_info
|
|
not op_types.include? op_type
|
|
end
|
|
end
|
|
|
|
if att_only
|
|
list.collect! do |mod_info|
|
|
op_type, att, new_val = mod_info
|
|
att
|
|
end
|
|
end
|
|
|
|
list
|
|
end
|
|
|
|
def nonempty_attributes
|
|
self.attributes.collect{|key, val| val.blank? ? nil : key }.compact
|
|
end
|
|
|
|
def missing_attributes
|
|
self.must.collect{|attr| attr.name } - self.nonempty_attributes - ['objectClass']
|
|
end
|
|
|
|
def self.objectclasses_attr_list(objectclass_list)
|
|
objectclass_list = [objectclass_list] unless objectclass_list.is_a? Array
|
|
list = []
|
|
objectclass_list.each do |objectclass|
|
|
objectclass_obj = ActiveLdap::Base.schema.object_class(objectclass)
|
|
attr_list = objectclass_obj.must + objectclass_obj.may
|
|
list += attr_list.collect{|attr| attr.human_attribute_name }
|
|
end
|
|
list
|
|
end
|
|
|
|
def self.possible_attributes
|
|
self.objectclasses_attr_list(self.required_classes)
|
|
end
|
|
end
|
|
end
|
|
|