Chris@1115: # Redmine - project management software Chris@1115: # Copyright (C) 2006-2012 Jean-Philippe Lang Chris@1115: # Chris@1115: # This program is free software; you can redistribute it and/or Chris@1115: # modify it under the terms of the GNU General Public License Chris@1115: # as published by the Free Software Foundation; either version 2 Chris@1115: # of the License, or (at your option) any later version. Chris@1115: # Chris@1115: # This program is distributed in the hope that it will be useful, Chris@1115: # but WITHOUT ANY WARRANTY; without even the implied warranty of Chris@1115: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Chris@1115: # GNU General Public License for more details. Chris@1115: # Chris@1115: # You should have received a copy of the GNU General Public License Chris@1115: # along with this program; if not, write to the Free Software Chris@1115: # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Chris@1115: chris@22: class CommentsController < ApplicationController chris@22: default_search_scope :news chris@22: model_object News chris@22: before_filter :find_model_object chris@22: before_filter :find_project_from_association chris@22: before_filter :authorize chris@22: chris@22: def create Chris@1115: raise Unauthorized unless @news.commentable? Chris@1115: Chris@929: @comment = Comment.new Chris@929: @comment.safe_attributes = params[:comment] chris@22: @comment.author = User.current chris@22: if @news.comments << @comment chris@22: flash[:notice] = l(:label_comment_added) chris@22: end Chris@909: chris@22: redirect_to :controller => 'news', :action => 'show', :id => @news chris@22: end chris@22: chris@22: def destroy chris@22: @news.comments.find(params[:comment_id]).destroy chris@22: redirect_to :controller => 'news', :action => 'show', :id => @news chris@22: end chris@22: chris@22: private chris@22: chris@22: # ApplicationController's find_model_object sets it based on the controller chris@22: # name so it needs to be overriden and set to @news instead chris@22: def find_model_object chris@22: super chris@22: @news = @object chris@22: @comment = nil chris@22: @news chris@22: end chris@22: end