diff --git a/app/assets/javascripts/discourse/controllers/group-membership.js.es6 b/app/assets/javascripts/discourse/controllers/group-membership.js.es6 index 76dafb878a3..8c22d2765e2 100644 --- a/app/assets/javascripts/discourse/controllers/group-membership.js.es6 +++ b/app/assets/javascripts/discourse/controllers/group-membership.js.es6 @@ -4,6 +4,7 @@ import { extractError } from 'discourse/lib/ajax-error'; export default Ember.Controller.extend(ModalFunctionality, { loading: false, + setAsOwner: false, @computed('model.usernames') disableAddButton(usernames) { @@ -12,19 +13,27 @@ export default Ember.Controller.extend(ModalFunctionality, { actions: { addMembers() { - if (Em.isEmpty(this.get("model.usernames"))) { return; } + const model = this.get('model'); + const usernames = model.get('usernames'); + if (Em.isEmpty(usernames)) { return; } + let promise; - this.get("model").addMembers(this.get("model.usernames")) - .then(() => { - this.transitionToRoute( - "group.members", - this.get('model.name'), - { queryParams: { filter: this.get('model.usernames') } } - ); - this.set("model.usernames", null); - this.send('closeModal'); - }) - .catch(error => this.flash(extractError(error), 'error')); + if (this.get('setAsOwner')) { + promise = model.addOwners(usernames, true); + } else { + promise = model.addMembers(usernames, true); + } + + promise.then(() => { + this.transitionToRoute( + "group.members", + this.get('model.name'), + { queryParams: { filter: usernames } } + ); + model.set("usernames", null); + this.send('closeModal'); + }) + .catch(error => this.flash(extractError(error), 'error')); }, }, }); diff --git a/app/assets/javascripts/discourse/models/group.js.es6 b/app/assets/javascripts/discourse/models/group.js.es6 index 14844e58ec1..4ad96c34fb6 100644 --- a/app/assets/javascripts/discourse/models/group.js.es6 +++ b/app/assets/javascripts/discourse/models/group.js.es6 @@ -74,24 +74,36 @@ const Group = RestModel.extend({ }); }, - addMembers(usernames) { + addMembers(usernames, filter) { return ajax('/groups/' + this.get('id') + '/members.json', { type: "PUT", data: { usernames: usernames } }).then(response => { - this.findMembers({ filter: response.usernames.join(',') }); + if (filter) { + this._filterMembers(response); + } else { + this.findMembers(); + } }); }, - addOwners(usernames) { + addOwners(usernames, filter) { return ajax(`/admin/groups/${this.get('id')}/owners.json`, { type: "PUT", data: { group: { usernames: usernames } } - }).then(() => { - this.findMembers(); + }).then(response => { + if (filter) { + this._filterMembers(response); + } else { + this.findMembers(); + } }); }, + _filterMembers(response) { + return this.findMembers({ filter: response.usernames.join(",") }); + }, + @computed("display_name", "name") displayName(groupDisplayName, name) { return groupDisplayName || name; diff --git a/app/assets/javascripts/discourse/templates/modal/group-membership.hbs b/app/assets/javascripts/discourse/templates/modal/group-membership.hbs index 7c5b07bfc66..92c35ab9f0a 100644 --- a/app/assets/javascripts/discourse/templates/modal/group-membership.hbs +++ b/app/assets/javascripts/discourse/templates/modal/group-membership.hbs @@ -1,7 +1,19 @@ {{#d-modal-body class='group-membership' title="groups.add_members.title"}} - {{user-selector usernames=model.usernames - placeholderKey="groups.selector_placeholder" - id="group-membership-user-selector"}} +
+ + + {{user-selector + usernames=model.usernames + placeholderKey="groups.selector_placeholder" + id="group-membership-user-selector"}} +
+ + {{#if this.currentUser.admin}} +
+ + {{input type="checkbox" class="inline" checked=setAsOwner}} +
+ {{/if}} {{/d-modal-body}}