aboutsummaryrefslogtreecommitdiffstats
path: root/app/controllers/admin_comment_controller.rb
blob: 0aafb122a19eb4a737e77e7fc52b5a524c140a1f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# app/controllers/admin_comment_controller.rb:
# Controller for editing comments from the admin interface.
#
# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
# Email: hello@mysociety.org; WWW: http://www.mysociety.org/

class AdminCommentController < AdminController

    def edit
        @comment = Comment.find(params[:id])
    end

    def update
        @comment = Comment.find(params[:id])

        old_body = @comment.body
        old_visible = @comment.visible
        @comment.visible = params[:comment][:visible] == "true" ? true : false

        if @comment.update_attributes(params[:comment])
            @comment.info_request.log_event("edit_comment",
                { :comment_id => @comment.id,
                  :editor => admin_current_user(),
                  :old_body => old_body,
                  :body => @comment.body,
                  :old_visible => old_visible,
                  :visible => @comment.visible,
                })
            flash[:notice] = 'Comment successfully updated.'
            redirect_to admin_request_url(@comment.info_request)
        else
            render :action => 'edit'
        end
    end

end