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
This commit is contained in:
Jean-Philippe Lang 2011-12-14 22:24:20 +00:00
parent 7d2298f39c
commit 7c00a4a11f
3 changed files with 5 additions and 5 deletions

View File

@ -30,7 +30,7 @@ class RolesController < ApplicationController
def new def new
# Prefills the form with 'Non member' role permissions # Prefills the form with 'Non member' role permissions
@role = Role.new(params[:role] || {:permissions => Role.non_member.permissions}) @role = Role.new(params[:role] || {:permissions => Role.non_member.permissions})
@roles = Role.all @roles = Role.sorted.all
end end
def create def create
@ -43,7 +43,7 @@ class RolesController < ApplicationController
flash[:notice] = l(:notice_successful_create) flash[:notice] = l(:notice_successful_create)
redirect_to :action => 'index' redirect_to :action => 'index'
else else
@roles = Role.all @roles = Role.sorted.all
render :action => 'new' render :action => 'new'
end end
end end
@ -70,7 +70,7 @@ class RolesController < ApplicationController
end end
def permissions def permissions
@roles = Role.find(:all, :order => 'builtin, position') @roles = Role.sorted.all
@permissions = Redmine::AccessControl.permissions.select { |p| !p.public? } @permissions = Redmine::AccessControl.permissions.select { |p| !p.public? }
if request.post? if request.post?
@roles.each do |role| @roles.each do |role|

View File

@ -26,7 +26,7 @@ class Role < ActiveRecord::Base
['own', :label_issues_visibility_own] ['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 :givable, { :conditions => "builtin = 0", :order => 'position' }
named_scope :builtin, lambda { |*args| named_scope :builtin, lambda { |*args|
compare = 'not' if args.first == true compare = 'not' if args.first == true

View File

@ -1,7 +1,7 @@
class AddRolePosition < ActiveRecord::Migration class AddRolePosition < ActiveRecord::Migration
def self.up def self.up
add_column :roles, :position, :integer, :default => 1 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 end
def self.down def self.down