Group owners are regular users that can add or remove users to a group The Admin UX allows admins to appoint group owners The public group UX will display group owners first and unlock UI to add and remove members Group owners can only be appointed on non automatic groups Group owners may not appoint another group owner
48 lines
1.4 KiB
JavaScript
48 lines
1.4 KiB
JavaScript
export default Ember.Controller.extend({
|
|
loading: false,
|
|
limit: null,
|
|
offset: null,
|
|
|
|
isOwner: function() {
|
|
if (this.get('currentUser.admin')) {
|
|
return true;
|
|
}
|
|
const owners = this.get('model.owners');
|
|
const currentUserId = this.get('currentUser.id');
|
|
if (currentUserId) {
|
|
return !!owners.findBy('id', currentUserId);
|
|
}
|
|
}.property('model.owners.@each'),
|
|
|
|
actions: {
|
|
removeMember(user) {
|
|
this.get('model').removeMember(user);
|
|
},
|
|
|
|
addMembers() {
|
|
const usernames = this.get('usernames');
|
|
if (usernames && usernames.length > 0) {
|
|
this.get('model').addMembers(usernames).then(() => this.set('usernames', []));
|
|
}
|
|
},
|
|
|
|
loadMore() {
|
|
if (this.get("loading")) { return; }
|
|
// we've reached the end
|
|
if (this.get("model.members.length") >= this.get("model.user_count")) { return; }
|
|
|
|
this.set("loading", true);
|
|
|
|
Discourse.Group.loadMembers(this.get("model.name"), this.get("model.members.length"), this.get("limit")).then(result => {
|
|
this.get("model.members").addObjects(result.members.map(member => Discourse.User.create(member)));
|
|
this.setProperties({
|
|
loading: false,
|
|
user_count: result.meta.total,
|
|
limit: result.meta.limit,
|
|
offset: Math.min(result.meta.offset + result.meta.limit, result.meta.total)
|
|
});
|
|
});
|
|
}
|
|
}
|
|
});
|