diff --git a/app/assets/javascripts/discourse/app/controllers/group-add-members.js b/app/assets/javascripts/discourse/app/controllers/group-add-members.js index 6528f103a11..b6bd5e51a4f 100644 --- a/app/assets/javascripts/discourse/app/controllers/group-add-members.js +++ b/app/assets/javascripts/discourse/app/controllers/group-add-members.js @@ -3,13 +3,14 @@ import { action } from "@ember/object"; import { isEmpty } from "@ember/utils"; import discourseComputed from "discourse-common/utils/decorators"; import { extractError } from "discourse/lib/ajax-error"; +import { emailValid } from "discourse/lib/utilities"; import ModalFunctionality from "discourse/mixins/modal-functionality"; import I18n from "I18n"; export default Controller.extend(ModalFunctionality, { loading: false, - usernames: null, + usernamesAndEmails: null, setOwner: false, notifyUsers: false, @@ -18,7 +19,7 @@ export default Controller.extend(ModalFunctionality, { loading: false, setOwner: false, notifyUsers: false, - usernames: [], + usernamesAndEmails: [], }); }, @@ -27,23 +28,50 @@ export default Controller.extend(ModalFunctionality, { return I18n.t("groups.add_members.title", { group_name: fullName || name }); }, + @discourseComputed("usernamesAndEmails.[]") + usernames(usernamesAndEmails) { + return usernamesAndEmails.reject(emailValid).join(","); + }, + + @discourseComputed("usernamesAndEmails.[]") + emails(usernamesAndEmails) { + return usernamesAndEmails.filter(emailValid).join(","); + }, + + @action + setUsernamesAndEmails(usernamesAndEmails) { + this.set("usernamesAndEmails", usernamesAndEmails); + + if (this.emails) { + if (!this.usernames) { + this.set("notifyUsers", false); + } + + this.set("setOwner", false); + } + }, + @action addMembers() { - if (isEmpty(this.usernames)) { + if (isEmpty(this.usernamesAndEmails)) { return; } this.set("loading", true); - const usernames = this.usernames.join(","); const promise = this.setOwner - ? this.model.addOwners(usernames, true, this.notifyUsers) - : this.model.addMembers(usernames, true, this.notifyUsers); + ? this.model.addOwners(this.usernames, true, this.notifyUsers) + : this.model.addMembers( + this.usernames, + true, + this.notifyUsers, + this.emails + ); promise .then(() => { this.transitionToRoute("group.members", this.get("model.name"), { - queryParams: usernames ? { filter: usernames } : {}, + queryParams: this.usernames ? { filter: this.usernames } : {}, }); this.send("closeModal"); diff --git a/app/assets/javascripts/discourse/app/templates/modal/group-add-members.hbs b/app/assets/javascripts/discourse/app/templates/modal/group-add-members.hbs index 873e20fb396..8769840814e 100644 --- a/app/assets/javascripts/discourse/app/templates/modal/group-add-members.hbs +++ b/app/assets/javascripts/discourse/app/templates/modal/group-add-members.hbs @@ -4,15 +4,22 @@
{{email-group-user-chooser - value=usernames - onChange=(action (mut usernames)) + value=usernamesAndEmails + onChange=(action "setUsernamesAndEmails") + options=(hash + allowEmails=currentUser.can_invite_to_forum + filterPlaceholder=(if currentUser.can_invite_to_forum + "groups.add_members.usernames_or_emails_placeholder" + "groups.add_members.usernames_placeholder" + ) + ) }}
{{#if model.can_admin_group}}
@@ -20,7 +27,7 @@
@@ -31,6 +38,6 @@ {{d-button action=(action "addMembers") class="add btn-primary" icon="plus" - disabled=(or loading (not usernames)) + disabled=(or loading (not usernamesAndEmails)) label="groups.add"}} diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 87a5cc185ee..56aba8372d8 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -668,6 +668,8 @@ en: add_members: title: "Add Users to %{group_name}" description: "Enter a list of users you want to invite to the group or paste in a comma separated list:" + usernames_placeholder: "usernames" + usernames_or_emails_placeholder: "usernames or emails" notify_users: "Notify users" set_owner: "Set users as owners of this group" requests: