From ddded2775770798beae04761b34c4d1933904917 Mon Sep 17 00:00:00 2001 From: Andreas Nedbal Date: Mon, 21 Nov 2022 22:28:38 +0100 Subject: [PATCH] Remove anonymous block AJAX implementation --- .../ajax/anonymous_block_controller.rb | 39 --------------- .../features/inbox/entry/blockAnon.ts | 31 ------------ .../retrospring/features/inbox/entry/index.ts | 4 +- .../features/moderation/blockAnon.ts | 47 ------------------- .../retrospring/features/moderation/index.ts | 4 +- config/routes.rb | 2 - 6 files changed, 2 insertions(+), 125 deletions(-) delete mode 100644 app/controllers/ajax/anonymous_block_controller.rb delete mode 100644 app/javascript/retrospring/features/inbox/entry/blockAnon.ts delete mode 100644 app/javascript/retrospring/features/moderation/blockAnon.ts diff --git a/app/controllers/ajax/anonymous_block_controller.rb b/app/controllers/ajax/anonymous_block_controller.rb deleted file mode 100644 index 20503553..00000000 --- a/app/controllers/ajax/anonymous_block_controller.rb +++ /dev/null @@ -1,39 +0,0 @@ -# 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, - question: - ) - - question.inboxes.first&.destroy - - @response[:status] = :okay - @response[:message] = t(".success") - @response[:success] = true - end - - def destroy - params.require :id - - block = AnonymousBlock.find(params[:id]) - if current_user != block.user - @response[:status] = :nopriv - @response[:message] = t(".nopriv") - end - - block.destroy! - - @response[:status] = :okay - @response[:message] = t(".success") - @response[:success] = true - end -end diff --git a/app/javascript/retrospring/features/inbox/entry/blockAnon.ts b/app/javascript/retrospring/features/inbox/entry/blockAnon.ts deleted file mode 100644 index f0d184b7..00000000 --- a/app/javascript/retrospring/features/inbox/entry/blockAnon.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { post } from '@rails/request.js'; - -import { showErrorNotification, showNotification } from "utilities/notifications"; -import I18n from "retrospring/i18n"; - -export function blockAnonEventHandler(event: Event): void { - const element: HTMLAnchorElement = event.target as HTMLAnchorElement; - - const data = { - question: element.getAttribute('data-q-id'), - }; - - post('/ajax/block_anon', { - body: data, - contentType: 'application/json' - }) - .then(async response => { - const data = await response.json; - - if (!data.success) return false; - const inboxEntry: Node = element.closest('.inbox-entry'); - - showNotification(data.message); - - (inboxEntry as HTMLElement).remove(); - }) - .catch(err => { - console.log(err); - showErrorNotification(I18n.translate('frontend.error.message')); - }); -} \ No newline at end of file diff --git a/app/javascript/retrospring/features/inbox/entry/index.ts b/app/javascript/retrospring/features/inbox/entry/index.ts index 27bbc5ac..54022129 100644 --- a/app/javascript/retrospring/features/inbox/entry/index.ts +++ b/app/javascript/retrospring/features/inbox/entry/index.ts @@ -3,15 +3,13 @@ import { answerEntryHandler, answerEntryInputHandler } from './answer'; import { deleteEntryHandler } from './delete'; import optionsEntryHandler from './options'; import { reportEventHandler } from './report'; -import { blockAnonEventHandler } from "retrospring/features/inbox/entry/blockAnon"; export default (): void => { registerEvents([ { type: 'click', target: 'button[name="ib-answer"]', handler: answerEntryHandler, global: true }, { type: 'click', target: '[name="ib-destroy"]', handler: deleteEntryHandler, global: true }, { type: 'click', target: '[name=ib-report]', handler: reportEventHandler, global: true }, - { type: 'click', target: '[name=ib-block-anon]', handler: blockAnonEventHandler, global: true }, { type: 'click', target: 'button[name=ib-options]', handler: optionsEntryHandler, global: true }, { type: 'keydown', target: 'textarea[name=ib-answer]', handler: answerEntryInputHandler, global: true } ]); -} \ No newline at end of file +} diff --git a/app/javascript/retrospring/features/moderation/blockAnon.ts b/app/javascript/retrospring/features/moderation/blockAnon.ts deleted file mode 100644 index 4f04004c..00000000 --- a/app/javascript/retrospring/features/moderation/blockAnon.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { post } from '@rails/request.js'; -import swal from 'sweetalert'; - -import { showErrorNotification, showNotification } from "utilities/notifications"; -import I18n from "retrospring/i18n"; - -export function blockAnonEventHandler(event: Event): void { - event.preventDefault(); - - swal({ - title: I18n.translate('frontend.mod_mute.confirm.title'), - text: I18n.translate('frontend.mod_mute.confirm.text'), - type: 'warning', - showCancelButton: true, - confirmButtonColor: "#DD6B55", - confirmButtonText: I18n.translate('voc.y'), - cancelButtonText: I18n.translate('voc.n'), - closeOnConfirm: true, - }, (dialogResult) => { - if (!dialogResult) { - return; - } - - const sender: HTMLAnchorElement = event.target as HTMLAnchorElement; - - const data = { - question: sender.getAttribute('data-q-id'), - global: 'true' - }; - - post('/ajax/block_anon', { - body: data, - contentType: 'application/json' - }) - .then(async response => { - const data = await response.json; - - if (!data.success) return false; - - showNotification(data.message); - }) - .catch(err => { - console.log(err); - showErrorNotification(I18n.translate('frontend.error.message')); - }); - }); -} \ No newline at end of file diff --git a/app/javascript/retrospring/features/moderation/index.ts b/app/javascript/retrospring/features/moderation/index.ts index 7d0e639a..bafa6130 100644 --- a/app/javascript/retrospring/features/moderation/index.ts +++ b/app/javascript/retrospring/features/moderation/index.ts @@ -2,15 +2,13 @@ import registerEvents from 'utilities/registerEvents'; import { banCheckboxHandler, banFormHandler, permanentBanCheckboxHandler } from './ban'; import { destroyReportHandler } from './destroy'; import { privilegeCheckHandler } from './privilege'; -import { blockAnonEventHandler } from './blockAnon'; export default (): void => { registerEvents([ { type: 'click', target: '[type="checkbox"][name="check-your-privileges"]', handler: privilegeCheckHandler, global: true }, { type: 'click', target: '[name="mod-delete-report"]', handler: destroyReportHandler, global: true }, - { type: 'click', target: '[name="mod-block-anon"]', handler: blockAnonEventHandler, global: true }, { type: 'change', target: '[name="ban"][type="checkbox"]', handler: banCheckboxHandler, global: true }, { type: 'change', target: '[name="permaban"][type="checkbox"]', handler: permanentBanCheckboxHandler, global: true }, { type: 'submit', target: '#modal-ban form', handler: banFormHandler, global: true } ]); -} \ No newline at end of file +} diff --git a/config/routes.rb b/config/routes.rb index 62c550e8..bee8dc2a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -132,8 +132,6 @@ Rails.application.routes.draw do post "/list_membership", to: "list#membership", as: :list_membership post "/subscribe", to: "subscription#subscribe", as: :subscribe_answer post "/unsubscribe", to: "subscription#unsubscribe", as: :unsubscribe_answer - post "/block_anon", to: "anonymous_block#create", as: :block_anon - delete "/block_anon/:id", to: "anonymous_block#destroy", as: :unblock_anon end get "/discover", to: "discover#index", as: :discover