##// END OF EJS Templates
Refactor builtin roles creation....
Jean-Philippe Lang -
r6179:cf56698d91ce
parent child
Show More
@@ -139,31 +139,17 class Role < ActiveRecord::Base
139 139 # Return the builtin 'non member' role. If the role doesn't exist,
140 140 # it will be created on the fly.
141 141 def self.non_member
142 non_member_role = find(:first, :conditions => {:builtin => BUILTIN_NON_MEMBER})
143 if non_member_role.nil?
144 non_member_role = create(:name => 'Non member', :position => 0) do |role|
145 role.builtin = BUILTIN_NON_MEMBER
146 end
147 raise 'Unable to create the non-member role.' if non_member_role.new_record?
148 end
149 non_member_role
142 find_or_create_system_role(BUILTIN_NON_MEMBER, 'Non member')
150 143 end
151 144
152 145 # Return the builtin 'anonymous' role. If the role doesn't exist,
153 146 # it will be created on the fly.
154 147 def self.anonymous
155 anonymous_role = find(:first, :conditions => {:builtin => BUILTIN_ANONYMOUS})
156 if anonymous_role.nil?
157 anonymous_role = create(:name => 'Anonymous', :position => 0) do |role|
158 role.builtin = BUILTIN_ANONYMOUS
159 end
160 raise 'Unable to create the anonymous role.' if anonymous_role.new_record?
161 end
162 anonymous_role
148 find_or_create_system_role(BUILTIN_ANONYMOUS, 'Anonymous')
163 149 end
164
165 150
166 151 private
152
167 153 def allowed_permissions
168 154 @allowed_permissions ||= permissions + Redmine::AccessControl.public_permissions.collect {|p| p.name}
169 155 end
@@ -176,4 +162,15 private
176 162 raise "Can't delete role" if members.any?
177 163 raise "Can't delete builtin role" if builtin?
178 164 end
165
166 def self.find_or_create_system_role(builtin, name)
167 role = first(:conditions => {:builtin => builtin})
168 if role.nil?
169 role = create(:name => name, :position => 0) do |r|
170 r.builtin = builtin
171 end
172 raise "Unable to create the #{name} role." if role.new_record?
173 end
174 role
175 end
179 176 end
General Comments 0
You need to be logged in to leave comments. Login now