annotate .svn/pristine/e7/e7d5b83dc86514b97aab96a27bc85fdb59bbd440.svn-base @ 1628:9c5f8e24dadc live tip

Quieten this cron script
author Chris Cannam
date Tue, 25 Aug 2020 11:38:49 +0100
parents dffacf8a6908
children
rev   line source
Chris@1517 1 # Redmine - project management software
Chris@1517 2 # Copyright (C) 2006-2014 Jean-Philippe Lang
Chris@1517 3 #
Chris@1517 4 # This program is free software; you can redistribute it and/or
Chris@1517 5 # modify it under the terms of the GNU General Public License
Chris@1517 6 # as published by the Free Software Foundation; either version 2
Chris@1517 7 # of the License, or (at your option) any later version.
Chris@1517 8 #
Chris@1517 9 # This program is distributed in the hope that it will be useful,
Chris@1517 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1517 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1517 12 # GNU General Public License for more details.
Chris@1517 13 #
Chris@1517 14 # You should have received a copy of the GNU General Public License
Chris@1517 15 # along with this program; if not, write to the Free Software
Chris@1517 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1517 17
Chris@1517 18 module Redmine
Chris@1517 19 module AccessControl
Chris@1517 20
Chris@1517 21 class << self
Chris@1517 22 def map
Chris@1517 23 mapper = Mapper.new
Chris@1517 24 yield mapper
Chris@1517 25 @permissions ||= []
Chris@1517 26 @permissions += mapper.mapped_permissions
Chris@1517 27 end
Chris@1517 28
Chris@1517 29 def permissions
Chris@1517 30 @permissions
Chris@1517 31 end
Chris@1517 32
Chris@1517 33 # Returns the permission of given name or nil if it wasn't found
Chris@1517 34 # Argument should be a symbol
Chris@1517 35 def permission(name)
Chris@1517 36 permissions.detect {|p| p.name == name}
Chris@1517 37 end
Chris@1517 38
Chris@1517 39 # Returns the actions that are allowed by the permission of given name
Chris@1517 40 def allowed_actions(permission_name)
Chris@1517 41 perm = permission(permission_name)
Chris@1517 42 perm ? perm.actions : []
Chris@1517 43 end
Chris@1517 44
Chris@1517 45 def public_permissions
Chris@1517 46 @public_permissions ||= @permissions.select {|p| p.public?}
Chris@1517 47 end
Chris@1517 48
Chris@1517 49 def members_only_permissions
Chris@1517 50 @members_only_permissions ||= @permissions.select {|p| p.require_member?}
Chris@1517 51 end
Chris@1517 52
Chris@1517 53 def loggedin_only_permissions
Chris@1517 54 @loggedin_only_permissions ||= @permissions.select {|p| p.require_loggedin?}
Chris@1517 55 end
Chris@1517 56
Chris@1517 57 def read_action?(action)
Chris@1517 58 if action.is_a?(Symbol)
Chris@1517 59 perm = permission(action)
Chris@1517 60 !perm.nil? && perm.read?
Chris@1517 61 else
Chris@1517 62 s = "#{action[:controller]}/#{action[:action]}"
Chris@1517 63 permissions.detect {|p| p.actions.include?(s) && p.read?}.present?
Chris@1517 64 end
Chris@1517 65 end
Chris@1517 66
Chris@1517 67 def available_project_modules
Chris@1517 68 @available_project_modules ||= @permissions.collect(&:project_module).uniq.compact
Chris@1517 69 end
Chris@1517 70
Chris@1517 71 def modules_permissions(modules)
Chris@1517 72 @permissions.select {|p| p.project_module.nil? || modules.include?(p.project_module.to_s)}
Chris@1517 73 end
Chris@1517 74 end
Chris@1517 75
Chris@1517 76 class Mapper
Chris@1517 77 def initialize
Chris@1517 78 @project_module = nil
Chris@1517 79 end
Chris@1517 80
Chris@1517 81 def permission(name, hash, options={})
Chris@1517 82 @permissions ||= []
Chris@1517 83 options.merge!(:project_module => @project_module)
Chris@1517 84 @permissions << Permission.new(name, hash, options)
Chris@1517 85 end
Chris@1517 86
Chris@1517 87 def project_module(name, options={})
Chris@1517 88 @project_module = name
Chris@1517 89 yield self
Chris@1517 90 @project_module = nil
Chris@1517 91 end
Chris@1517 92
Chris@1517 93 def mapped_permissions
Chris@1517 94 @permissions
Chris@1517 95 end
Chris@1517 96 end
Chris@1517 97
Chris@1517 98 class Permission
Chris@1517 99 attr_reader :name, :actions, :project_module
Chris@1517 100
Chris@1517 101 def initialize(name, hash, options)
Chris@1517 102 @name = name
Chris@1517 103 @actions = []
Chris@1517 104 @public = options[:public] || false
Chris@1517 105 @require = options[:require]
Chris@1517 106 @read = options[:read] || false
Chris@1517 107 @project_module = options[:project_module]
Chris@1517 108 hash.each do |controller, actions|
Chris@1517 109 if actions.is_a? Array
Chris@1517 110 @actions << actions.collect {|action| "#{controller}/#{action}"}
Chris@1517 111 else
Chris@1517 112 @actions << "#{controller}/#{actions}"
Chris@1517 113 end
Chris@1517 114 end
Chris@1517 115 @actions.flatten!
Chris@1517 116 end
Chris@1517 117
Chris@1517 118 def public?
Chris@1517 119 @public
Chris@1517 120 end
Chris@1517 121
Chris@1517 122 def require_member?
Chris@1517 123 @require && @require == :member
Chris@1517 124 end
Chris@1517 125
Chris@1517 126 def require_loggedin?
Chris@1517 127 @require && (@require == :member || @require == :loggedin)
Chris@1517 128 end
Chris@1517 129
Chris@1517 130 def read?
Chris@1517 131 @read
Chris@1517 132 end
Chris@1517 133 end
Chris@1517 134 end
Chris@1517 135 end