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])
30 @entry = DiaryEntry.find(params[:id])
31 @comments = @entry.visible_comments
32 @diary_comment = @entry.comments.build(comment_params)
33 @diary_comment.user = current_user
34 if @diary_comment.save
36 # Notify current subscribers of the new comment
37 @entry.subscribers.visible.each do |user|
38 UserMailer.diary_comment_notification(@diary_comment, user).deliver_later if current_user != user
41 # Add the commenter to the subscribers if necessary
42 @entry.subscriptions.create(:user => current_user) unless @entry.subscribers.exists?(current_user.id)
44 redirect_to diary_entry_path(@entry.user, @entry, :anchor => "comment#{@diary_comment.id}")
46 render :action => "new"
48 rescue ActiveRecord::RecordNotFound
49 render "diary_entries/no_such_entry", :status => :not_found
53 comment = DiaryComment.find(params[:comment])
54 comment.update(:visible => false)
55 redirect_to diary_entry_path(comment.diary_entry.user, comment.diary_entry)
59 comment = DiaryComment.find(params[:comment])
60 comment.update(:visible => true)
61 redirect_to diary_entry_path(comment.diary_entry.user, comment.diary_entry)
67 # return permitted diary comment parameters
69 params.require(:diary_comment).permit(:body)