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