diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2011-07-20 16:34:55 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2011-07-20 16:34:55 +0000 |
commit | cf56698d91cedb461726200cf0e32834e7124cda (patch) | |
tree | 91a99d5554d535d1a884376554064f879495aa4b /app/models/role.rb | |
parent | 4f92276654fe7560e44cb8ae82df7f87fdd60eb1 (diff) | |
download | redmine-cf56698d91cedb461726200cf0e32834e7124cda.tar.gz redmine-cf56698d91cedb461726200cf0e32834e7124cda.zip |
Refactor builtin roles creation.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@6299 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models/role.rb')
-rw-r--r-- | app/models/role.rb | 31 |
1 files changed, 14 insertions, 17 deletions
diff --git a/app/models/role.rb b/app/models/role.rb index c11111c0a..4000d645e 100644 --- a/app/models/role.rb +++ b/app/models/role.rb @@ -139,31 +139,17 @@ class Role < ActiveRecord::Base # Return the builtin 'non member' role. If the role doesn't exist, # it will be created on the fly. def self.non_member - non_member_role = find(:first, :conditions => {:builtin => BUILTIN_NON_MEMBER}) - if non_member_role.nil? - non_member_role = create(:name => 'Non member', :position => 0) do |role| - role.builtin = BUILTIN_NON_MEMBER - end - raise 'Unable to create the non-member role.' if non_member_role.new_record? - end - non_member_role + find_or_create_system_role(BUILTIN_NON_MEMBER, 'Non member') end # Return the builtin 'anonymous' role. If the role doesn't exist, # it will be created on the fly. def self.anonymous - anonymous_role = find(:first, :conditions => {:builtin => BUILTIN_ANONYMOUS}) - if anonymous_role.nil? - anonymous_role = create(:name => 'Anonymous', :position => 0) do |role| - role.builtin = BUILTIN_ANONYMOUS - end - raise 'Unable to create the anonymous role.' if anonymous_role.new_record? - end - anonymous_role + find_or_create_system_role(BUILTIN_ANONYMOUS, 'Anonymous') end - private + def allowed_permissions @allowed_permissions ||= permissions + Redmine::AccessControl.public_permissions.collect {|p| p.name} end @@ -176,4 +162,15 @@ private raise "Can't delete role" if members.any? raise "Can't delete builtin role" if builtin? end + + def self.find_or_create_system_role(builtin, name) + role = first(:conditions => {:builtin => builtin}) + if role.nil? + role = create(:name => name, :position => 0) do |r| + r.builtin = builtin + end + raise "Unable to create the #{name} role." if role.new_record? + end + role + end end |