diff --git a/app/controllers/ajax/anonymous_block_controller.rb b/app/controllers/ajax/anonymous_block_controller.rb index 04f06171..b9262264 100644 --- a/app/controllers/ajax/anonymous_block_controller.rb +++ b/app/controllers/ajax/anonymous_block_controller.rb @@ -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 diff --git a/config/locales/en.yml b/config/locales/en.yml index 981698eb..21bb3b11 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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." diff --git a/config/routes.rb b/config/routes.rb index 6e116e95..83edd94d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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