annotate .svn/pristine/95/95a7ef8cd08c5e04408d2693f468d8a51618e5eb.svn-base @ 1524:82fac3dcf466 redmine-2.5-integration

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