diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2011-12-14 22:24:20 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2011-12-14 22:24:20 +0000 |
commit | 7c00a4a11fc33bb5016cb6b1e401a9ecf56dc3f5 (patch) | |
tree | 72f6cc21b4a0778703a4cb4f496a05f012ee6963 | |
parent | 7d2298f39c609ec79dd16f27ef69885a7c390d00 (diff) | |
download | redmine-7c00a4a11fc33bb5016cb6b1e401a9ecf56dc3f5.tar.gz redmine-7c00a4a11fc33bb5016cb6b1e401a9ecf56dc3f5.zip |
Restores migration broken by r8182 and removes default scope on Role (#9800).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8213 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r-- | app/controllers/roles_controller.rb | 6 | ||||
-rw-r--r-- | app/models/role.rb | 2 | ||||
-rw-r--r-- | db/migrate/020_add_role_position.rb | 2 |
3 files changed, 5 insertions, 5 deletions
diff --git a/app/controllers/roles_controller.rb b/app/controllers/roles_controller.rb index b74404470..cfdc133bf 100644 --- a/app/controllers/roles_controller.rb +++ b/app/controllers/roles_controller.rb @@ -30,7 +30,7 @@ class RolesController < ApplicationController def new # Prefills the form with 'Non member' role permissions @role = Role.new(params[:role] || {:permissions => Role.non_member.permissions}) - @roles = Role.all + @roles = Role.sorted.all end def create @@ -43,7 +43,7 @@ class RolesController < ApplicationController flash[:notice] = l(:notice_successful_create) redirect_to :action => 'index' else - @roles = Role.all + @roles = Role.sorted.all render :action => 'new' end end @@ -70,7 +70,7 @@ class RolesController < ApplicationController end def permissions - @roles = Role.find(:all, :order => 'builtin, position') + @roles = Role.sorted.all @permissions = Redmine::AccessControl.permissions.select { |p| !p.public? } if request.post? @roles.each do |role| diff --git a/app/models/role.rb b/app/models/role.rb index e0c0fef1c..44bb340c3 100644 --- a/app/models/role.rb +++ b/app/models/role.rb @@ -26,7 +26,7 @@ class Role < ActiveRecord::Base ['own', :label_issues_visibility_own] ] - default_scope :order => 'builtin, position' + named_scope :sorted, {:order => 'builtin, position'} named_scope :givable, { :conditions => "builtin = 0", :order => 'position' } named_scope :builtin, lambda { |*args| compare = 'not' if args.first == true diff --git a/db/migrate/020_add_role_position.rb b/db/migrate/020_add_role_position.rb index 0012833fe..48ac89a36 100644 --- a/db/migrate/020_add_role_position.rb +++ b/db/migrate/020_add_role_position.rb @@ -1,7 +1,7 @@ class AddRolePosition < ActiveRecord::Migration def self.up add_column :roles, :position, :integer, :default => 1 - Role.update_all("position = (SELECT COUNT(*) FROM #{Role.table_name} r WHERE r.id < id) + 1") + Role.all.each_with_index {|role, i| role.update_attribute(:position, i+1)} end def self.down |