From a60f8425cb618d534afc57d1c4978de75b43c857 Mon Sep 17 00:00:00 2001 From: Martin Brennan Date: Fri, 30 Sep 2022 16:40:29 +1000 Subject: [PATCH 1/2] FIX: Make chat_allow_uploads apply to DM channels This setting should have applied to both public and DM channels from the beginning, making it so it works correctly and updating the description accordingly. --- assets/javascripts/discourse/components/chat-composer.js | 7 ++----- config/locales/server.en.yml | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/assets/javascripts/discourse/components/chat-composer.js b/assets/javascripts/discourse/components/chat-composer.js index 65e4c559d..6921f3835 100644 --- a/assets/javascripts/discourse/components/chat-composer.js +++ b/assets/javascripts/discourse/components/chat-composer.js @@ -16,7 +16,7 @@ import { findRawTemplate } from "discourse-common/lib/raw-templates"; import { emojiSearch, isSkinTonableEmoji } from "pretty-text/emoji"; import { emojiUrlFor } from "discourse/lib/text"; import { inject as service } from "@ember/service"; -import { or, readOnly, reads } from "@ember/object/computed"; +import { readOnly, reads } from "@ember/object/computed"; import { search as searchCategoryTag } from "discourse/lib/category-tag-search"; import { SKIP } from "discourse/lib/autocomplete"; import { Promise } from "rsvp"; @@ -44,10 +44,7 @@ export default Component.extend(TextareaTextManipulation, { inProgressUploads: null, composerEventPrefix: "chat", composerFocusSelector: ".chat-composer-input", - canAttachUploads: or( - "siteSettings.chat_allow_uploads", - "chatChannel.isDirectMessageChannel" - ), + canAttachUploads: reads("siteSettings.chat_allow_uploads"), isNetworkUnreliable: reads("chat.isNetworkUnreliable"), @discourseComputed(...chatComposerButtonsDependentKeys()) diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index ac0d6c09e..3f18fc220 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -12,7 +12,7 @@ en: chat_default_channel_id: "The chat channel that will be opened by default when a user has no unread messages or mentions in other channels." chat_duplicate_message_sensitivity: "The likelihood that a duplicate message by the same sender will be blocked in a short period. Decimal number between 0 and 1.0, with 1.0 being the highest setting (blocks messages more frequently in a shorter amount of time). Set to `0` to allow duplicate messages." chat_minimum_message_length: "Minimum number of characters for a chat message." - chat_allow_uploads: "Allow uploads in public chat channels." + chat_allow_uploads: "Allow uploads in public chat channels and direct message channels." chat_archive_destination_topic_status: "The status that the destination topic should be once a channel archive is completed. This only applies when the destination topic is a new topic, not an existing one." default_emoji_reactions: "Default emoji reactions for chat messages. Add up to 5 emojis for quick reaction." errors: From 7d3f31db5428de43bcebabdf653b7f477b9196f9 Mon Sep 17 00:00:00 2001 From: Martin Brennan Date: Fri, 30 Sep 2022 17:48:40 +1000 Subject: [PATCH 2/2] DEV: Add acceptance tests for chat_allow_uploads --- test/javascripts/acceptance/chat-test.js | 39 +++++++++++ .../chat-composer-attachments-test.js | 66 ------------------- 2 files changed, 39 insertions(+), 66 deletions(-) delete mode 100644 test/javascripts/components/chat-composer-attachments-test.js diff --git a/test/javascripts/acceptance/chat-test.js b/test/javascripts/acceptance/chat-test.js index 72fe42e38..6537ed897 100644 --- a/test/javascripts/acceptance/chat-test.js +++ b/test/javascripts/acceptance/chat-test.js @@ -1511,6 +1511,45 @@ acceptance("Discourse Chat - image uploads", function (needs) { }); }); +acceptance( + "Discourse Chat - image uploads - uploads not allowed", + function (needs) { + needs.user({ + admin: false, + moderator: false, + username: "eviltrout", + id: 1, + can_chat: true, + has_chat_enabled: true, + }); + needs.settings({ + chat_enabled: true, + chat_allow_uploads: false, + }); + needs.pretender((server, helper) => { + baseChatPretenders(server, helper); + directMessageChannelPretender(server, helper); + chatChannelPretender(server, helper); + }); + + test("uploads are not allowed in public channels", async function (assert) { + await visit("/chat/channel/4/public-category"); + assert.notOk( + visible(".chat-composer-dropdown__trigger-btn"), + "composer dropdown should not be visible because uploads are not enabled and no other buttons are rendered" + ); + }); + + test("uploads are not allowed in direct message channels", async function (assert) { + await visit("/chat/channel/75/@hawk"); + assert.notOk( + visible(".chat-composer-dropdown__trigger-btn"), + "composer dropdown should not be visible because uploads are not enabled and no other buttons are rendered" + ); + }); + } +); + acceptance("Discourse Chat - Insert Date", function (needs) { needs.user({ username: "eviltrout", diff --git a/test/javascripts/components/chat-composer-attachments-test.js b/test/javascripts/components/chat-composer-attachments-test.js deleted file mode 100644 index 05fa4bdd0..000000000 --- a/test/javascripts/components/chat-composer-attachments-test.js +++ /dev/null @@ -1,66 +0,0 @@ -import { set } from "@ember/object"; -import componentTest, { - setupRenderingTest, -} from "discourse/tests/helpers/component-test"; -import { exists, visible } from "discourse/tests/helpers/qunit-helpers"; -import hbs from "htmlbars-inline-precompile"; -import ChatChannel from "discourse/plugins/discourse-chat/discourse/models/chat-channel"; -import { click } from "@ember/test-helpers"; -import { module } from "qunit"; - -module( - "Discourse Chat | Component | chat-composer attachments test", - function (hooks) { - setupRenderingTest(hooks); - - componentTest( - "Allow attachments setting doesn't apply to direct message channels", - { - template: hbs`{{chat-composer chatChannel=chatChannel canInteractWithChat=true}}`, - beforeEach() { - set(this.currentUser, "id", 1); - this.set( - "chatChannel", - ChatChannel.create({ - chatable_type: "DirectMessageChannel", - chatable: { - users: [{ id: 1 }], - }, - }) - ); - this.siteSettings.chat_allow_uploads = false; - }, - async test(assert) { - await click(".chat-composer-dropdown__trigger-btn"); - - assert.ok( - visible(".chat-composer-dropdown__action-btn.chat-upload-btn") - ); - }, - - skip: true, // this should be an acceptance test - } - ); - - componentTest("Allow attachments setting applies to public channels", { - template: hbs`{{chat-composer chatChannel=chatChannel canInteractWithChat=true}}`, - - beforeEach() { - set(this.currentUser, "id", 1); - this.set( - "chatChannel", - ChatChannel.create({ - chatable_type: "Category", - chatable: {}, - }) - ); - this.siteSettings.chat_allow_uploads = false; - }, - - async test(assert) { - // Toolbar button isn't present because there are no buttons to be rendered - assert.notOk(exists(".open-toolbar-btn")); - }, - }); - } -);