]> git.openstreetmap.org Git - rails.git/blob - app/controllers/diary_comments_controller.rb
Add frozen_string_literal comments to ruby files
[rails.git] / app / controllers / diary_comments_controller.rb
1 # frozen_string_literal: true
2
3 class DiaryCommentsController < ApplicationController
4   layout :site_layout
5
6   before_action :authorize_web
7   before_action :set_locale
8   before_action :check_database_readable
9
10   authorize_resource
11
12   before_action :check_database_writable
13
14   allow_thirdparty_images :only => :create
15
16   def create
17     @diary_entry = DiaryEntry.find(params[:id])
18     @comments = @diary_entry.visible_comments
19     @diary_comment = @diary_entry.comments.build(comment_params)
20     @diary_comment.user = current_user
21     if @diary_comment.save
22
23       # Notify current subscribers of the new comment
24       @diary_entry.subscribers.visible.each do |user|
25         UserMailer.diary_comment_notification(@diary_comment, user).deliver_later if current_user != user
26       end
27
28       # Add the commenter to the subscribers if necessary
29       @diary_entry.subscriptions.create(:user => current_user) unless @diary_entry.subscribers.exists?(current_user.id)
30
31       redirect_to diary_entry_path(@diary_entry.user, @diary_entry, :anchor => "comment#{@diary_comment.id}")
32     else
33       render :action => "new"
34     end
35   rescue ActiveRecord::RecordNotFound
36     render "diary_entries/no_such_entry", :status => :not_found
37   end
38
39   def hide
40     comment = DiaryComment.find(params[:comment])
41     comment.update(:visible => false)
42     redirect_to diary_entry_path(comment.diary_entry.user, comment.diary_entry)
43   end
44
45   def unhide
46     comment = DiaryComment.find(params[:comment])
47     comment.update(:visible => true)
48     redirect_to diary_entry_path(comment.diary_entry.user, comment.diary_entry)
49   end
50
51   private
52
53   ##
54   # return permitted diary comment parameters
55   def comment_params
56     params.expect(:diary_comment => [:body])
57   end
58 end