Skip to content

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

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

Dan Ungureanu17efce9023b6
diff --git a/app/assets/javascripts/discourse/app/controllers/create-invite.js b/app/assets/javascripts/discourse/app/controllers/create-invite.js
index 11262768faa..13f8436ae83 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 82f3045c876..c4ad16f19b0 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 4b640844e80..a04ee351d37 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 b7cf7b33fe1..a537853f637 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))