Project

General

Profile

Download (2.87 KB) Statistics
| Branch: | Tag: | Revision:
89d8bebc Marc Dequènes (Duck)
#--
# LdapShadows, a Medium-level LDAP Access Library and Tool.
bc2c2691 Marc Dequènes (Duck)
# Copyright (c) 2009-2010 Marc Dequènes (Duck) <Duck@DuckCorp.org>
89d8bebc Marc Dequènes (Duck)
#
# 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
3e7f80c0 Marc Dequènes (Duck)
class Base
def family_parent_dn
98217996 Marc Dequènes (Duck)
self.dn.parent
3e7f80c0 Marc Dequènes (Duck)
end

def family_parent
98217996 Marc Dequènes (Duck)
ActiveLdap::Base.find(:first, :base => self.family_parent_dn, :scope => :base)
3e7f80c0 Marc Dequènes (Duck)
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
98217996 Marc Dequènes (Duck)
ActiveLdap::Base.find(:all, :base => self.family_parent_dn, :scope => :one).select{|obj| obj.dn != self.dn }
3e7f80c0 Marc Dequènes (Duck)
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

707b1758 Marc Dequènes (Duck)
def nonempty_attributes
f0a9fa9e Marc Dequènes (Duck)
self.attributes.collect{|key, val| (val.blank? and not val.is_a?(FalseClass)) ? nil : key }.compact
707b1758 Marc Dequènes (Duck)
end

def missing_attributes
self.must.collect{|attr| attr.name } - self.nonempty_attributes - ['objectClass']
end

3e7f80c0 Marc Dequènes (Duck)
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
89d8bebc Marc Dequènes (Duck)
end