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



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

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

.available_project_modulesObject



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

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

.loggedin_only_permissionsObject



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

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

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

Yields:

  • (mapper)


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

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

.members_only_permissionsObject



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

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

.modules_permissions(modules) ⇒ Object



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

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



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

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

.permissionsObject



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

def permissions
  @permissions
end

.public_permissionsObject



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

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

.read_action?(action) ⇒ Boolean

Returns:

  • (Boolean)


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

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