]> source.dussan.org Git - redmine.git/commitdiff
Prevent mass-assignment when adding/updating a forum (#10390).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Tue, 6 Mar 2012 21:36:28 +0000 (21:36 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Tue, 6 Mar 2012 21:36:28 +0000 (21:36 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9140 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/boards_controller.rb
app/models/board.rb
test/functional/boards_controller_test.rb

index e4d7749bc0afd947737920ce76396efa7086a8b6..380933960951c52a3cb3b1c4c014ed5ff74da52e 100644 (file)
@@ -60,11 +60,13 @@ class BoardsController < ApplicationController
   end
 
   def new
-    @board = @project.boards.build(params[:board])
+    @board = @project.boards.build
+    @board.safe_attributes = params[:board]
   end
 
   def create
-    @board = @project.boards.build(params[:board])
+    @board = @project.boards.build
+    @board.safe_attributes = params[:board]
     if @board.save
       flash[:notice] = l(:notice_successful_create)
       redirect_to_settings_in_projects
@@ -77,7 +79,8 @@ class BoardsController < ApplicationController
   end
 
   def update
-    if @board.update_attributes(params[:board])
+    @board.safe_attributes = params[:board]
+    if @board.save
       redirect_to_settings_in_projects
     else
       render :action => 'edit'
index a76868d09d9458db5eed20045863372bce6dec01..40fd356737b46ea69eb01ef82e2ca11d71761e4f 100644 (file)
@@ -16,6 +16,7 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
 class Board < ActiveRecord::Base
+  include Redmine::SafeAttributes
   belongs_to :project
   has_many :topics, :class_name => 'Message', :conditions => "#{Message.table_name}.parent_id IS NULL", :order => "#{Message.table_name}.created_on DESC"
   has_many :messages, :dependent => :destroy, :order => "#{Message.table_name}.created_on DESC"
@@ -30,6 +31,8 @@ class Board < ActiveRecord::Base
   named_scope :visible, lambda {|*args| { :include => :project,
                                           :conditions => Project.allowed_to_condition(args.shift || User.current, :view_messages, *args) } }
 
+  safe_attributes 'name', 'description', 'move_to'
+
   def visible?(user=User.current)
     !user.nil? && user.allowed_to?(:view_messages, project)
   end
index c848b3e1ac75a193614323bb8593044675875591..03dee9de8b301d5de268714239b5ddcc96711ef8 100644 (file)
@@ -122,6 +122,14 @@ class BoardsControllerTest < ActionController::TestCase
     assert_equal 'Testing', Board.find(2).name
   end
 
+  def test_update_position
+    @request.session[:user_id] = 2
+    put :update, :project_id => 1, :id => 2, :board => { :move_to => 'highest'}
+    assert_redirected_to '/projects/ecookbook/settings/boards'
+    board = Board.find(2)
+    assert_equal 1, board.position
+  end
+
   def test_update_with_failure
     @request.session[:user_id] = 2
     put :update, :project_id => 1, :id => 2, :board => { :name => '', :description => 'Testing board update'}