Adds the ability to move threads between project forums (#2452). 'Edit message' permission is required.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2649 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
3d65ed7aa0
commit
ca166b30e1
|
@ -46,6 +46,7 @@ class BoardsController < ApplicationController
|
||||||
:include => [:author, {:last_reply => :author}],
|
:include => [:author, {:last_reply => :author}],
|
||||||
:limit => @topic_pages.items_per_page,
|
:limit => @topic_pages.items_per_page,
|
||||||
:offset => @topic_pages.current.offset
|
:offset => @topic_pages.current.offset
|
||||||
|
@message = Message.new
|
||||||
render :action => 'show', :layout => !request.xhr?
|
render :action => 'show', :layout => !request.xhr?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -73,7 +73,8 @@ class MessagesController < ApplicationController
|
||||||
if request.post? && @message.update_attributes(params[:message])
|
if request.post? && @message.update_attributes(params[:message])
|
||||||
attach_files(@message, params[:attachments])
|
attach_files(@message, params[:attachments])
|
||||||
flash[:notice] = l(:notice_successful_update)
|
flash[:notice] = l(:notice_successful_update)
|
||||||
redirect_to :action => 'show', :id => @topic
|
@message.reload
|
||||||
|
redirect_to :action => 'show', :board_id => @message.board, :id => @message.root
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -26,4 +26,17 @@ class Board < ActiveRecord::Base
|
||||||
validates_presence_of :name, :description
|
validates_presence_of :name, :description
|
||||||
validates_length_of :name, :maximum => 30
|
validates_length_of :name, :maximum => 30
|
||||||
validates_length_of :description, :maximum => 255
|
validates_length_of :description, :maximum => 255
|
||||||
|
|
||||||
|
def reset_counters!
|
||||||
|
self.class.reset_counters!(id)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Updates topics_count, messages_count and last_message_id attributes for +board_id+
|
||||||
|
def self.reset_counters!(board_id)
|
||||||
|
board_id = board_id.to_i
|
||||||
|
update_all("topics_count = (SELECT COUNT(*) FROM #{Message.table_name} WHERE board_id=#{board_id} AND parent_id IS NULL)," +
|
||||||
|
" messages_count = (SELECT COUNT(*) FROM #{Message.table_name} WHERE board_id=#{board_id})," +
|
||||||
|
" last_message_id = (SELECT MAX(id) FROM #{Message.table_name} WHERE board_id=#{board_id})",
|
||||||
|
["id = ?", board_id])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -37,7 +37,7 @@ class Message < ActiveRecord::Base
|
||||||
acts_as_watchable
|
acts_as_watchable
|
||||||
|
|
||||||
attr_protected :locked, :sticky
|
attr_protected :locked, :sticky
|
||||||
validates_presence_of :subject, :content
|
validates_presence_of :board, :subject, :content
|
||||||
validates_length_of :subject, :maximum => 255
|
validates_length_of :subject, :maximum => 255
|
||||||
|
|
||||||
after_create :add_author_as_watcher
|
after_create :add_author_as_watcher
|
||||||
|
@ -48,21 +48,22 @@ class Message < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def after_create
|
def after_create
|
||||||
board.update_attribute(:last_message_id, self.id)
|
|
||||||
board.increment! :messages_count
|
|
||||||
if parent
|
if parent
|
||||||
parent.reload.update_attribute(:last_reply_id, self.id)
|
parent.reload.update_attribute(:last_reply_id, self.id)
|
||||||
else
|
end
|
||||||
board.increment! :topics_count
|
board.reset_counters!
|
||||||
|
end
|
||||||
|
|
||||||
|
def after_update
|
||||||
|
if board_id_changed?
|
||||||
|
Message.update_all("board_id = #{board_id}", ["id = ? OR parent_id = ?", root.id, root.id])
|
||||||
|
Board.reset_counters!(board_id_was)
|
||||||
|
Board.reset_counters!(board_id)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def after_destroy
|
def after_destroy
|
||||||
# The following line is required so that the previous counter
|
board.reset_counters!
|
||||||
# updates (due to children removal) are not overwritten
|
|
||||||
board.reload
|
|
||||||
board.decrement! :messages_count
|
|
||||||
board.decrement! :topics_count unless parent
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def sticky?
|
def sticky?
|
||||||
|
|
|
@ -12,6 +12,11 @@
|
||||||
<% end %>
|
<% end %>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
<% if !replying && !@message.new_record? && User.current.allowed_to?(:edit_messages, @project) %>
|
||||||
|
<p><label><%= l(:label_board) %></label><br />
|
||||||
|
<%= f.select :board_id, @project.boards.collect {|b| [b.name, b.id]} %></p>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
<p><%= f.text_area :content, :cols => 80, :rows => 15, :class => 'wiki-edit', :id => 'message_content' %></p>
|
<p><%= f.text_area :content, :cols => 80, :rows => 15, :class => 'wiki-edit', :id => 'message_content' %></p>
|
||||||
<%= wikitoolbar_for 'message_content' %>
|
<%= wikitoolbar_for 'message_content' %>
|
||||||
<!--[eoform:message]-->
|
<!--[eoform:message]-->
|
||||||
|
|
|
@ -6,8 +6,8 @@ boards_001:
|
||||||
id: 1
|
id: 1
|
||||||
description: Help board
|
description: Help board
|
||||||
position: 1
|
position: 1
|
||||||
last_message_id: 5
|
last_message_id: 6
|
||||||
messages_count: 5
|
messages_count: 6
|
||||||
boards_002:
|
boards_002:
|
||||||
name: Discussion
|
name: Discussion
|
||||||
project_id: 1
|
project_id: 1
|
||||||
|
|
|
@ -1,3 +1,20 @@
|
||||||
|
# Redmine - project management software
|
||||||
|
# Copyright (C) 2006-2009 Jean-Philippe Lang
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or
|
||||||
|
# modify it under the terms of the GNU General Public License
|
||||||
|
# as published by the Free Software Foundation; either version 2
|
||||||
|
# of the License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
require File.dirname(__FILE__) + '/../test_helper'
|
require File.dirname(__FILE__) + '/../test_helper'
|
||||||
|
|
||||||
class MessageTest < Test::Unit::TestCase
|
class MessageTest < Test::Unit::TestCase
|
||||||
|
@ -47,6 +64,23 @@ class MessageTest < Test::Unit::TestCase
|
||||||
assert @message.watched_by?(reply_author)
|
assert @message.watched_by?(reply_author)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_moving_message_should_update_counters
|
||||||
|
@message = Message.find(1)
|
||||||
|
assert_no_difference 'Message.count' do
|
||||||
|
# Previous board
|
||||||
|
assert_difference 'Board.find(1).topics_count', -1 do
|
||||||
|
assert_difference 'Board.find(1).messages_count', -(1 + @message.replies_count) do
|
||||||
|
# New board
|
||||||
|
assert_difference 'Board.find(2).topics_count' do
|
||||||
|
assert_difference 'Board.find(2).messages_count', (1 + @message.replies_count) do
|
||||||
|
@message.update_attributes(:board_id => 2)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_destroy_topic
|
def test_destroy_topic
|
||||||
message = Message.find(1)
|
message = Message.find(1)
|
||||||
board = message.board
|
board = message.board
|
||||||
|
|
Loading…
Reference in New Issue