1 class DiaryCommentsController < ApplicationController
3 include PaginationMethods
7 before_action :authorize_web
8 before_action :set_locale
9 before_action :check_database_readable
13 before_action :lookup_user, :only => :index
14 before_action :check_database_writable, :only => [:create, :hide, :unhide]
16 allow_thirdparty_images :only => :index
19 @title = t ".title", :user => @user.display_name
21 comments = DiaryComment.where(:user => @user)
22 comments = comments.visible unless can? :unhide, DiaryComment
24 @params = params.permit(:display_name, :before, :after)
26 @comments, @newer_comments_id, @older_comments_id = get_page_items(comments, :includes => [:user])
28 render :partial => "page" if turbo_frame_request_id == "pagination"
32 @entry = DiaryEntry.find(params[:id])
33 @comments = @entry.visible_comments
34 @diary_comment = @entry.comments.build(comment_params)
35 @diary_comment.user = current_user
36 if @diary_comment.save
38 # Notify current subscribers of the new comment
39 @entry.subscribers.visible.each do |user|
40 UserMailer.diary_comment_notification(@diary_comment, user).deliver_later if current_user != user
43 # Add the commenter to the subscribers if necessary
44 @entry.subscriptions.create(:user => current_user) unless @entry.subscribers.exists?(current_user.id)
46 redirect_to diary_entry_path(@entry.user, @entry, :anchor => "comment#{@diary_comment.id}")
48 render :action => "new"
50 rescue ActiveRecord::RecordNotFound
51 render "diary_entries/no_such_entry", :status => :not_found
55 comment = DiaryComment.find(params[:comment])
56 comment.update(:visible => false)
57 redirect_to diary_entry_path(comment.diary_entry.user, comment.diary_entry)
61 comment = DiaryComment.find(params[:comment])
62 comment.update(:visible => true)
63 redirect_to diary_entry_path(comment.diary_entry.user, comment.diary_entry)
69 # return permitted diary comment parameters
71 params.require(:diary_comment).permit(:body)