Skip to content

A platform for community discussion. Free, open, simple.

UX: hide chat button on user card when suspended (#20292)

Joffrey JAFFEUX585d1e2f4d65
diff --git a/plugins/chat/assets/javascripts/discourse/components/user-card-chat-button.hbs b/plugins/chat/assets/javascripts/discourse/components/user-card-chat-button.hbs
index 764aa1ae8e6..2dd02ec8a75 100644
--- a/plugins/chat/assets/javascripts/discourse/components/user-card-chat-button.hbs
+++ b/plugins/chat/assets/javascripts/discourse/components/user-card-chat-button.hbs
@@ -1,4 +1,4 @@
-{{#if this.chat.userCanDirectMessage}}
+{{#if (and this.chat.userCanDirectMessage (not @user.suspended))}}
<DButton
@class="btn-primary user-card-chat-btn"
@action={{action "startChatting"}}
diff --git a/plugins/chat/test/javascripts/components/user-card-chat-button-test.js b/plugins/chat/test/javascripts/components/user-card-chat-button-test.js
index 953efb9e455..a3bb89a8784 100644
--- a/plugins/chat/test/javascripts/components/user-card-chat-button-test.js
+++ b/plugins/chat/test/javascripts/components/user-card-chat-button-test.js
@@ -4,6 +4,7 @@ import { render } from "@ember/test-helpers";
import { module, test } from "qunit";
import sinon from "sinon";
import { exists } from "discourse/tests/helpers/qunit-helpers";
+import User from "discourse/models/user";
module("Discourse Chat | Component | user-card-chat-button", function (hooks) {
setupRenderingTest(hooks);
@@ -30,4 +31,21 @@ module("Discourse Chat | Component | user-card-chat-button", function (hooks) {
"it doesn’t show the chat button"
);
});
+
+ test("when displayed user is suspended", async function (assert) {
+ sinon
+ .stub(this.owner.lookup("service:chat"), "userCanDirectMessage")
+ .value(true);
+
+ this.user = User.create({
+ suspended_till: moment().add(1, "year").toDate(),
+ });
+
+ await render(hbs`<UserCardChatButton @user={{user}}/>`);
+
+ assert.false(
+ exists(".user-card-chat-btn"),
+ "it doesn’t show the chat button"
+ );
+ });
});