Add endpoint for removing anon blocks

This commit is contained in:
Karina Kwiatek 2022-06-14 23:30:27 +02:00 committed by Karina Kwiatek
parent f379845615
commit 7e98f427c6
3 changed files with 18 additions and 5 deletions

View File

@ -13,12 +13,23 @@ class Ajax::AnonymousBlockController < AjaxController
question.inboxes.first.destroy
@response[:status] = :okay
@response[:message] = I18n.t('messages.block.create.okay')
@response[:message] = I18n.t("messages.block.create.okay")
@response[:success] = true
end
rescue Errors::Base => e
@response[:status] = e.code
@response[:message] = I18n.t(e.locale_tag)
@response[:success] = false
def destroy
params.require :id
block = AnonymousBlock.find(params[:id])
if current_user != block.user
@response[:status] = :nopriv
@response[:message] = I18n.t("messages.block.destroy.nopriv")
end
block.destroy!
@response[:status] = :okay
@response[:message] = I18n.t("messages.block.create.okay")
@response[:success] = true
end
end

View File

@ -86,6 +86,7 @@ en:
destroy:
fail: "You are not blocking that user."
okay: "Successfully unblocked user."
nopriv: "Cannot remove a block belonging to someone else."
list:
create:
noname: "Please give that list a name."

View File

@ -119,6 +119,7 @@ Rails.application.routes.draw do
match '/mute/:id', to: 'mute_rule#update', via: :post, as: :update_mute_rule
match '/mute/:id', to: 'mute_rule#destroy', via: :delete, as: :delete_mute_rule
match '/block_anon', to: 'anonymous_block#create', via: :post, as: :block_anon
match '/block_anon/:id', to: 'anonymous_block#destroy', via: :delete, as: :unblock_anon
end
match '/discover', to: 'discover#index', via: :get, as: :discover