annotate app/controllers/comments_controller.rb @ 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@1115 1 # Redmine - project management software
Chris@1494 2 # Copyright (C) 2006-2014 Jean-Philippe Lang
Chris@1115 3 #
Chris@1115 4 # This program is free software; you can redistribute it and/or
Chris@1115 5 # modify it under the terms of the GNU General Public License
Chris@1115 6 # as published by the Free Software Foundation; either version 2
Chris@1115 7 # of the License, or (at your option) any later version.
Chris@1115 8 #
Chris@1115 9 # This program is distributed in the hope that it will be useful,
Chris@1115 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1115 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1115 12 # GNU General Public License for more details.
Chris@1115 13 #
Chris@1115 14 # You should have received a copy of the GNU General Public License
Chris@1115 15 # along with this program; if not, write to the Free Software
Chris@1115 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1115 17
chris@22 18 class CommentsController < ApplicationController
chris@22 19 default_search_scope :news
chris@22 20 model_object News
chris@22 21 before_filter :find_model_object
chris@22 22 before_filter :find_project_from_association
chris@22 23 before_filter :authorize
chris@22 24
chris@22 25 def create
Chris@1115 26 raise Unauthorized unless @news.commentable?
Chris@1115 27
Chris@929 28 @comment = Comment.new
Chris@929 29 @comment.safe_attributes = params[:comment]
chris@22 30 @comment.author = User.current
chris@22 31 if @news.comments << @comment
chris@22 32 flash[:notice] = l(:label_comment_added)
chris@22 33 end
Chris@909 34
Chris@1464 35 redirect_to news_path(@news)
chris@22 36 end
chris@22 37
chris@22 38 def destroy
chris@22 39 @news.comments.find(params[:comment_id]).destroy
Chris@1464 40 redirect_to news_path(@news)
chris@22 41 end
chris@22 42
chris@22 43 private
chris@22 44
chris@22 45 # ApplicationController's find_model_object sets it based on the controller
chris@22 46 # name so it needs to be overriden and set to @news instead
chris@22 47 def find_model_object
chris@22 48 super
chris@22 49 @news = @object
chris@22 50 @comment = nil
chris@22 51 @news
chris@22 52 end
chris@22 53 end