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
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|
......
......@@ -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
......
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
......
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