@@ -5,12 +5,12 | |||
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 |
# |
|
|
8 | # | |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 |
# |
|
|
13 | # | |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
@@ -19,7 +19,7 class Role < ActiveRecord::Base | |||
|
19 | 19 | # Built-in roles |
|
20 | 20 | BUILTIN_NON_MEMBER = 1 |
|
21 | 21 | BUILTIN_ANONYMOUS = 2 |
|
22 | ||
|
22 | ||
|
23 | 23 | ISSUES_VISIBILITY_OPTIONS = [ |
|
24 | 24 | ['all', :label_issues_visibility_all], |
|
25 | 25 | ['default', :label_issues_visibility_public], |
@@ -31,18 +31,18 class Role < ActiveRecord::Base | |||
|
31 | 31 | compare = 'not' if args.first == true |
|
32 | 32 | { :conditions => "#{compare} builtin = 0" } |
|
33 | 33 | } |
|
34 | ||
|
34 | ||
|
35 | 35 | before_destroy :check_deletable |
|
36 | 36 | has_many :workflows, :dependent => :delete_all do |
|
37 | 37 | def copy(source_role) |
|
38 | 38 | Workflow.copy(nil, source_role, nil, proxy_owner) |
|
39 | 39 | end |
|
40 | 40 | end |
|
41 | ||
|
41 | ||
|
42 | 42 | has_many :member_roles, :dependent => :destroy |
|
43 | 43 | has_many :members, :through => :member_roles |
|
44 | 44 | acts_as_list |
|
45 | ||
|
45 | ||
|
46 | 46 | serialize :permissions, Array |
|
47 | 47 | attr_protected :builtin |
|
48 | 48 | |
@@ -52,11 +52,11 class Role < ActiveRecord::Base | |||
|
52 | 52 | validates_inclusion_of :issues_visibility, |
|
53 | 53 | :in => ISSUES_VISIBILITY_OPTIONS.collect(&:first), |
|
54 | 54 | :if => lambda {|role| role.respond_to?(:issues_visibility)} |
|
55 | ||
|
55 | ||
|
56 | 56 | def permissions |
|
57 | 57 | read_attribute(:permissions) || [] |
|
58 | 58 | end |
|
59 | ||
|
59 | ||
|
60 | 60 | def permissions=(perms) |
|
61 | 61 | perms = perms.collect {|p| p.to_sym unless p.blank? }.compact.uniq if perms |
|
62 | 62 | write_attribute(:permissions, perms) |
@@ -79,20 +79,20 class Role < ActiveRecord::Base | |||
|
79 | 79 | perms.each { |p| permissions.delete(p.to_sym) } |
|
80 | 80 | save! |
|
81 | 81 | end |
|
82 | ||
|
82 | ||
|
83 | 83 | # Returns true if the role has the given permission |
|
84 | 84 | def has_permission?(perm) |
|
85 | 85 | !permissions.nil? && permissions.include?(perm.to_sym) |
|
86 | 86 | end |
|
87 | ||
|
87 | ||
|
88 | 88 | def <=>(role) |
|
89 | 89 | role ? position <=> role.position : -1 |
|
90 | 90 | end |
|
91 | ||
|
91 | ||
|
92 | 92 | def to_s |
|
93 | 93 | name |
|
94 | 94 | end |
|
95 | ||
|
95 | ||
|
96 | 96 | def name |
|
97 | 97 | case builtin |
|
98 | 98 | when 1; l(:label_role_non_member, :default => read_attribute(:name)) |
@@ -100,17 +100,17 class Role < ActiveRecord::Base | |||
|
100 | 100 | else; read_attribute(:name) |
|
101 | 101 | end |
|
102 | 102 | end |
|
103 | ||
|
103 | ||
|
104 | 104 | # Return true if the role is a builtin role |
|
105 | 105 | def builtin? |
|
106 | 106 | self.builtin != 0 |
|
107 | 107 | end |
|
108 | ||
|
108 | ||
|
109 | 109 | # Return true if the role is a project member role |
|
110 | 110 | def member? |
|
111 | 111 | !self.builtin? |
|
112 | 112 | end |
|
113 | ||
|
113 | ||
|
114 | 114 | # Return true if role is allowed to do the specified action |
|
115 | 115 | # action can be: |
|
116 | 116 | # * a parameter-like Hash (eg. :controller => 'projects', :action => 'edit') |
@@ -122,7 +122,7 class Role < ActiveRecord::Base | |||
|
122 | 122 | allowed_permissions.include? action |
|
123 | 123 | end |
|
124 | 124 | end |
|
125 | ||
|
125 | ||
|
126 | 126 | # Return all the permissions that can be given to the role |
|
127 | 127 | def setable_permissions |
|
128 | 128 | setable_permissions = Redmine::AccessControl.permissions - Redmine::AccessControl.public_permissions |
@@ -147,9 +147,9 class Role < ActiveRecord::Base | |||
|
147 | 147 | def self.anonymous |
|
148 | 148 | find_or_create_system_role(BUILTIN_ANONYMOUS, 'Anonymous') |
|
149 | 149 | end |
|
150 | ||
|
150 | ||
|
151 | 151 | private |
|
152 | ||
|
152 | ||
|
153 | 153 | def allowed_permissions |
|
154 | 154 | @allowed_permissions ||= permissions + Redmine::AccessControl.public_permissions.collect {|p| p.name} |
|
155 | 155 | end |
@@ -157,12 +157,12 private | |||
|
157 | 157 | def allowed_actions |
|
158 | 158 | @actions_allowed ||= allowed_permissions.inject([]) { |actions, permission| actions += Redmine::AccessControl.allowed_actions(permission) }.flatten |
|
159 | 159 | end |
|
160 | ||
|
160 | ||
|
161 | 161 | def check_deletable |
|
162 | 162 | raise "Can't delete role" if members.any? |
|
163 | 163 | raise "Can't delete builtin role" if builtin? |
|
164 | 164 | end |
|
165 | ||
|
165 | ||
|
166 | 166 | def self.find_or_create_system_role(builtin, name) |
|
167 | 167 | role = first(:conditions => {:builtin => builtin}) |
|
168 | 168 | if role.nil? |
General Comments 0
You need to be logged in to leave comments.
Login now