Class: ActiveDirectory::Ou
- Includes:
- Member
- Defined in:
- lib/active_directory/ou.rb
Constant Summary
Constants inherited from Base
Class Method Summary collapse
-
.filter ⇒ Object
:nodoc:.
-
.required_attributes ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#add(new_member) ⇒ Object
Add the passed User or Group object to this Group.
-
#has_member?(user) ⇒ Boolean
Returns true if the passed User or Group object belongs to this group.
-
#has_members? ⇒ Boolean
Return true if members exist in this group.
-
#member_groups(recursive = false) ⇒ Object
Returns an array of all Group objects that belong to this group.
-
#member_users(recursive = false) ⇒ Object
Returns an array of all User objects that belong to this group.
-
#reload ⇒ Object
:nodoc:.
-
#remove(member) ⇒ Object
Remove a User or Group from this Group.
Methods included from Member
Methods inherited from Base
#==, #changed?, create, #destroy, error, exists?, find, find_all, find_first, #initialize, make_filter_from_hash, method_missing, #method_missing, #move, #new_record?, parse_finder_spec, #save, setup, #update_attribute, #update_attributes
Constructor Details
This class inherits a constructor from ActiveDirectory::Base
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class ActiveDirectory::Base
Class Method Details
.filter ⇒ Object
:nodoc:
31 32 33 |
# File 'lib/active_directory/ou.rb', line 31 def self.filter # :nodoc: Net::LDAP::Filter.eq(:objectClass,'ou') end |
.required_attributes ⇒ Object
:nodoc:
35 36 37 |
# File 'lib/active_directory/ou.rb', line 35 def self.required_attributes # :nodoc: { :objectClass => [ 'top', 'ou' ] } end |
Instance Method Details
#add(new_member) ⇒ Object
Add the passed User or Group object to this Group. Returns true if the User or Group is already a member of the group, or if the operation to add them succeeds.
62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/active_directory/ou.rb', line 62 def add(new_member) debugger return false unless new_member.is_a?(ActiveDirectory::User) || new_member.is_a?(ActiveDirectory::Group) if @@ldap.modify(:dn => distinguishedName, :operations => [ [ :add, :member, new_member.distinguishedName ] ]) self.reload return true else return has_member?(new_member) end end |
#has_member?(user) ⇒ Boolean
Returns true if the passed User or Group object belongs to this group. For performance reasons, the check is handled by the User or Group object passed.
53 54 55 |
# File 'lib/active_directory/ou.rb', line 53 def has_member?(user) user.member_of?(self) end |
#has_members? ⇒ Boolean
Return true if members exist in this group.
95 96 97 98 99 100 101 |
# File 'lib/active_directory/ou.rb', line 95 def has_members? begin return (@entry.member.nil? || @entry.member.empty?) ? false : true rescue NoMethodError return false end end |
#member_groups(recursive = false) ⇒ Object
Returns an array of all Group objects that belong to this group.
If the recursive argument is passed as false, then only Groups that belong explicitly to this Group are returned.
If the recursive argument is passed as true, then all Groups that belong to this Group, or any of its subgroups, are returned.
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/active_directory/ou.rb', line 144 def member_groups(recursive = false) return [] unless has_members? if recursive if @member_groups_r.nil? @member_groups_r = [] @entry.member.each do |member_dn| subgroup = Group.find_by_distinguishedName(member_dn) if subgroup @member_groups_r << subgroup @member_groups_r = @member_groups_r.concat(subgroup.member_groups(true)) end end end return @member_groups_r else @member_groups_non_r ||= @entry.member.collect { |dn| Group.find_by_distinguishedName(dn) }.delete_if { |g| g.nil? } end end |
#member_users(recursive = false) ⇒ Object
Returns an array of all User objects that belong to this group.
If the recursive argument is passed as false, then only Users who belong explicitly to this Group are returned.
If the recursive argument is passed as true, then all Users who belong to this Group, or any of its subgroups, are returned.
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/active_directory/ou.rb', line 112 def member_users(recursive = false) return [] unless has_members? if recursive if @member_users_r.nil? @member_users_r = [] @entry.member.each do |member_dn| subuser = User.find_by_distinguishedName(member_dn) if subuser @member_users_r << subuser else subgroup = Group.find_by_distinguishedName(member_dn) if subgroup @member_users_r = @member_users_r.concat(subgroup.member_users(true)) end end end end return @member_users_r else @member_users_non_r ||= @entry.member.collect { |dn| User.find_by_distinguishedName(dn) }.delete_if { |u| u.nil? } end end |
#reload ⇒ Object
:nodoc:
39 40 41 42 43 44 45 46 |
# File 'lib/active_directory/ou.rb', line 39 def reload # :nodoc: @member_users_non_r = nil @member_users_r = nil @member_groups_non_r = nil @member_groups_r = nil @groups = nil super end |
#remove(member) ⇒ Object
Remove a User or Group from this Group. Returns true if the User or Group does not belong to this Group, or if the operation to remove them succeeds.
80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/active_directory/ou.rb', line 80 def remove(member) return false unless member.is_a?(User) || member.is_a?(Group) if @@ldap.modify(:dn => distinguishedName, :operations => [ [ :delete, :member, member.distinguishedName ] ]) self.reload return true else return !has_member?(member) end end |