annotate .svn/pristine/6f/6fb6f5177f90bcc2602109132f0fff373aeedf99.svn-base @ 1628:9c5f8e24dadc live tip

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