diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2012-05-25 20:43:18 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2012-05-25 20:43:18 +0000 |
commit | aa18cd54c7ec55f0b326ef2e8c0302801ad2bdef (patch) | |
tree | 5f3c7cd90d9723a3f7e2c08b5f3f5d86bf9ea794 /app/models/role.rb | |
parent | 59cbc68dde9cda2178e9194746f60a2161d973bf (diff) | |
download | redmine-aa18cd54c7ec55f0b326ef2e8c0302801ad2bdef.tar.gz redmine-aa18cd54c7ec55f0b326ef2e8c0302801ad2bdef.zip |
Code cleanup.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9715 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models/role.rb')
-rw-r--r-- | app/models/role.rb | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/app/models/role.rb b/app/models/role.rb index ee59ce905..c8a1028da 100644 --- a/app/models/role.rb +++ b/app/models/role.rb @@ -26,11 +26,11 @@ class Role < ActiveRecord::Base ['own', :label_issues_visibility_own] ] - scope :sorted, {:order => 'builtin, position'} - scope :givable, { :conditions => "builtin = 0", :order => 'position' } + scope :sorted, order("#{table_name}.builtin ASC, #{table_name}.position ASC") + scope :givable, order("#{table_name}.position ASC").where(:builtin => 0) scope :builtin, lambda { |*args| - compare = 'not' if args.first == true - { :conditions => "#{compare} builtin = 0" } + compare = (args.first == true ? 'not' : '') + where("#{compare} builtin = 0") } before_destroy :check_deletable @@ -87,7 +87,15 @@ class Role < ActiveRecord::Base end def <=>(role) - role ? position <=> role.position : -1 + if role + if builtin == role.builtin + position <=> role.position + else + builtin <=> role.builtin + end + else + -1 + end end def to_s @@ -134,7 +142,7 @@ class Role < ActiveRecord::Base # Find all the roles that can be given to a project member def self.find_all_givable - find(:all, :conditions => {:builtin => 0}, :order => 'position') + Role.givable.all end # Return the builtin 'non member' role. If the role doesn't exist, @@ -165,7 +173,7 @@ private end def self.find_or_create_system_role(builtin, name) - role = first(:conditions => {:builtin => builtin}) + role = where(:builtin => builtin).first if role.nil? role = create(:name => name, :position => 0) do |r| r.builtin = builtin |