Module: Redmine::AccessControl
- Defined in:
- lib/redmine/access_control.rb
Overview
Defined Under Namespace
Classes: Mapper, Permission
Class Method Summary
collapse
Class Method Details
.allowed_actions(permission_name) ⇒ Object
Returns the actions that are allowed by the permission of given name
40
41
42
43
|
# File 'lib/redmine/access_control.rb', line 40
def allowed_actions(permission_name)
perm = permission(permission_name)
perm ? perm.actions : []
end
|
.available_project_modules ⇒ Object
69
70
71
|
# File 'lib/redmine/access_control.rb', line 69
def available_project_modules
@available_project_modules ||= @permissions.collect(&:project_module).uniq.compact
end
|
.loggedin_only_permissions ⇒ Object
53
54
55
|
# File 'lib/redmine/access_control.rb', line 53
def loggedin_only_permissions
@loggedin_only_permissions ||= @permissions.select {|p| p.require_loggedin?}
end
|
.map {|mapper| ... } ⇒ Object
22
23
24
25
26
27
|
# File 'lib/redmine/access_control.rb', line 22
def map
mapper = Mapper.new
yield mapper
@permissions ||= []
@permissions += mapper.mapped_permissions
end
|
.members_only_permissions ⇒ Object
49
50
51
|
# File 'lib/redmine/access_control.rb', line 49
def members_only_permissions
@members_only_permissions ||= @permissions.select {|p| p.require_member?}
end
|
.modules_permissions(modules) ⇒ Object
73
74
75
|
# File 'lib/redmine/access_control.rb', line 73
def modules_permissions(modules)
@permissions.select {|p| p.project_module.nil? || modules.include?(p.project_module.to_s)}
end
|
.permission(name) ⇒ Object
Returns the permission of given name or nil if it wasn't found Argument
should be a symbol
35
36
37
|
# File 'lib/redmine/access_control.rb', line 35
def permission(name)
permissions.detect {|p| p.name == name}
end
|
.permissions ⇒ Object
29
30
31
|
# File 'lib/redmine/access_control.rb', line 29
def permissions
@permissions
end
|
.public_permissions ⇒ Object
45
46
47
|
# File 'lib/redmine/access_control.rb', line 45
def public_permissions
@public_permissions ||= @permissions.select {|p| p.public?}
end
|
.read_action?(action) ⇒ Boolean
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/redmine/access_control.rb', line 57
def read_action?(action)
if action.is_a?(Symbol)
perm = permission(action)
!perm.nil? && perm.read?
elsif action.is_a?(Hash)
s = "#{action[:controller]}/#{action[:action]}"
permissions.detect {|p| p.actions.include?(s) && p.read?}.present?
else
raise ArgumentError.new("Symbol or a Hash expected, #{action.class.name} given: #{action}")
end
end
|