2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2025-09-06 10:50:21 +08:00

UX: confirmation before changing group membership in admin (#6426)

This commit is contained in:
Kyle Zhao 2018-10-02 12:34:08 +08:00 committed by Guo Xiang Tan
parent ab448ca8f3
commit d9bea66365
3 changed files with 79 additions and 55 deletions

View file

@ -11,6 +11,7 @@ export default Ember.Controller.extend(CanCheckEmails, {
editingName: false,
editingTitle: false,
originalPrimaryGroupId: null,
customGroupIdsBuffer: null,
availableGroups: null,
userTitleValue: null,
@ -30,6 +31,20 @@ export default Ember.Controller.extend(CanCheckEmails, {
"model.can_disable_second_factor"
),
@computed("model.customGroups")
customGroupIds(customGroups) {
return customGroups.mapBy("id");
},
@computed("customGroupIdsBuffer", "customGroupIds")
customGroupsDirty(buffer, original) {
if (buffer === null) return false;
return buffer.length === original.length
? buffer.any(id => !original.includes(id))
: true;
},
@computed("model.automaticGroups")
automaticGroups(automaticGroups) {
return automaticGroups
@ -105,6 +120,27 @@ export default Ember.Controller.extend(CanCheckEmails, {
}
},
groupAdded(added) {
this.get("model")
.groupAdded(added)
.catch(function() {
bootbox.alert(I18n.t("generic_error"));
});
},
groupRemoved(groupId) {
this.get("model")
.groupRemoved(groupId)
.then(() => {
if (groupId === this.get("originalPrimaryGroupId")) {
this.set("originalPrimaryGroupId", null);
}
})
.catch(function() {
bootbox.alert(I18n.t("generic_error"));
});
},
actions: {
impersonate() {
return this.get("model").impersonate();
@ -278,20 +314,22 @@ export default Ember.Controller.extend(CanCheckEmails, {
this.get("model").generateApiKey();
},
groupAdded(added) {
this.get("model")
.groupAdded(added)
.catch(function() {
bootbox.alert(I18n.t("generic_error"));
});
saveCustomGroups() {
const currentIds = this.get("customGroupIds");
const bufferedIds = this.get("customGroupIdsBuffer");
const availableGroups = this.get("availableGroups");
bufferedIds.filter(id => !currentIds.includes(id)).forEach(id => {
this.groupAdded(availableGroups.findBy("id", id));
});
currentIds
.filter(id => !bufferedIds.includes(id))
.forEach(id => this.groupRemoved(id));
},
groupRemoved(groupId) {
this.get("model")
.groupRemoved(groupId)
.catch(function() {
bootbox.alert(I18n.t("generic_error"));
});
resetCustomGroups() {
this.set("customGroupIdsBuffer", null);
},
savePrimaryGroup() {