Remove anonymous block AJAX implementation
This commit is contained in:
parent
13bd043722
commit
ddded27757
|
@ -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
|
|
@ -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'));
|
||||
});
|
||||
}
|
|
@ -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 }
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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'));
|
||||
});
|
||||
});
|
||||
}
|
|
@ -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 }
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue