Commit 2b3e55c1 authored by jplang's avatar jplang
Browse files

Restores migration broken by r8182 and removes default scope on Role (#9800).

git-svn-id: https://svn.redmine.org/redmine/trunk@8213 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent 1a125c81
...@@ -30,7 +30,7 @@ class RolesController < ApplicationController ...@@ -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 ...@@ -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 ...@@ -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|
......
...@@ -26,7 +26,7 @@ class Role < ActiveRecord::Base ...@@ -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
......
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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment