# frozen_string_literal: true class Posts::HidesController < ApplicationController before_action :load_post before_action :check_auth def create PostHider.new(@post, user: current_user, reason: params[:deletion_reason]).save redirect_to post_path(@post), notice: t('posts.destroy.success', id: @post.id) end def update if params[:deletion_reason].blank? flash[:error] = t('posts.errors.blank_deletion_reason') respond_to do |format| format.html { redirect_to post_path(@post) } format.json { head :error } end return end @post.update_columns(deletion_reason: params[:deletion_reason]) notice = t('posts.change_hide_reason.success') respond_to do |format| format.html { redirect_to post_path(@post), notice: notice } format.json { head :ok } end end # TODO: this is a mess def destroy if @post.duplicate_id @dup_image = Post.find_by id: @post.duplicate_id dr = @post.duplicate_reports.find_by(duplicate_of_post_id: @dup_image.id) rescue nil if dr dr.reject!(current_user) else # manually set as non-dupe @post.duplicate_id = nil PostUnhider.new(@post).save end else PostUnhider.new(@post).save end respond_to do |format| format.html { redirect_to post_path(@post) } format.json { head :ok } end end private def load_post @post = Post.find_by!(id: params[:post_id], destroyed_content: false) end def check_auth authorize! :hide, @post end end