FEATURE: Allow sending a message with invite (#12892)

FEATURE: Allow sending a message with invite (#12892)

  • FEATURE: Allow sending a message with invite

It used to be a staff-only feature and this commit makes it available to everyone who can invite.

  • FIX: Inviting to topic uses another email template

This used to be the case, but the extra parameter was lost when we switched to the new modal.

diff --git a/app/assets/javascripts/discourse/app/controllers/create-invite.js b/app/assets/javascripts/discourse/app/controllers/create-invite.js
index 1126276..13f8436 100644
--- a/app/assets/javascripts/discourse/app/controllers/create-invite.js
+++ b/app/assets/javascripts/discourse/app/controllers/create-invite.js
@@ -20,6 +20,7 @@ export default Controller.extend(
     invites: null,
 
     showAdvanced: false,
+    inviteToTopic: false,
     limitToEmail: false,
     autogenerated: false,
 
@@ -34,6 +35,7 @@ export default Controller.extend(
         invite: null,
         invites: null,
         showAdvanced: false,
+        inviteToTopic: false,
         limitToEmail: false,
         autogenerated: false,
       });
@@ -90,6 +92,9 @@ export default Controller.extend(
 
         if (opts.sendEmail) {
           data.send_email = true;
+          if (this.inviteToTopic) {
+            data.invite_to_topic = true;
+          }
         } else {
           data.skip_email = true;
         }
@@ -160,6 +165,11 @@ export default Controller.extend(
       return hasBufferedChanges || (inviteEmail ? "email" : "link") !== type;
     },
 
+    @discourseComputed("currentUser.staff", "type")
+    hasAdvanced(staff, type) {
+      return staff || type === "email";
+    },
+
     @action
     copied() {
       if (this.type === "email" && !this.buffered.get("email")) {
diff --git a/app/assets/javascripts/discourse/app/controllers/share-topic.js b/app/assets/javascripts/discourse/app/controllers/share-topic.js
index 82f3045..c4ad16f 100644
--- a/app/assets/javascripts/discourse/app/controllers/share-topic.js
+++ b/app/assets/javascripts/discourse/app/controllers/share-topic.js
@@ -105,7 +105,10 @@ export default Controller.extend(
     inviteUsers() {
       this.set("showNotifyUsers", false);
       const controller = showModal("create-invite");
-      controller.set("showAdvanced", true);
+      controller.setProperties({
+        showAdvanced: true,
+        inviteToTopic: true,
+      });
       controller.buffered.setProperties({
         topicId: this.topic.id,
         topicTitle: this.topic.title,
diff --git a/app/assets/javascripts/discourse/app/templates/modal/create-invite.hbs b/app/assets/javascripts/discourse/app/templates/modal/create-invite.hbs
index 4b64084..a04ee35 100644
--- a/app/assets/javascripts/discourse/app/templates/modal/create-invite.hbs
+++ b/app/assets/javascripts/discourse/app/templates/modal/create-invite.hbs
@@ -52,12 +52,10 @@
 
     {{#if isEmail}}
       {{#if showAdvanced}}
-        {{#if currentUser.staff}}
-          <div class="input-group invite-custom-message">
-            <label for="invite-message">{{i18n "user.invited.invite.custom_message"}}</label>
-            {{textarea id="invite-message" value=buffered.custom_message}}
-          </div>
-        {{/if}}
+        <div class="input-group invite-custom-message">
+          <label for="invite-message">{{i18n "user.invited.invite.custom_message"}}</label>
+          {{textarea id="invite-message" value=buffered.custom_message}}
+        </div>
       {{/if}}
     {{/if}}
 
@@ -71,7 +69,7 @@
             label="user.invited.invite.invite_to_topic"
           }}
         </div>
-      {{else}}
+      {{else if buffered.topicTitle}}
         <div class="input-group">
           <label for="invite-topic">{{i18n "user.invited.invite.invite_to_topic"}}</label>
           {{input
@@ -133,7 +131,7 @@
     }}
   {{/if}}
 
-  {{#if currentUser.staff}}
+  {{#if hasAdvanced}}
     {{d-button
       action=(action "toggleAdvanced")
       class="show-advanced"
diff --git a/app/controllers/invites_controller.rb b/app/controllers/invites_controller.rb
index b7cf7b3..a537853 100644
--- a/app/controllers/invites_controller.rb
+++ b/app/controllers/invites_controller.rb
@@ -183,7 +183,7 @@ class InvitesController < ApplicationController
 
     if invite.emailed_status == Invite.emailed_status_types[:pending]
       invite.update_column(:emailed_status, Invite.emailed_status_types[:sending])
-      Jobs.enqueue(:invite_email, invite_id: invite.id)
+      Jobs.enqueue(:invite_email, invite_id: invite.id, invite_to_topic: params[:invite_to_topic])
     end
 
     render_serialized(invite, InviteSerializer, scope: guardian, root: nil, show_emails: params.has_key?(:email))

GitHub sha: 17efce90

This commit appears in #12892 which was approved by eviltrout. It was merged by udan11.