Class: ActiveDirectory::Group
- Includes:
- Member
- Defined in:
- lib/active_directory/group.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.
-
#groups ⇒ Object
Returns an array of Group objects that this Group belongs to.
-
#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:
5 6 7 |
# File 'lib/active_directory/group.rb', line 5 def self.filter # :nodoc: Net::LDAP::Filter.eq(:objectClass,'group') end |
.required_attributes ⇒ Object
:nodoc:
9 10 11 |
# File 'lib/active_directory/group.rb', line 9 def self.required_attributes # :nodoc: { :objectClass => [ 'top', 'group' ] } 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.
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/active_directory/group.rb', line 36 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 |
#groups ⇒ Object
Returns an array of Group objects that this Group belongs to.
140 141 142 143 |
# File 'lib/active_directory/group.rb', line 140 def groups return [] if memberOf.nil? @groups ||= memberOf.collect { |group_dn| Group.find_by_distinguishedName(group_dn) } 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.
27 28 29 |
# File 'lib/active_directory/group.rb', line 27 def has_member?(user) user.member_of?(self) end |
#has_members? ⇒ Boolean
Return true if members exist in this group.
69 70 71 72 73 74 75 |
# File 'lib/active_directory/group.rb', line 69 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.
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/active_directory/group.rb', line 118 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.
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/active_directory/group.rb', line 86 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:
13 14 15 16 17 18 19 20 |
# File 'lib/active_directory/group.rb', line 13 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.
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/active_directory/group.rb', line 54 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 |