Retrospring/app/controllers/ajax/anonymous_block_controller.rb

40 lines
880 B
Ruby
Raw Normal View History

2022-06-14 15:17:02 -07:00
# frozen_string_literal: true
class Ajax::AnonymousBlockController < AjaxController
def create
params.require :question
question = Question.find(params[:question])
raise Errors::Forbidden if params[:global] && !current_user.mod?
AnonymousBlock.create!(
user: params[:global] ? nil : current_user,
identifier: question.author_identifier,
2022-08-13 12:21:17 -07:00
question:
)
question.inboxes.first&.destroy
@response[:status] = :okay
@response[:message] = t(".success")
@response[:success] = true
2022-06-14 14:30:27 -07:00
end
def destroy
params.require :id
block = AnonymousBlock.find(params[:id])
if current_user != block.user
@response[:status] = :nopriv
@response[:message] = t(".nopriv")
2022-06-14 14:30:27 -07:00
end
2022-06-14 14:30:27 -07:00
block.destroy!
@response[:status] = :okay
@response[:message] = t(".success")
2022-06-14 14:30:27 -07:00
@response[:success] = true
end
end