Module: Redmine::AccessControl

Defined in:
lib/redmine/access_control.rb

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



42
43
44
45
# File 'lib/redmine/access_control.rb', line 42

def allowed_actions(permission_name)
  perm = permission(permission_name)
  perm ? perm.actions : []
end

.available_project_modulesObject



71
72
73
# File 'lib/redmine/access_control.rb', line 71

def available_project_modules
  @available_project_modules ||= @permissions.collect(&:project_module).uniq.compact
end

.loggedin_only_permissionsObject



55
56
57
# File 'lib/redmine/access_control.rb', line 55

def loggedin_only_permissions
  @loggedin_only_permissions ||= @permissions.select {|p| p.require_loggedin?}
end

.map {|mapper| ... } ⇒ Object

Yields:

  • (mapper)


24
25
26
27
28
29
# File 'lib/redmine/access_control.rb', line 24

def map
  mapper = Mapper.new
  yield mapper
  @permissions ||= []
  @permissions += mapper.mapped_permissions
end

.members_only_permissionsObject



51
52
53
# File 'lib/redmine/access_control.rb', line 51

def members_only_permissions
  @members_only_permissions ||= @permissions.select {|p| p.require_member?}
end

.modules_permissions(modules) ⇒ Object



75
76
77
# File 'lib/redmine/access_control.rb', line 75

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



37
38
39
# File 'lib/redmine/access_control.rb', line 37

def permission(name)
  permissions.detect {|p| p.name == name}
end

.permissionsObject



31
32
33
# File 'lib/redmine/access_control.rb', line 31

def permissions
  @permissions
end

.public_permissionsObject



47
48
49
# File 'lib/redmine/access_control.rb', line 47

def public_permissions
  @public_permissions ||= @permissions.select {|p| p.public?}
end

.read_action?(action) ⇒ Boolean

Returns:

  • (Boolean)


59
60
61
62
63
64
65
66
67
68
69
# File 'lib/redmine/access_control.rb', line 59

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