annotate .svn/pristine/db/dbe1bda8432254ab1c9b544c6336106917863bf8.svn-base @ 1628:9c5f8e24dadc live tip

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