From d2116f0029ca268c9f19be79bd3b8349f25a9700 Mon Sep 17 00:00:00 2001 From: Bianca Nenciu Date: Tue, 3 Nov 2020 17:38:56 +0200 Subject: [PATCH] FIX: Show error message if user is already silenced or suspended (#10988) Users could be silenced or suspended by two staff members at the same time and would not be aware of it. This commit shows an error message if another penalty has been applied. --- .../admin/addon/mixins/penalty-controller.js | 8 +++- .../admin/addon/models/admin-user.js | 13 +----- .../templates/modal/admin-silence-user.hbs | 4 ++ .../templates/modal/admin-suspend-user.hbs | 4 ++ app/controllers/admin/users_controller.rb | 19 +++++++++ config/locales/server.en.yml | 2 + spec/requests/admin/users_controller_spec.rb | 42 +++++++++++++++++++ 7 files changed, 78 insertions(+), 14 deletions(-) diff --git a/app/assets/javascripts/admin/addon/mixins/penalty-controller.js b/app/assets/javascripts/admin/addon/mixins/penalty-controller.js index caf3aee5596..250d60664f6 100644 --- a/app/assets/javascripts/admin/addon/mixins/penalty-controller.js +++ b/app/assets/javascripts/admin/addon/mixins/penalty-controller.js @@ -1,12 +1,13 @@ import I18n from "I18n"; import ModalFunctionality from "discourse/mixins/modal-functionality"; -import { popupAjaxError } from "discourse/lib/ajax-error"; +import { extractError } from "discourse/lib/ajax-error"; import Mixin from "@ember/object/mixin"; import { next } from "@ember/runloop"; import { Promise } from "rsvp"; import bootbox from "bootbox"; export default Mixin.create(ModalFunctionality, { + errorMessage: null, reason: null, message: null, postEdit: null, @@ -18,6 +19,7 @@ export default Mixin.create(ModalFunctionality, { resetModal() { this.setProperties({ + errorMessage: null, reason: null, message: null, loadingUser: true, @@ -66,6 +68,8 @@ export default Mixin.create(ModalFunctionality, { callback(result); } }) - .catch(popupAjaxError); + .catch((error) => { + this.set("errorMessage", extractError(error)); + }); }, }); diff --git a/app/assets/javascripts/admin/addon/models/admin-user.js b/app/assets/javascripts/admin/addon/models/admin-user.js index 4a58d212733..0bc1132623b 100644 --- a/app/assets/javascripts/admin/addon/models/admin-user.js +++ b/app/assets/javascripts/admin/addon/models/admin-user.js @@ -352,28 +352,17 @@ const AdminUser = User.extend({ type: "PUT", }) .then((result) => this.setProperties(result.unsilence)) - .catch((e) => { - const error = I18n.t("admin.user.unsilence_failed", { - error: this._formatError(e), - }); - bootbox.alert(error); - }) .finally(() => this.set("silencingUser", false)); }, silence(data) { this.set("silencingUser", true); + return ajax(`/admin/users/${this.id}/silence`, { type: "PUT", data, }) .then((result) => this.setProperties(result.silence)) - .catch((e) => { - const error = I18n.t("admin.user.silence_failed", { - error: this._formatError(e), - }); - bootbox.alert(error); - }) .finally(() => this.set("silencingUser", false)); }, diff --git a/app/assets/javascripts/admin/addon/templates/modal/admin-silence-user.hbs b/app/assets/javascripts/admin/addon/templates/modal/admin-silence-user.hbs index 5e18b4cfb40..db3a184437b 100644 --- a/app/assets/javascripts/admin/addon/templates/modal/admin-silence-user.hbs +++ b/app/assets/javascripts/admin/addon/templates/modal/admin-silence-user.hbs @@ -1,6 +1,10 @@ {{#d-modal-body title="admin.user.silence_modal_title"}} {{#conditional-loading-spinner condition=loadingUser}} + {{#if errorMessage}} +
{{errorMessage}}
+ {{/if}} +