Implement frontend for blocking users site-wide
This commit is contained in:
parent
74e309e9fc
commit
ae5d8931af
|
@ -0,0 +1,44 @@
|
|||
import Rails from '@rails/ujs';
|
||||
import swal from 'sweetalert';
|
||||
|
||||
import { showErrorNotification, showNotification } from "utilities/notifications";
|
||||
import I18n from "retrospring/i18n";
|
||||
|
||||
export function blockAnonEventHandler(event: Event): void {
|
||||
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'
|
||||
};
|
||||
|
||||
Rails.ajax({
|
||||
url: '/ajax/block_anon',
|
||||
type: 'POST',
|
||||
data: new URLSearchParams(data).toString(),
|
||||
success: (data) => {
|
||||
if (!data.success) return false;
|
||||
|
||||
showNotification(data.message);
|
||||
},
|
||||
error: (data, status, xhr) => {
|
||||
console.log(data, status, xhr);
|
||||
showErrorNotification(I18n.translate('frontend.error.message'));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
|
@ -2,11 +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: '[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 }
|
||||
|
|
|
@ -26,4 +26,8 @@ class Question < ApplicationRecord
|
|||
return false if Inbox.where(question: self).count > 1
|
||||
true
|
||||
end
|
||||
|
||||
def generated? = %w[justask retrospring_exporter].include?(author_identifier)
|
||||
|
||||
def anonymous? = author_is_anonymous && author_identifier.present?
|
||||
end
|
||||
|
|
|
@ -18,6 +18,10 @@
|
|||
%a.dropdown-item{ href: "#", tabindex: -1, data: { action: "ab-question-report", q_id: a.question.id } }
|
||||
%i.fa.fa-exclamation-triangle
|
||||
= t("voc.report")
|
||||
- if current_user.has_role?(:moderator) && a.question.anonymous? && !a.question.generated?
|
||||
%a.dropdown-item{ name: "mod-block-anon", data: { q_id: a.question.id } }
|
||||
%i.fa.fa-volume-off
|
||||
= t("voc.block_site_wide")
|
||||
- if current_user.has_role? :administrator
|
||||
%a.dropdown-item{ href: rails_admin_path_for_resource(a.question), target: "_blank" }
|
||||
%i.fa.fa-gears
|
||||
|
|
|
@ -22,15 +22,18 @@
|
|||
.dropdown-menu.dropdown-menu-right{ role: :menu }
|
||||
- if i.question.user_id != current_user.id
|
||||
%a.dropdown-item{ name: "ib-report", data: { q_id: i.question.id } }
|
||||
%i.fa.fa-warning
|
||||
%i.fa.fa-fw.fa-warning
|
||||
= t("voc.report")
|
||||
- if i.question.author_is_anonymous && i.question.author_identifier.present?
|
||||
- if current_user.has_role?(:moderator) && i.question.anonymous? && !i.question.generated?
|
||||
%a.dropdown-item{ name: "mod-block-anon", data: { q_id: i.question.id } }
|
||||
%i.fa.fa-fw.fa-volume-off
|
||||
= t("voc.block_site_wide")
|
||||
%a.dropdown-item{ name: "ib-block-anon", data: { q_id: i.question.id } }
|
||||
%i.fa.fa-minus-circle
|
||||
%i.fa.fa-fw.fa-minus-circle
|
||||
= t("voc.block")
|
||||
- if current_user.has_role? :administrator
|
||||
%a.dropdown-item{ href: rails_admin_path_for_resource(i) }
|
||||
%i.fa.fa-gears
|
||||
%i.fa.fa-fw.fa-gears
|
||||
= t("voc.view_in_rails_admin")
|
||||
- if current_user == i.user
|
||||
.card-body
|
||||
|
|
|
@ -30,6 +30,9 @@
|
|||
= link_to moderation_toggle_unmask_path, method: :post, class: "dropdown-item" do
|
||||
%i.fa.fa-toggle-off
|
||||
= t(".unmask.enable")
|
||||
%a.dropdown-item{ href: mod_anon_block_index_path }
|
||||
%i.fa.fa-fw.fa-volume-off
|
||||
= t("views.navigation.blocks")
|
||||
%a.dropdown-item{ href: moderation_path }
|
||||
%i.fa.fa-fw.fa-gavel
|
||||
= t(".moderation")
|
||||
|
|
|
@ -45,6 +45,10 @@ en:
|
|||
confirm:
|
||||
title: "Are you sure?"
|
||||
text: "This question will be gone forever."
|
||||
mod_mute:
|
||||
confirm:
|
||||
title: "Are you sure?"
|
||||
text: "This will block this user for everyone."
|
||||
report:
|
||||
confirm:
|
||||
title: "Are you sure you want to report this %{type}?"
|
||||
|
|
Loading…
Reference in New Issue