2022-06-14 15:17:02 -07:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-06-14 14:16:55 -07:00
|
|
|
class Ajax::AnonymousBlockController < AjaxController
|
|
|
|
def create
|
|
|
|
params.require :question
|
|
|
|
|
|
|
|
question = Question.find(params[:question])
|
|
|
|
|
2022-08-17 13:25:34 -07:00
|
|
|
raise Errors::Forbidden if params[:global] && !current_user.mod?
|
2022-08-13 11:01:22 -07:00
|
|
|
|
2022-06-14 14:16:55 -07:00
|
|
|
AnonymousBlock.create!(
|
2022-08-13 11:01:22 -07:00
|
|
|
user: params[:global] ? nil : current_user,
|
2022-06-14 15:28:47 -07:00
|
|
|
identifier: question.author_identifier,
|
2022-08-13 12:21:17 -07:00
|
|
|
question:
|
2022-06-14 14:16:55 -07:00
|
|
|
)
|
|
|
|
|
2022-08-20 10:18:28 -07:00
|
|
|
question.inboxes.first&.destroy
|
2022-06-14 14:16:55 -07:00
|
|
|
|
|
|
|
@response[:status] = :okay
|
2022-07-06 00:21:15 -07:00
|
|
|
@response[:message] = t(".success")
|
2022-06-14 14:16:55 -07:00
|
|
|
@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
|
2022-07-06 00:21:15 -07:00
|
|
|
@response[:message] = t(".nopriv")
|
2022-06-14 14:30:27 -07:00
|
|
|
end
|
2022-06-14 14:16:55 -07:00
|
|
|
|
2022-06-14 14:30:27 -07:00
|
|
|
block.destroy!
|
|
|
|
|
|
|
|
@response[:status] = :okay
|
2022-07-06 00:21:15 -07:00
|
|
|
@response[:message] = t(".success")
|
2022-06-14 14:30:27 -07:00
|
|
|
@response[:success] = true
|
2022-06-14 14:16:55 -07:00
|
|
|
end
|
|
|
|
end
|