summaryrefslogtreecommitdiff
path: root/app/controllers/posts/comments/hides_controller.rb
blob: 10fbfac4cfe1ac99160c1f530f313c219f40905e (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
37
38
39
40
# frozen_string_literal: true

class Posts::Comments::HidesController < ApplicationController
  before_action :load_post
  before_action :load_comment
  before_action :check_auth

  def create
    ReportableHider.new(@comment, user: current_user, reason: params[:deletion_reason]).save
    # HidableLogger.log(@comment, 'Deleted', current_user.name, params[:deletion_reason])

    flash[:notice] = t('comments.destroy.soft_removed')

    redirect_to post_path(@post, anchor: "comment_#{@comment.id}")
  end

  def destroy
    Unhider.new(@comment).save
    # HidableLogger.log(@comment, 'Restored', current_user.name)

    respond_to do |format|
      format.html { redirect_to post_path(@post, anchor: "comment_#{@comment.id}") }
      format.json { render json: :ok }
    end
  end

  private

  def load_post
    @post = Post.find(params[:post_id])
  end

  def load_comment
    @comment = @post.comments.find(params[:comment_id])
  end

  def check_auth
    authorize! :hide, @comment
  end
end