5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/id_please/model_extensions/for_group.rb', line 5
def children(*args)
options = args.
roles = options[:roles] || [_auth_group_role]
view = options[:view] || :subjects
role_hash = {}
subject_hash = {}
assignments = if roles == :any
_auth_assign_class.role_authorizable_eq(self).all(:include => [:subject, :role])
else
_auth_assign_class.role_name_eq(*roles.collect(&:to_s)).role_authorizable_eq(self).all(:include => [:subject, :role])
end
assignments.each do |a|
name, subject = a.role.name.to_sym, a.subject
role_hash.has_key?(name) ? role_hash[name] << subject : role_hash[name] = [subject]
subject_hash.has_key?(subject) ? subject_hash[subject] << name : subject_hash[subject] = [name]
if _auth_nested_groups == true && options[:nested] != false && subject._auth_is_group == true
children = subject.children
role_hash[name] |= children
children.each { |child| subject_hash.has_key?(child) ? subject_hash[child] << name : subject_hash[child] = [name]}
end
end
case view
when :subjects
subject_hash.keys
when :subject_hash
subject_hash
when :roles
role_hash.keys
when :role_hash
role_hash
end
end
|