mirror of
https://github.com/redmine/redmine.git
synced 2025-11-02 11:25:55 +01:00
Forums enhancements:
* messages can now be edited/deleted (explicit permissions need to be given) * topics can be locked so that no reply can be added (only by users allowed to edit messages) * topics can be marked as sticky so that they always appear at the top of the list (only by users allowed to edit messages) git-svn-id: http://redmine.rubyforge.org/svn/trunk@926 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
@@ -17,22 +17,30 @@
|
||||
|
||||
class MessagesController < ApplicationController
|
||||
layout 'base'
|
||||
before_filter :find_project, :authorize
|
||||
before_filter :find_board, :only => :new
|
||||
before_filter :find_message, :except => :new
|
||||
before_filter :authorize
|
||||
|
||||
verify :method => :post, :only => [ :reply, :destroy ], :redirect_to => { :action => :show }
|
||||
|
||||
helper :attachments
|
||||
include AttachmentsHelper
|
||||
|
||||
# Show a topic and its replies
|
||||
def show
|
||||
@reply = Message.new(:subject => "RE: #{@message.subject}")
|
||||
render :action => "show", :layout => false if request.xhr?
|
||||
end
|
||||
|
||||
# Create a new topic
|
||||
def new
|
||||
@message = Message.new(params[:message])
|
||||
@message.author = User.current
|
||||
@message.board = @board
|
||||
@message.board = @board
|
||||
if params[:message] && User.current.allowed_to?(:edit_messages, @project)
|
||||
@message.locked = params[:message]['locked']
|
||||
@message.sticky = params[:message]['sticky']
|
||||
end
|
||||
if request.post? && @message.save
|
||||
params[:attachments].each { |file|
|
||||
Attachment.create(:container => @message, :file => file, :author => User.current) if file.size > 0
|
||||
@@ -41,24 +49,55 @@ class MessagesController < ApplicationController
|
||||
end
|
||||
end
|
||||
|
||||
# Reply to a topic
|
||||
def reply
|
||||
@reply = Message.new(params[:reply])
|
||||
@reply.author = User.current
|
||||
@reply.board = @board
|
||||
@message.children << @reply
|
||||
@topic.children << @reply
|
||||
if !@reply.new_record?
|
||||
params[:attachments].each { |file|
|
||||
Attachment.create(:container => @reply, :file => file, :author => User.current) if file.size > 0
|
||||
} if params[:attachments] and params[:attachments].is_a? Array
|
||||
end
|
||||
redirect_to :action => 'show', :id => @message
|
||||
redirect_to :action => 'show', :id => @topic
|
||||
end
|
||||
|
||||
# Edit a message
|
||||
def edit
|
||||
if params[:message] && User.current.allowed_to?(:edit_messages, @project)
|
||||
@message.locked = params[:message]['locked']
|
||||
@message.sticky = params[:message]['sticky']
|
||||
end
|
||||
if request.post? && @message.update_attributes(params[:message])
|
||||
params[:attachments].each { |file|
|
||||
Attachment.create(:container => @message, :file => file, :author => User.current) if file.size > 0
|
||||
} if params[:attachments] and params[:attachments].is_a? Array
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
redirect_to :action => 'show', :id => @topic
|
||||
end
|
||||
end
|
||||
|
||||
# Delete a messages
|
||||
def destroy
|
||||
@message.destroy
|
||||
redirect_to @message.parent.nil? ?
|
||||
{ :controller => 'boards', :action => 'show', :project_id => @project, :id => @board } :
|
||||
{ :action => 'show', :id => @message.parent }
|
||||
end
|
||||
|
||||
private
|
||||
def find_project
|
||||
def find_message
|
||||
find_board
|
||||
@message = @board.messages.find(params[:id], :include => :parent)
|
||||
@topic = @message.root
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
def find_board
|
||||
@board = Board.find(params[:board_id], :include => :project)
|
||||
@project = @board.project
|
||||
@message = @board.topics.find(params[:id]) if params[:id]
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user