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