FIX: Show error when attempting to send encrypted message to group

FIX: Show error when attempting to send encrypted message to group

diff --git a/assets/javascripts/discourse/initializers/hook-composer.js.es6 b/assets/javascripts/discourse/initializers/hook-composer.js.es6
index a27a30e..070e960 100644
--- a/assets/javascripts/discourse/initializers/hook-composer.js.es6
+++ b/assets/javascripts/discourse/initializers/hook-composer.js.es6
@@ -69,6 +69,17 @@ export default {
         const usernames = this.targetUsernames.split(",");
         usernames.push(this.user.username);
 
+        const groupNames = new Set(this.site.groups.map(g => g.name));
+        if (usernames.some(username => groupNames.has(username))) {
+          this.setProperties({
+            isEncrypted: false,
+            disableEncryptIndicator: true,
+            encryptError: I18n.t("encrypt.composer.group_not_allowed"),
+            showEncryptError: this.showEncryptError || this.isEncrypted
+          });
+          return;
+        }
+
         ajax("/encrypt/user", {
           type: "GET",
           data: { usernames }
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index 531cc96..6d8dff1 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -30,6 +30,7 @@ en:
 
       composer:
         encrypt: "Encrypt message?"
+        group_not_allowed: "You are not allowed to send messages to groups."
         user_has_no_key: "Unfortunately {{username}} did not enable encrypted messages."
 
       preferences:

GitHub sha: 8bfbccde

1 Like