comparison app/controllers/comments_controller.rb @ 1115:433d4f72a19b redmine-2.2

Update to Redmine SVN revision 11137 on 2.2-stable branch
author Chris Cannam
date Mon, 07 Jan 2013 12:01:42 +0000
parents 5f33065ddc4b
children 622f24f53b42
comparison
equal deleted inserted replaced
929:5f33065ddc4b 1115:433d4f72a19b
1 # Redmine - project management software
2 # Copyright (C) 2006-2012 Jean-Philippe Lang
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
1 class CommentsController < ApplicationController 18 class CommentsController < ApplicationController
2 default_search_scope :news 19 default_search_scope :news
3 model_object News 20 model_object News
4 before_filter :find_model_object 21 before_filter :find_model_object
5 before_filter :find_project_from_association 22 before_filter :find_project_from_association
6 before_filter :authorize 23 before_filter :authorize
7 24
8 verify :method => :post, :only => :create, :render => {:nothing => true, :status => :method_not_allowed }
9 def create 25 def create
26 raise Unauthorized unless @news.commentable?
27
10 @comment = Comment.new 28 @comment = Comment.new
11 @comment.safe_attributes = params[:comment] 29 @comment.safe_attributes = params[:comment]
12 @comment.author = User.current 30 @comment.author = User.current
13 if @news.comments << @comment 31 if @news.comments << @comment
14 flash[:notice] = l(:label_comment_added) 32 flash[:notice] = l(:label_comment_added)
15 end 33 end
16 34
17 redirect_to :controller => 'news', :action => 'show', :id => @news 35 redirect_to :controller => 'news', :action => 'show', :id => @news
18 end 36 end
19 37
20 verify :method => :delete, :only => :destroy, :render => {:nothing => true, :status => :method_not_allowed }
21 def destroy 38 def destroy
22 @news.comments.find(params[:comment_id]).destroy 39 @news.comments.find(params[:comment_id]).destroy
23 redirect_to :controller => 'news', :action => 'show', :id => @news 40 redirect_to :controller => 'news', :action => 'show', :id => @news
24 end 41 end
25 42
31 super 48 super
32 @news = @object 49 @news = @object
33 @comment = nil 50 @comment = nil
34 @news 51 @news
35 end 52 end
36
37 end 53 end