annotate .svn/pristine/8c/8c660d1a6e08b50e40cfcf882882d2414791e6df.svn-base @ 1628:9c5f8e24dadc live tip

Quieten this cron script
author Chris Cannam
date Tue, 25 Aug 2020 11:38:49 +0100
parents e248c7af89ec
children
rev   line source
Chris@1494 1 # Redmine - project management software
Chris@1494 2 # Copyright (C) 2006-2014 Jean-Philippe Lang
Chris@1494 3 #
Chris@1494 4 # This program is free software; you can redistribute it and/or
Chris@1494 5 # modify it under the terms of the GNU General Public License
Chris@1494 6 # as published by the Free Software Foundation; either version 2
Chris@1494 7 # of the License, or (at your option) any later version.
Chris@1494 8 #
Chris@1494 9 # This program is distributed in the hope that it will be useful,
Chris@1494 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1494 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1494 12 # GNU General Public License for more details.
Chris@1494 13 #
Chris@1494 14 # You should have received a copy of the GNU General Public License
Chris@1494 15 # along with this program; if not, write to the Free Software
Chris@1494 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1494 17
Chris@1494 18 class MessagesController < ApplicationController
Chris@1494 19 menu_item :boards
Chris@1494 20 default_search_scope :messages
Chris@1494 21 before_filter :find_board, :only => [:new, :preview]
Chris@1494 22 before_filter :find_attachments, :only => [:preview]
Chris@1494 23 before_filter :find_message, :except => [:new, :preview]
Chris@1494 24 before_filter :authorize, :except => [:preview, :edit, :destroy]
Chris@1494 25
Chris@1494 26 helper :boards
Chris@1494 27 helper :watchers
Chris@1494 28 helper :attachments
Chris@1494 29 include AttachmentsHelper
Chris@1494 30
Chris@1494 31 REPLIES_PER_PAGE = 25 unless const_defined?(:REPLIES_PER_PAGE)
Chris@1494 32
Chris@1494 33 # Show a topic and its replies
Chris@1494 34 def show
Chris@1494 35 page = params[:page]
Chris@1494 36 # Find the page of the requested reply
Chris@1494 37 if params[:r] && page.nil?
Chris@1494 38 offset = @topic.children.where("#{Message.table_name}.id < ?", params[:r].to_i).count
Chris@1494 39 page = 1 + offset / REPLIES_PER_PAGE
Chris@1494 40 end
Chris@1494 41
Chris@1494 42 @reply_count = @topic.children.count
Chris@1494 43 @reply_pages = Paginator.new @reply_count, REPLIES_PER_PAGE, page
Chris@1494 44 @replies = @topic.children.
Chris@1494 45 includes(:author, :attachments, {:board => :project}).
Chris@1494 46 reorder("#{Message.table_name}.created_on ASC").
Chris@1494 47 limit(@reply_pages.per_page).
Chris@1494 48 offset(@reply_pages.offset).
Chris@1494 49 all
Chris@1494 50
Chris@1494 51 @reply = Message.new(:subject => "RE: #{@message.subject}")
Chris@1494 52 render :action => "show", :layout => false if request.xhr?
Chris@1494 53 end
Chris@1494 54
Chris@1494 55 # Create a new topic
Chris@1494 56 def new
Chris@1494 57 @message = Message.new
Chris@1494 58 @message.author = User.current
Chris@1494 59 @message.board = @board
Chris@1494 60 @message.safe_attributes = params[:message]
Chris@1494 61 if request.post?
Chris@1494 62 @message.save_attachments(params[:attachments])
Chris@1494 63 if @message.save
Chris@1494 64 call_hook(:controller_messages_new_after_save, { :params => params, :message => @message})
Chris@1494 65 render_attachment_warning_if_needed(@message)
Chris@1494 66 redirect_to board_message_path(@board, @message)
Chris@1494 67 end
Chris@1494 68 end
Chris@1494 69 end
Chris@1494 70
Chris@1494 71 # Reply to a topic
Chris@1494 72 def reply
Chris@1494 73 @reply = Message.new
Chris@1494 74 @reply.author = User.current
Chris@1494 75 @reply.board = @board
Chris@1494 76 @reply.safe_attributes = params[:reply]
Chris@1494 77 @topic.children << @reply
Chris@1494 78 if !@reply.new_record?
Chris@1494 79 call_hook(:controller_messages_reply_after_save, { :params => params, :message => @reply})
Chris@1494 80 attachments = Attachment.attach_files(@reply, params[:attachments])
Chris@1494 81 render_attachment_warning_if_needed(@reply)
Chris@1494 82 end
Chris@1494 83 redirect_to board_message_path(@board, @topic, :r => @reply)
Chris@1494 84 end
Chris@1494 85
Chris@1494 86 # Edit a message
Chris@1494 87 def edit
Chris@1494 88 (render_403; return false) unless @message.editable_by?(User.current)
Chris@1494 89 @message.safe_attributes = params[:message]
Chris@1494 90 if request.post? && @message.save
Chris@1494 91 attachments = Attachment.attach_files(@message, params[:attachments])
Chris@1494 92 render_attachment_warning_if_needed(@message)
Chris@1494 93 flash[:notice] = l(:notice_successful_update)
Chris@1494 94 @message.reload
Chris@1494 95 redirect_to board_message_path(@message.board, @message.root, :r => (@message.parent_id && @message.id))
Chris@1494 96 end
Chris@1494 97 end
Chris@1494 98
Chris@1494 99 # Delete a messages
Chris@1494 100 def destroy
Chris@1494 101 (render_403; return false) unless @message.destroyable_by?(User.current)
Chris@1494 102 r = @message.to_param
Chris@1494 103 @message.destroy
Chris@1494 104 if @message.parent
Chris@1494 105 redirect_to board_message_path(@board, @message.parent, :r => r)
Chris@1494 106 else
Chris@1494 107 redirect_to project_board_path(@project, @board)
Chris@1494 108 end
Chris@1494 109 end
Chris@1494 110
Chris@1494 111 def quote
Chris@1494 112 @subject = @message.subject
Chris@1494 113 @subject = "RE: #{@subject}" unless @subject.starts_with?('RE:')
Chris@1494 114
Chris@1494 115 @content = "#{ll(Setting.default_language, :text_user_wrote, @message.author)}\n> "
Chris@1494 116 @content << @message.content.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]').gsub(/(\r?\n|\r\n?)/, "\n> ") + "\n\n"
Chris@1494 117 end
Chris@1494 118
Chris@1494 119 def preview
Chris@1494 120 message = @board.messages.find_by_id(params[:id])
Chris@1494 121 @text = (params[:message] || params[:reply])[:content]
Chris@1494 122 @previewed = message
Chris@1494 123 render :partial => 'common/preview'
Chris@1494 124 end
Chris@1494 125
Chris@1494 126 private
Chris@1494 127 def find_message
Chris@1494 128 return unless find_board
Chris@1494 129 @message = @board.messages.find(params[:id], :include => :parent)
Chris@1494 130 @topic = @message.root
Chris@1494 131 rescue ActiveRecord::RecordNotFound
Chris@1494 132 render_404
Chris@1494 133 end
Chris@1494 134
Chris@1494 135 def find_board
Chris@1494 136 @board = Board.find(params[:board_id], :include => :project)
Chris@1494 137 @project = @board.project
Chris@1494 138 rescue ActiveRecord::RecordNotFound
Chris@1494 139 render_404
Chris@1494 140 nil
Chris@1494 141 end
Chris@1494 142 end