mirror of
https://github.com/discourse/discourse.git
synced 2025-09-06 10:50:21 +08:00
DEV: refactoring admin user index (#6927)
This commit is contained in:
parent
31a700daf8
commit
fc710de3ab
2 changed files with 376 additions and 283 deletions
|
@ -3,7 +3,8 @@ import CanCheckEmails from "discourse/mixins/can-check-emails";
|
|||
import { propertyNotEqual, setting } from "discourse/lib/computed";
|
||||
import { userPath } from "discourse/lib/url";
|
||||
import { popupAjaxError } from "discourse/lib/ajax-error";
|
||||
import computed from "ember-addons/ember-computed-decorators";
|
||||
import { default as computed } from "ember-addons/ember-computed-decorators";
|
||||
import { fmt } from "discourse/lib/computed";
|
||||
|
||||
export default Ember.Controller.extend(CanCheckEmails, {
|
||||
adminTools: Ember.inject.service(),
|
||||
|
@ -64,24 +65,22 @@ export default Ember.Controller.extend(CanCheckEmails, {
|
|||
.join(", ");
|
||||
},
|
||||
|
||||
userFields: function() {
|
||||
const siteUserFields = this.site.get("user_fields"),
|
||||
userFields = this.get("model.user_fields");
|
||||
@computed("model.user_fields.[]")
|
||||
userFields(userFields) {
|
||||
const siteUserFields = this.site.get("user_fields");
|
||||
|
||||
if (!Ember.isEmpty(siteUserFields)) {
|
||||
return siteUserFields.map(function(uf) {
|
||||
let value = userFields ? userFields[uf.get("id").toString()] : null;
|
||||
return { name: uf.get("name"), value: value };
|
||||
return siteUserFields.map(uf => {
|
||||
const value = userFields ? userFields[uf.get("id").toString()] : null;
|
||||
return { name: uf.get("name"), value };
|
||||
});
|
||||
}
|
||||
return [];
|
||||
}.property("model.user_fields.[]"),
|
||||
|
||||
@computed("model.username_lower")
|
||||
preferencesPath(username) {
|
||||
return userPath(`${username}/preferences`);
|
||||
return [];
|
||||
},
|
||||
|
||||
preferencesPath: fmt("model.username_lower", "%@/preferences"),
|
||||
|
||||
@computed("model.can_delete_all_posts", "model.staff", "model.post_count")
|
||||
deleteAllPostsExplanation(canDeleteAllPosts, staff, postCount) {
|
||||
if (canDeleteAllPosts) {
|
||||
|
@ -120,9 +119,7 @@ export default Ember.Controller.extend(CanCheckEmails, {
|
|||
groupAdded(added) {
|
||||
this.get("model")
|
||||
.groupAdded(added)
|
||||
.catch(function() {
|
||||
bootbox.alert(I18n.t("generic_error"));
|
||||
});
|
||||
.catch(() => bootbox.alert(I18n.t("generic_error")));
|
||||
},
|
||||
|
||||
groupRemoved(groupId) {
|
||||
|
@ -133,9 +130,7 @@ export default Ember.Controller.extend(CanCheckEmails, {
|
|||
this.set("originalPrimaryGroupId", null);
|
||||
}
|
||||
})
|
||||
.catch(function() {
|
||||
bootbox.alert(I18n.t("generic_error"));
|
||||
});
|
||||
.catch(() => bootbox.alert(I18n.t("generic_error")));
|
||||
},
|
||||
|
||||
actions: {
|
||||
|
@ -201,13 +196,11 @@ export default Ember.Controller.extend(CanCheckEmails, {
|
|||
},
|
||||
|
||||
clearPenaltyHistory() {
|
||||
let user = this.get("model");
|
||||
return ajax(`/admin/users/${user.get("id")}/penalty_history`, {
|
||||
type: "DELETE"
|
||||
})
|
||||
.then(() => {
|
||||
user.set("tl3_requirements.penalty_counts.total", 0);
|
||||
})
|
||||
const user = this.get("model");
|
||||
const path = `/admin/users/${user.get("id")}/penalty_history`;
|
||||
|
||||
return ajax(path, { type: "DELETE" })
|
||||
.then(() => user.set("tl3_requirements.penalty_counts.total", 0))
|
||||
.catch(popupAjaxError);
|
||||
},
|
||||
|
||||
|
@ -225,7 +218,6 @@ export default Ember.Controller.extend(CanCheckEmails, {
|
|||
target_user: this.get("model.username")
|
||||
});
|
||||
},
|
||||
|
||||
showFlagsReceived() {
|
||||
this.get("adminTools").showFlagsReceived(this.get("model"));
|
||||
},
|
||||
|
@ -245,10 +237,9 @@ export default Ember.Controller.extend(CanCheckEmails, {
|
|||
const oldUsername = this.get("model.username");
|
||||
this.set("model.username", newUsername);
|
||||
|
||||
return ajax(`/users/${oldUsername.toLowerCase()}/preferences/username`, {
|
||||
data: { new_username: newUsername },
|
||||
type: "PUT"
|
||||
})
|
||||
const path = `/users/${oldUsername.toLowerCase()}/preferences/username`;
|
||||
|
||||
return ajax(path, { data: { new_username: newUsername }, type: "PUT" })
|
||||
.catch(e => {
|
||||
this.set("model.username", oldUsername);
|
||||
popupAjaxError(e);
|
||||
|
@ -260,13 +251,9 @@ export default Ember.Controller.extend(CanCheckEmails, {
|
|||
const oldName = this.get("model.name");
|
||||
this.set("model.name", newName);
|
||||
|
||||
return ajax(
|
||||
userPath(`${this.get("model.username").toLowerCase()}.json`),
|
||||
{
|
||||
data: { name: newName },
|
||||
type: "PUT"
|
||||
}
|
||||
)
|
||||
const path = userPath(`${this.get("model.username").toLowerCase()}.json`);
|
||||
|
||||
return ajax(path, { data: { name: newName }, type: "PUT" })
|
||||
.catch(e => {
|
||||
this.set("model.name", oldName);
|
||||
popupAjaxError(e);
|
||||
|
@ -276,15 +263,11 @@ export default Ember.Controller.extend(CanCheckEmails, {
|
|||
|
||||
saveTitle(newTitle) {
|
||||
const oldTitle = this.get("model.title");
|
||||
|
||||
this.set("model.title", newTitle);
|
||||
return ajax(
|
||||
userPath(`${this.get("model.username").toLowerCase()}.json`),
|
||||
{
|
||||
data: { title: newTitle },
|
||||
type: "PUT"
|
||||
}
|
||||
)
|
||||
|
||||
const path = userPath(`${this.get("model.username").toLowerCase()}.json`);
|
||||
|
||||
return ajax(path, { data: { title: newTitle }, type: "PUT" })
|
||||
.catch(e => {
|
||||
this.set("model.title", oldTitle);
|
||||
popupAjaxError(e);
|
||||
|
@ -303,9 +286,7 @@ export default Ember.Controller.extend(CanCheckEmails, {
|
|||
|
||||
bufferedIds
|
||||
.filter(id => !currentIds.includes(id))
|
||||
.forEach(id => {
|
||||
this.groupAdded(availableGroups.findBy("id", id));
|
||||
});
|
||||
.forEach(id => this.groupAdded(availableGroups.findBy("id", id)));
|
||||
|
||||
currentIds
|
||||
.filter(id => !bufferedIds.includes(id))
|
||||
|
@ -317,21 +298,15 @@ export default Ember.Controller.extend(CanCheckEmails, {
|
|||
},
|
||||
|
||||
savePrimaryGroup() {
|
||||
const self = this;
|
||||
const primaryGroupId = this.get("model.primary_group_id");
|
||||
const path = `/admin/users/${this.get("model.id")}/primary_group`;
|
||||
|
||||
return ajax("/admin/users/" + this.get("model.id") + "/primary_group", {
|
||||
return ajax(path, {
|
||||
type: "PUT",
|
||||
data: { primary_group_id: this.get("model.primary_group_id") }
|
||||
data: { primary_group_id: primaryGroupId }
|
||||
})
|
||||
.then(function() {
|
||||
self.set(
|
||||
"originalPrimaryGroupId",
|
||||
self.get("model.primary_group_id")
|
||||
);
|
||||
})
|
||||
.catch(function() {
|
||||
bootbox.alert(I18n.t("generic_error"));
|
||||
});
|
||||
.then(() => this.set("originalPrimaryGroupId", primaryGroupId))
|
||||
.catch(() => bootbox.alert(I18n.t("generic_error")));
|
||||
},
|
||||
|
||||
resetPrimaryGroup() {
|
||||
|
@ -339,30 +314,26 @@ export default Ember.Controller.extend(CanCheckEmails, {
|
|||
},
|
||||
|
||||
regenerateApiKey() {
|
||||
const self = this;
|
||||
|
||||
bootbox.confirm(
|
||||
I18n.t("admin.api.confirm_regen"),
|
||||
I18n.t("no_value"),
|
||||
I18n.t("yes_value"),
|
||||
function(result) {
|
||||
result => {
|
||||
if (result) {
|
||||
self.get("model").generateApiKey();
|
||||
this.get("model").generateApiKey();
|
||||
}
|
||||
}
|
||||
);
|
||||
},
|
||||
|
||||
revokeApiKey() {
|
||||
const self = this;
|
||||
|
||||
bootbox.confirm(
|
||||
I18n.t("admin.api.confirm_revoke"),
|
||||
I18n.t("no_value"),
|
||||
I18n.t("yes_value"),
|
||||
function(result) {
|
||||
result => {
|
||||
if (result) {
|
||||
self.get("model").revokeApiKey();
|
||||
this.get("model").revokeApiKey();
|
||||
}
|
||||
}
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue