Class: ActiveDirectory::Group

Inherits:
Base
  • Object
show all
Includes:
Member
Defined in:
lib/active_directory/group.rb

Constant Summary

Constants inherited from Base

Base::NIL_FILTER

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Member

#join, #member_of?, #unjoin

Methods inherited from Base

#==, cache?, #changed?, class_name, clear_cache, connected?, create, decode_field, #destroy, disable_cache, enable_cache, encode_field, error, error?, error_code, exists?, find, find_all, find_cached_results, find_first, #get_attr, get_field_type, #initialize, make_filter, make_filter_from_hash, method_missing, #method_missing, #move, #new_record?, parse_finder_spec, #save, #set_attr, setup, #to_ary, #update_attribute, #update_attributes, #valid_attribute?

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

.filterObject

:nodoc:



25
26
27
# File 'lib/active_directory/group.rb', line 25

def self.filter # :nodoc:
	Net::LDAP::Filter.eq(:objectClass,'group')
end

.required_attributesObject

:nodoc:



29
30
31
# File 'lib/active_directory/group.rb', line 29

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.



56
57
58
59
60
61
62
63
64
65
# File 'lib/active_directory/group.rb', line 56

def add(new_member)
	return false unless new_member.is_a?(User) || new_member.is_a?(Group)
	if @@ldap.modify(:dn => distinguishedName, :operations => [
		[ :add, :member, new_member.distinguishedName ]
	])
		return true
	else
		return has_member?(new_member)
	end
end

#groupsObject

Returns an array of Group objects that this Group belongs to.



132
133
134
135
# File 'lib/active_directory/group.rb', line 132

def groups
	return [] if memberOf.nil?
	@groups ||= Group.find(:all, :distinguishedname => @entry.memberOf).delete_if { |g| g.nil? }
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.

Returns:

  • (Boolean)


47
48
49
# File 'lib/active_directory/group.rb', line 47

def has_member?(user)
	user.member_of?(self)
end

#has_members?Boolean

Returns:

  • (Boolean)


83
84
85
86
87
88
89
# File 'lib/active_directory/group.rb', line 83

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.



119
120
121
122
123
124
125
126
127
# File 'lib/active_directory/group.rb', line 119

def member_groups(recursive = false)
                      @member_groups ||= Group.find(:all, :distinguishedname => @entry[:member]).delete_if { |g| g.nil? }
                      if recursive then
                        self.member_groups.each do |group|
                          @member_groups.concat(group.member_groups(true))
                        end
                      end
                      return @member_groups
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.



100
101
102
103
104
105
106
107
108
# File 'lib/active_directory/group.rb', line 100

def member_users(recursive = false)
                      @member_users = User.find(:all, :distinguishedname => @entry[:member]).delete_if { |u| u.nil? }
                      if recursive then
                        self.member_groups.each do |group|
                          @member_users.concat(group.member_users(true))
                        end
                      end
                      return @member_users
end

#reloadObject

:nodoc:



33
34
35
36
37
38
39
40
# File 'lib/active_directory/group.rb', line 33

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 oepration to remove them succeeds.



72
73
74
75
76
77
78
79
80
81
# File 'lib/active_directory/group.rb', line 72

def remove(member)
	return false unless member.is_a?(User) || member.is_a?(Group)
	if @@ldap.modify(:dn => distinguishedName, :operations => [
		[ :delete, :member, member.distinguishedName ]
	])
		return true
	else
		return !has_member?(member)
	end
end