mirror of
https://github.com/discourse/discourse.git
synced 2025-05-24 01:14:12 +08:00
FIX: remove rendering UX from ember models (#11724)
Fix for `admin-user.js` and `backup.js` models.
This commit is contained in:

committed by
GitHub

parent
fb184fed06
commit
8b10fc2f8c
@ -1,16 +1,19 @@
|
|||||||
|
import DiscourseURL, { userPath } from "discourse/lib/url";
|
||||||
import { and, notEmpty } from "@ember/object/computed";
|
import { and, notEmpty } from "@ember/object/computed";
|
||||||
import { fmt, propertyNotEqual, setting } from "discourse/lib/computed";
|
import { fmt, propertyNotEqual, setting } from "discourse/lib/computed";
|
||||||
|
import AdminUser from "admin/models/admin-user";
|
||||||
import CanCheckEmails from "discourse/mixins/can-check-emails";
|
import CanCheckEmails from "discourse/mixins/can-check-emails";
|
||||||
import Controller from "@ember/controller";
|
import Controller from "@ember/controller";
|
||||||
import I18n from "I18n";
|
import I18n from "I18n";
|
||||||
import { ajax } from "discourse/lib/ajax";
|
import { ajax } from "discourse/lib/ajax";
|
||||||
import bootbox from "bootbox";
|
import bootbox from "bootbox";
|
||||||
import discourseComputed from "discourse-common/utils/decorators";
|
import discourseComputed from "discourse-common/utils/decorators";
|
||||||
|
import getURL from "discourse-common/lib/get-url";
|
||||||
import { htmlSafe } from "@ember/template";
|
import { htmlSafe } from "@ember/template";
|
||||||
|
import { iconHTML } from "discourse-common/lib/icon-library";
|
||||||
import { popupAjaxError } from "discourse/lib/ajax-error";
|
import { popupAjaxError } from "discourse/lib/ajax-error";
|
||||||
import { inject as service } from "@ember/service";
|
import { inject as service } from "@ember/service";
|
||||||
import showModal from "discourse/lib/show-modal";
|
import showModal from "discourse/lib/show-modal";
|
||||||
import { userPath } from "discourse/lib/url";
|
|
||||||
|
|
||||||
export default Controller.extend(CanCheckEmails, {
|
export default Controller.extend(CanCheckEmails, {
|
||||||
adminTools: service(),
|
adminTools: service(),
|
||||||
@ -141,10 +144,21 @@ export default Controller.extend(CanCheckEmails, {
|
|||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
impersonate() {
|
impersonate() {
|
||||||
return this.model.impersonate();
|
return this.model
|
||||||
|
.impersonate()
|
||||||
|
.then(() => DiscourseURL.redirectTo("/"))
|
||||||
|
.catch((e) => {
|
||||||
|
if (e.status === 404) {
|
||||||
|
bootbox.alert(I18n.t("admin.impersonate.not_found"));
|
||||||
|
} else {
|
||||||
|
bootbox.alert(I18n.t("admin.impersonate.invalid"));
|
||||||
|
}
|
||||||
|
});
|
||||||
},
|
},
|
||||||
logOut() {
|
logOut() {
|
||||||
return this.model.logOut();
|
return this.model
|
||||||
|
.logOut()
|
||||||
|
.then(() => bootbox.alert(I18n.t("admin.user.logged_out")));
|
||||||
},
|
},
|
||||||
resetBounceScore() {
|
resetBounceScore() {
|
||||||
return this.model.resetBounceScore();
|
return this.model.resetBounceScore();
|
||||||
@ -152,20 +166,56 @@ export default Controller.extend(CanCheckEmails, {
|
|||||||
approve() {
|
approve() {
|
||||||
return this.model.approve(this.currentUser);
|
return this.model.approve(this.currentUser);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_formatError(event) {
|
||||||
|
return `http: ${event.status} - ${event.body}`;
|
||||||
|
},
|
||||||
|
|
||||||
deactivate() {
|
deactivate() {
|
||||||
return this.model.deactivate();
|
return this.model
|
||||||
|
.deactivate()
|
||||||
|
.then(() =>
|
||||||
|
this.model.setProperties({ active: false, can_activate: true })
|
||||||
|
)
|
||||||
|
.catch((e) => {
|
||||||
|
const error = I18n.t("admin.user.deactivate_failed", {
|
||||||
|
error: this._formatError(e),
|
||||||
|
});
|
||||||
|
bootbox.alert(error);
|
||||||
|
});
|
||||||
},
|
},
|
||||||
sendActivationEmail() {
|
sendActivationEmail() {
|
||||||
return this.model.sendActivationEmail();
|
return this.model
|
||||||
|
.sendActivationEmail()
|
||||||
|
.then(() => bootbox.alert(I18n.t("admin.user.activation_email_sent")))
|
||||||
|
.catch(popupAjaxError);
|
||||||
},
|
},
|
||||||
activate() {
|
activate() {
|
||||||
return this.model.activate();
|
return this.model
|
||||||
|
.activate()
|
||||||
|
.then(() =>
|
||||||
|
this.model.setProperties({
|
||||||
|
active: true,
|
||||||
|
can_deactivate: !this.model.staff,
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.catch((e) => {
|
||||||
|
const error = I18n.t("admin.user.activate_failed", {
|
||||||
|
error: this._formatError(e),
|
||||||
|
});
|
||||||
|
bootbox.alert(error);
|
||||||
|
});
|
||||||
},
|
},
|
||||||
revokeAdmin() {
|
revokeAdmin() {
|
||||||
return this.model.revokeAdmin();
|
return this.model.revokeAdmin();
|
||||||
},
|
},
|
||||||
grantAdmin() {
|
grantAdmin() {
|
||||||
return this.model.grantAdmin();
|
return this.model
|
||||||
|
.grantAdmin()
|
||||||
|
.then(() => {
|
||||||
|
bootbox.alert(I18n.t("admin.user.grant_admin_confirm"));
|
||||||
|
})
|
||||||
|
.catch(popupAjaxError);
|
||||||
},
|
},
|
||||||
revokeModeration() {
|
revokeModeration() {
|
||||||
return this.model.revokeModeration();
|
return this.model.revokeModeration();
|
||||||
@ -174,13 +224,41 @@ export default Controller.extend(CanCheckEmails, {
|
|||||||
return this.model.grantModeration();
|
return this.model.grantModeration();
|
||||||
},
|
},
|
||||||
saveTrustLevel() {
|
saveTrustLevel() {
|
||||||
return this.model.saveTrustLevel();
|
return this.model
|
||||||
|
.saveTrustLevel()
|
||||||
|
.then(() => window.location.reload())
|
||||||
|
.catch((e) => {
|
||||||
|
let error;
|
||||||
|
if (e.jqXHR.responseJSON && e.jqXHR.responseJSON.errors) {
|
||||||
|
error = e.jqXHR.responseJSON.errors[0];
|
||||||
|
}
|
||||||
|
error =
|
||||||
|
error ||
|
||||||
|
I18n.t("admin.user.trust_level_change_failed", {
|
||||||
|
error: this._formatError(e),
|
||||||
|
});
|
||||||
|
bootbox.alert(error);
|
||||||
|
});
|
||||||
},
|
},
|
||||||
restoreTrustLevel() {
|
restoreTrustLevel() {
|
||||||
return this.model.restoreTrustLevel();
|
return this.model.restoreTrustLevel();
|
||||||
},
|
},
|
||||||
lockTrustLevel(locked) {
|
lockTrustLevel(locked) {
|
||||||
return this.model.lockTrustLevel(locked);
|
return this.model
|
||||||
|
.lockTrustLevel(locked)
|
||||||
|
.then(() => window.location.reload())
|
||||||
|
.catch((e) => {
|
||||||
|
let error;
|
||||||
|
if (e.jqXHR.responseJSON && e.jqXHR.responseJSON.errors) {
|
||||||
|
error = e.jqXHR.responseJSON.errors[0];
|
||||||
|
}
|
||||||
|
error =
|
||||||
|
error ||
|
||||||
|
I18n.t("admin.user.trust_level_change_failed", {
|
||||||
|
error: this._formatError(e),
|
||||||
|
});
|
||||||
|
bootbox.alert(error);
|
||||||
|
});
|
||||||
},
|
},
|
||||||
unsilence() {
|
unsilence() {
|
||||||
return this.model.unsilence();
|
return this.model.unsilence();
|
||||||
@ -189,11 +267,119 @@ export default Controller.extend(CanCheckEmails, {
|
|||||||
return this.model.silence();
|
return this.model.silence();
|
||||||
},
|
},
|
||||||
deleteAllPosts() {
|
deleteAllPosts() {
|
||||||
return this.model.deleteAllPosts();
|
let deletedPosts = 0;
|
||||||
|
let deletedPercentage = 0;
|
||||||
|
const user = this.model;
|
||||||
|
const message = I18n.messageFormat(
|
||||||
|
"admin.user.delete_all_posts_confirm_MF",
|
||||||
|
{
|
||||||
|
POSTS: user.get("post_count"),
|
||||||
|
TOPICS: user.get("topic_count"),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
const performDelete = (progressModal) => {
|
||||||
|
this.model
|
||||||
|
.deleteAllPosts()
|
||||||
|
.then(({ posts_deleted }) => {
|
||||||
|
if (posts_deleted === 0) {
|
||||||
|
user.set("post_count", 0);
|
||||||
|
progressModal.send("closeModal");
|
||||||
|
} else {
|
||||||
|
deletedPosts += posts_deleted;
|
||||||
|
deletedPercentage = Math.floor(
|
||||||
|
(deletedPosts * 100) / user.get("post_count")
|
||||||
|
);
|
||||||
|
progressModal.setProperties({
|
||||||
|
deletedPercentage: deletedPercentage,
|
||||||
|
});
|
||||||
|
performDelete(progressModal);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((e) => {
|
||||||
|
progressModal.send("closeModal");
|
||||||
|
let error;
|
||||||
|
AdminUser.find(user.get("id")).then((u) => user.setProperties(u));
|
||||||
|
if (e.jqXHR.responseJSON && e.jqXHR.responseJSON.errors) {
|
||||||
|
error = e.jqXHR.responseJSON.errors[0];
|
||||||
|
}
|
||||||
|
error = error || I18n.t("admin.user.delete_posts_failed");
|
||||||
|
bootbox.alert(error);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const buttons = [
|
||||||
|
{
|
||||||
|
label: I18n.t("composer.cancel"),
|
||||||
|
class: "d-modal-cancel",
|
||||||
|
link: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label:
|
||||||
|
`${iconHTML("exclamation-triangle")} ` +
|
||||||
|
I18n.t("admin.user.delete_all_posts"),
|
||||||
|
class: "btn btn-danger",
|
||||||
|
callback: () => {
|
||||||
|
const progressModal = openProgressModal();
|
||||||
|
performDelete(progressModal);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const openProgressModal = () => {
|
||||||
|
return showModal("admin-delete-user-posts-progress", {
|
||||||
|
admin: true,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
bootbox.dialog(message, buttons, { classes: "delete-all-posts" });
|
||||||
},
|
},
|
||||||
|
|
||||||
anonymize() {
|
anonymize() {
|
||||||
return this.model.anonymize();
|
const user = this.model;
|
||||||
|
const message = I18n.t("admin.user.anonymize_confirm");
|
||||||
|
|
||||||
|
const performAnonymize = () => {
|
||||||
|
this.model
|
||||||
|
.anonymize()
|
||||||
|
.then((data) => {
|
||||||
|
if (data.success) {
|
||||||
|
if (data.username) {
|
||||||
|
document.location = getURL(
|
||||||
|
`/admin/users/${user.get("id")}/${data.username}`
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
document.location = getURL("/admin/users/list/active");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
bootbox.alert(I18n.t("admin.user.anonymize_failed"));
|
||||||
|
if (data.user) {
|
||||||
|
user.setProperties(data.user);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(() => bootbox.alert(I18n.t("admin.user.anonymize_failed")));
|
||||||
|
};
|
||||||
|
const buttons = [
|
||||||
|
{
|
||||||
|
label: I18n.t("composer.cancel"),
|
||||||
|
class: "cancel",
|
||||||
|
link: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label:
|
||||||
|
`${iconHTML("exclamation-triangle")} ` +
|
||||||
|
I18n.t("admin.user.anonymize_yes"),
|
||||||
|
class: "btn btn-danger",
|
||||||
|
callback: () => {
|
||||||
|
performAnonymize();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
bootbox.dialog(message, buttons, { classes: "delete-user-modal" });
|
||||||
},
|
},
|
||||||
|
|
||||||
disableSecondFactor() {
|
disableSecondFactor() {
|
||||||
return this.model.disableSecondFactor();
|
return this.model.disableSecondFactor();
|
||||||
},
|
},
|
||||||
@ -210,11 +396,68 @@ export default Controller.extend(CanCheckEmails, {
|
|||||||
destroy() {
|
destroy() {
|
||||||
const postCount = this.get("model.post_count");
|
const postCount = this.get("model.post_count");
|
||||||
const maxPostCount = this.siteSettings.delete_all_posts_max;
|
const maxPostCount = this.siteSettings.delete_all_posts_max;
|
||||||
if (postCount <= maxPostCount) {
|
const user = this.model;
|
||||||
return this.model.destroy({ deletePosts: true });
|
const message = I18n.t("admin.user.delete_confirm");
|
||||||
} else {
|
const location = document.location.pathname;
|
||||||
return this.model.destroy();
|
|
||||||
}
|
const performDestroy = (block) => {
|
||||||
|
bootbox.dialog(I18n.t("admin.user.deleting_user"));
|
||||||
|
let formData = { context: location };
|
||||||
|
if (block) {
|
||||||
|
formData["block_email"] = true;
|
||||||
|
formData["block_urls"] = true;
|
||||||
|
formData["block_ip"] = true;
|
||||||
|
}
|
||||||
|
if (postCount <= maxPostCount) {
|
||||||
|
formData["delete_posts"] = true;
|
||||||
|
}
|
||||||
|
this.model
|
||||||
|
.destroy(formData)
|
||||||
|
.then((data) => {
|
||||||
|
if (data.deleted) {
|
||||||
|
if (/^\/admin\/users\/list\//.test(location)) {
|
||||||
|
document.location = location;
|
||||||
|
} else {
|
||||||
|
document.location = getURL("/admin/users/list/active");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
bootbox.alert(I18n.t("admin.user.delete_failed"));
|
||||||
|
if (data.user) {
|
||||||
|
user.setProperties(data.user);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
AdminUser.find(user.get("id")).then((u) => user.setProperties(u));
|
||||||
|
bootbox.alert(I18n.t("admin.user.delete_failed"));
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const buttons = [
|
||||||
|
{
|
||||||
|
label: I18n.t("composer.cancel"),
|
||||||
|
class: "btn",
|
||||||
|
link: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label:
|
||||||
|
`${iconHTML("exclamation-triangle")} ` +
|
||||||
|
I18n.t("admin.user.delete_and_block"),
|
||||||
|
class: "btn btn-danger",
|
||||||
|
callback: () => {
|
||||||
|
performDestroy(true);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: I18n.t("admin.user.delete_dont_block"),
|
||||||
|
class: "btn btn-primary",
|
||||||
|
callback: () => {
|
||||||
|
performDestroy(false);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
bootbox.dialog(message, buttons, { classes: "delete-user-modal" });
|
||||||
},
|
},
|
||||||
|
|
||||||
promptTargetUser() {
|
promptTargetUser() {
|
||||||
@ -235,7 +478,31 @@ export default Controller.extend(CanCheckEmails, {
|
|||||||
},
|
},
|
||||||
|
|
||||||
merge(targetUsername) {
|
merge(targetUsername) {
|
||||||
return this.model.merge({ targetUsername });
|
const user = this.model;
|
||||||
|
const location = document.location.pathname;
|
||||||
|
|
||||||
|
let formData = { context: location };
|
||||||
|
|
||||||
|
if (targetUsername) {
|
||||||
|
formData["target_username"] = targetUsername;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.model
|
||||||
|
.merge(formData)
|
||||||
|
.then((response) => {
|
||||||
|
if (response.success) {
|
||||||
|
showModal("admin-merge-users-progress", {
|
||||||
|
admin: true,
|
||||||
|
model: this.model,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
bootbox.alert(I18n.t("admin.user.merge_failed"));
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
AdminUser.find(user.id).then((u) => user.setProperties(u));
|
||||||
|
bootbox.alert(I18n.t("admin.user.merge_failed"));
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
viewActionLogs() {
|
viewActionLogs() {
|
||||||
|
@ -0,0 +1,6 @@
|
|||||||
|
import Controller from "@ember/controller";
|
||||||
|
import ModalFunctionality from "discourse/mixins/modal-functionality";
|
||||||
|
|
||||||
|
export default Controller.extend(ModalFunctionality, {
|
||||||
|
deletedPercentage: 0,
|
||||||
|
});
|
@ -0,0 +1,31 @@
|
|||||||
|
import Controller from "@ember/controller";
|
||||||
|
import DiscourseURL from "discourse/lib/url";
|
||||||
|
import I18n from "I18n";
|
||||||
|
import ModalFunctionality from "discourse/mixins/modal-functionality";
|
||||||
|
import messageBus from "message-bus-client";
|
||||||
|
|
||||||
|
export default Controller.extend(ModalFunctionality, {
|
||||||
|
message: I18n.t("admin.user.merging_user"),
|
||||||
|
|
||||||
|
onShow() {
|
||||||
|
messageBus.subscribe("/merge_user", (data) => {
|
||||||
|
if (data.merged) {
|
||||||
|
if (/^\/admin\/users\/list\//.test(location)) {
|
||||||
|
DiscourseURL.redirectTo(location);
|
||||||
|
} else {
|
||||||
|
DiscourseURL.redirectTo(
|
||||||
|
`/admin/users/${data.user.id}/${data.user.username}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else if (data.message) {
|
||||||
|
this.set("message", data.message);
|
||||||
|
} else if (data.failed) {
|
||||||
|
this.set("message", I18n.t("admin.user.merge_failed"));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
onClose() {
|
||||||
|
this.messageBus.unsubscribe("/merge_user");
|
||||||
|
},
|
||||||
|
});
|
@ -1,17 +1,14 @@
|
|||||||
import DiscourseURL, { userPath } from "discourse/lib/url";
|
|
||||||
import { filter, gt, lt, not, or } from "@ember/object/computed";
|
import { filter, gt, lt, not, or } from "@ember/object/computed";
|
||||||
import Group from "discourse/models/group";
|
import Group from "discourse/models/group";
|
||||||
import I18n from "I18n";
|
import I18n from "I18n";
|
||||||
import { Promise } from "rsvp";
|
import { Promise } from "rsvp";
|
||||||
import User from "discourse/models/user";
|
import User from "discourse/models/user";
|
||||||
import { ajax } from "discourse/lib/ajax";
|
import { ajax } from "discourse/lib/ajax";
|
||||||
import bootbox from "bootbox";
|
|
||||||
import discourseComputed from "discourse-common/utils/decorators";
|
import discourseComputed from "discourse-common/utils/decorators";
|
||||||
import getURL from "discourse-common/lib/get-url";
|
import getURL from "discourse-common/lib/get-url";
|
||||||
import { iconHTML } from "discourse-common/lib/icon-library";
|
|
||||||
import messageBus from "message-bus-client";
|
|
||||||
import { popupAjaxError } from "discourse/lib/ajax-error";
|
import { popupAjaxError } from "discourse/lib/ajax-error";
|
||||||
import { propertyNotEqual } from "discourse/lib/computed";
|
import { propertyNotEqual } from "discourse/lib/computed";
|
||||||
|
import { userPath } from "discourse/lib/url";
|
||||||
|
|
||||||
const wrapAdmin = (user) => (user ? AdminUser.create(user) : null);
|
const wrapAdmin = (user) => (user ? AdminUser.create(user) : null);
|
||||||
|
|
||||||
@ -81,74 +78,9 @@ const AdminUser = User.extend({
|
|||||||
},
|
},
|
||||||
|
|
||||||
deleteAllPosts() {
|
deleteAllPosts() {
|
||||||
let deletedPosts = 0;
|
return ajax(`/admin/users/${this.get("id")}/delete_posts_batch`, {
|
||||||
const user = this;
|
type: "PUT",
|
||||||
const message = I18n.messageFormat(
|
});
|
||||||
"admin.user.delete_all_posts_confirm_MF",
|
|
||||||
{
|
|
||||||
POSTS: user.get("post_count"),
|
|
||||||
TOPICS: user.get("topic_count"),
|
|
||||||
}
|
|
||||||
);
|
|
||||||
const buttons = [
|
|
||||||
{
|
|
||||||
label: I18n.t("composer.cancel"),
|
|
||||||
class: "d-modal-cancel",
|
|
||||||
link: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label:
|
|
||||||
`${iconHTML("exclamation-triangle")} ` +
|
|
||||||
I18n.t("admin.user.delete_all_posts"),
|
|
||||||
class: "btn btn-danger",
|
|
||||||
callback: () => {
|
|
||||||
openProgressModal();
|
|
||||||
performDelete();
|
|
||||||
},
|
|
||||||
},
|
|
||||||
];
|
|
||||||
const openProgressModal = () => {
|
|
||||||
bootbox.dialog(
|
|
||||||
`<p>${I18n.t(
|
|
||||||
"admin.user.delete_posts_progress"
|
|
||||||
)}</p><div class='progress-bar'><span></span></div>`,
|
|
||||||
[],
|
|
||||||
{ classes: "delete-posts-progress" }
|
|
||||||
);
|
|
||||||
};
|
|
||||||
const performDelete = () => {
|
|
||||||
let deletedPercentage = 0;
|
|
||||||
return ajax(`/admin/users/${user.get("id")}/delete_posts_batch`, {
|
|
||||||
type: "PUT",
|
|
||||||
})
|
|
||||||
.then(({ posts_deleted }) => {
|
|
||||||
if (posts_deleted === 0) {
|
|
||||||
user.set("post_count", 0);
|
|
||||||
bootbox.hideAll();
|
|
||||||
} else {
|
|
||||||
deletedPosts += posts_deleted;
|
|
||||||
deletedPercentage = Math.floor(
|
|
||||||
(deletedPosts * 100) / user.get("post_count")
|
|
||||||
);
|
|
||||||
$(".delete-posts-progress .progress-bar > span").css({
|
|
||||||
width: `${deletedPercentage}%`,
|
|
||||||
});
|
|
||||||
performDelete();
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch((e) => {
|
|
||||||
bootbox.hideAll();
|
|
||||||
let error;
|
|
||||||
AdminUser.find(user.get("id")).then((u) => user.setProperties(u));
|
|
||||||
if (e.jqXHR.responseJSON && e.jqXHR.responseJSON.errors) {
|
|
||||||
error = e.jqXHR.responseJSON.errors[0];
|
|
||||||
}
|
|
||||||
error = error || I18n.t("admin.user.delete_posts_failed");
|
|
||||||
bootbox.alert(error);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
bootbox.dialog(message, buttons, { classes: "delete-all-posts" });
|
|
||||||
},
|
},
|
||||||
|
|
||||||
revokeAdmin() {
|
revokeAdmin() {
|
||||||
@ -166,11 +98,7 @@ const AdminUser = User.extend({
|
|||||||
grantAdmin() {
|
grantAdmin() {
|
||||||
return ajax(`/admin/users/${this.id}/grant_admin`, {
|
return ajax(`/admin/users/${this.id}/grant_admin`, {
|
||||||
type: "PUT",
|
type: "PUT",
|
||||||
})
|
});
|
||||||
.then(() => {
|
|
||||||
bootbox.alert(I18n.t("admin.user.grant_admin_confirm"));
|
|
||||||
})
|
|
||||||
.catch(popupAjaxError);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
revokeModeration() {
|
revokeModeration() {
|
||||||
@ -233,20 +161,7 @@ const AdminUser = User.extend({
|
|||||||
return ajax(`/admin/users/${this.id}/trust_level`, {
|
return ajax(`/admin/users/${this.id}/trust_level`, {
|
||||||
type: "PUT",
|
type: "PUT",
|
||||||
data: { level: this.trust_level },
|
data: { level: this.trust_level },
|
||||||
})
|
});
|
||||||
.then(() => window.location.reload())
|
|
||||||
.catch((e) => {
|
|
||||||
let error;
|
|
||||||
if (e.jqXHR.responseJSON && e.jqXHR.responseJSON.errors) {
|
|
||||||
error = e.jqXHR.responseJSON.errors[0];
|
|
||||||
}
|
|
||||||
error =
|
|
||||||
error ||
|
|
||||||
I18n.t("admin.user.trust_level_change_failed", {
|
|
||||||
error: this._formatError(e),
|
|
||||||
});
|
|
||||||
bootbox.alert(error);
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
restoreTrustLevel() {
|
restoreTrustLevel() {
|
||||||
@ -257,20 +172,7 @@ const AdminUser = User.extend({
|
|||||||
return ajax(`/admin/users/${this.id}/trust_level_lock`, {
|
return ajax(`/admin/users/${this.id}/trust_level_lock`, {
|
||||||
type: "PUT",
|
type: "PUT",
|
||||||
data: { locked: !!locked },
|
data: { locked: !!locked },
|
||||||
})
|
});
|
||||||
.then(() => window.location.reload())
|
|
||||||
.catch((e) => {
|
|
||||||
let error;
|
|
||||||
if (e.jqXHR.responseJSON && e.jqXHR.responseJSON.errors) {
|
|
||||||
error = e.jqXHR.responseJSON.errors[0];
|
|
||||||
}
|
|
||||||
error =
|
|
||||||
error ||
|
|
||||||
I18n.t("admin.user.trust_level_change_failed", {
|
|
||||||
error: this._formatError(e),
|
|
||||||
});
|
|
||||||
bootbox.alert(error);
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
canLockTrustLevel: lt("trust_level", 4),
|
canLockTrustLevel: lt("trust_level", 4),
|
||||||
@ -301,49 +203,27 @@ const AdminUser = User.extend({
|
|||||||
return ajax("/admin/users/" + this.id + "/log_out", {
|
return ajax("/admin/users/" + this.id + "/log_out", {
|
||||||
type: "POST",
|
type: "POST",
|
||||||
data: { username_or_email: this.username },
|
data: { username_or_email: this.username },
|
||||||
}).then(() => bootbox.alert(I18n.t("admin.user.logged_out")));
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
impersonate() {
|
impersonate() {
|
||||||
return ajax("/admin/impersonate", {
|
return ajax("/admin/impersonate", {
|
||||||
type: "POST",
|
type: "POST",
|
||||||
data: { username_or_email: this.username },
|
data: { username_or_email: this.username },
|
||||||
})
|
});
|
||||||
.then(() => (document.location = getURL("/")))
|
|
||||||
.catch((e) => {
|
|
||||||
if (e.status === 404) {
|
|
||||||
bootbox.alert(I18n.t("admin.impersonate.not_found"));
|
|
||||||
} else {
|
|
||||||
bootbox.alert(I18n.t("admin.impersonate.invalid"));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
activate() {
|
activate() {
|
||||||
return ajax(`/admin/users/${this.id}/activate`, {
|
return ajax(`/admin/users/${this.id}/activate`, {
|
||||||
type: "PUT",
|
type: "PUT",
|
||||||
})
|
});
|
||||||
.then(() => window.location.reload())
|
|
||||||
.catch((e) => {
|
|
||||||
const error = I18n.t("admin.user.activate_failed", {
|
|
||||||
error: this._formatError(e),
|
|
||||||
});
|
|
||||||
bootbox.alert(error);
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
deactivate() {
|
deactivate() {
|
||||||
return ajax(`/admin/users/${this.id}/deactivate`, {
|
return ajax(`/admin/users/${this.id}/deactivate`, {
|
||||||
type: "PUT",
|
type: "PUT",
|
||||||
data: { context: document.location.pathname },
|
data: { context: document.location.pathname },
|
||||||
})
|
});
|
||||||
.then(() => window.location.reload())
|
|
||||||
.catch((e) => {
|
|
||||||
const error = I18n.t("admin.user.deactivate_failed", {
|
|
||||||
error: this._formatError(e),
|
|
||||||
});
|
|
||||||
bootbox.alert(error);
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
unsilence() {
|
unsilence() {
|
||||||
@ -371,165 +251,27 @@ const AdminUser = User.extend({
|
|||||||
return ajax(userPath("action/send_activation_email"), {
|
return ajax(userPath("action/send_activation_email"), {
|
||||||
type: "POST",
|
type: "POST",
|
||||||
data: { username: this.username },
|
data: { username: this.username },
|
||||||
})
|
});
|
||||||
.then(() => bootbox.alert(I18n.t("admin.user.activation_email_sent")))
|
|
||||||
.catch(popupAjaxError);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
anonymize() {
|
anonymize() {
|
||||||
const user = this;
|
return ajax(`/admin/users/${this.id}/anonymize.json`, {
|
||||||
const message = I18n.t("admin.user.anonymize_confirm");
|
type: "PUT",
|
||||||
|
});
|
||||||
const performAnonymize = function () {
|
|
||||||
return ajax(`/admin/users/${user.get("id")}/anonymize.json`, {
|
|
||||||
type: "PUT",
|
|
||||||
})
|
|
||||||
.then(function (data) {
|
|
||||||
if (data.success) {
|
|
||||||
if (data.username) {
|
|
||||||
document.location = getURL(
|
|
||||||
`/admin/users/${user.get("id")}/${data.username}`
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
document.location = getURL("/admin/users/list/active");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
bootbox.alert(I18n.t("admin.user.anonymize_failed"));
|
|
||||||
if (data.user) {
|
|
||||||
user.setProperties(data.user);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(() => bootbox.alert(I18n.t("admin.user.anonymize_failed")));
|
|
||||||
};
|
|
||||||
|
|
||||||
const buttons = [
|
|
||||||
{
|
|
||||||
label: I18n.t("composer.cancel"),
|
|
||||||
class: "cancel",
|
|
||||||
link: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label:
|
|
||||||
`${iconHTML("exclamation-triangle")} ` +
|
|
||||||
I18n.t("admin.user.anonymize_yes"),
|
|
||||||
class: "btn btn-danger",
|
|
||||||
callback: function () {
|
|
||||||
performAnonymize();
|
|
||||||
},
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
bootbox.dialog(message, buttons, { classes: "delete-user-modal" });
|
|
||||||
},
|
},
|
||||||
|
|
||||||
destroy(opts) {
|
destroy(formData) {
|
||||||
const user = this;
|
return ajax(`/admin/users/${this.id}.json`, {
|
||||||
const message = I18n.t("admin.user.delete_confirm");
|
type: "DELETE",
|
||||||
const location = document.location.pathname;
|
data: formData,
|
||||||
|
});
|
||||||
const performDestroy = function (block) {
|
|
||||||
bootbox.dialog(I18n.t("admin.user.deleting_user"));
|
|
||||||
let formData = { context: location };
|
|
||||||
if (block) {
|
|
||||||
formData["block_email"] = true;
|
|
||||||
formData["block_urls"] = true;
|
|
||||||
formData["block_ip"] = true;
|
|
||||||
}
|
|
||||||
if (opts && opts.deletePosts) {
|
|
||||||
formData["delete_posts"] = true;
|
|
||||||
}
|
|
||||||
return ajax(`/admin/users/${user.get("id")}.json`, {
|
|
||||||
type: "DELETE",
|
|
||||||
data: formData,
|
|
||||||
})
|
|
||||||
.then(function (data) {
|
|
||||||
if (data.deleted) {
|
|
||||||
if (/^\/admin\/users\/list\//.test(location)) {
|
|
||||||
document.location = location;
|
|
||||||
} else {
|
|
||||||
document.location = getURL("/admin/users/list/active");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
bootbox.alert(I18n.t("admin.user.delete_failed"));
|
|
||||||
if (data.user) {
|
|
||||||
user.setProperties(data.user);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(function () {
|
|
||||||
AdminUser.find(user.get("id")).then((u) => user.setProperties(u));
|
|
||||||
bootbox.alert(I18n.t("admin.user.delete_failed"));
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const buttons = [
|
|
||||||
{
|
|
||||||
label: I18n.t("composer.cancel"),
|
|
||||||
class: "btn",
|
|
||||||
link: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label:
|
|
||||||
`${iconHTML("exclamation-triangle")} ` +
|
|
||||||
I18n.t("admin.user.delete_and_block"),
|
|
||||||
class: "btn btn-danger",
|
|
||||||
callback: function () {
|
|
||||||
performDestroy(true);
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: I18n.t("admin.user.delete_dont_block"),
|
|
||||||
class: "btn btn-primary",
|
|
||||||
callback: function () {
|
|
||||||
performDestroy(false);
|
|
||||||
},
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
bootbox.dialog(message, buttons, { classes: "delete-user-modal" });
|
|
||||||
},
|
},
|
||||||
|
|
||||||
merge(opts) {
|
merge(formData) {
|
||||||
const user = this;
|
return ajax(`/admin/users/${this.id}/merge.json`, {
|
||||||
const location = document.location.pathname;
|
|
||||||
|
|
||||||
const bootboxDiv = bootbox.dialog(I18n.t("admin.user.merging_user"));
|
|
||||||
let formData = { context: location };
|
|
||||||
|
|
||||||
if (opts && opts.targetUsername) {
|
|
||||||
formData["target_username"] = opts.targetUsername;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ajax(`/admin/users/${user.id}/merge.json`, {
|
|
||||||
type: "POST",
|
type: "POST",
|
||||||
data: formData,
|
data: formData,
|
||||||
})
|
});
|
||||||
.then((response) => {
|
|
||||||
if (response.success) {
|
|
||||||
messageBus.subscribe("/merge_user", (data) => {
|
|
||||||
if (data.merged) {
|
|
||||||
if (/^\/admin\/users\/list\//.test(location)) {
|
|
||||||
DiscourseURL.redirectTo(location);
|
|
||||||
} else {
|
|
||||||
DiscourseURL.redirectTo(
|
|
||||||
`/admin/users/${data.user.id}/${data.user.username}`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} else if (data.message) {
|
|
||||||
bootboxDiv.find(".modal-body").html(data.message);
|
|
||||||
} else if (data.failed) {
|
|
||||||
bootbox.alert(I18n.t("admin.user.merge_failed"));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
bootbox.alert(I18n.t("admin.user.merge_failed"));
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(() => {
|
|
||||||
AdminUser.find(user.id).then((u) => user.setProperties(u));
|
|
||||||
bootbox.alert(I18n.t("admin.user.merge_failed"));
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
loadDetails() {
|
loadDetails() {
|
||||||
@ -559,10 +301,6 @@ const AdminUser = User.extend({
|
|||||||
@discourseComputed("approved_by")
|
@discourseComputed("approved_by")
|
||||||
approvedBy: wrapAdmin,
|
approvedBy: wrapAdmin,
|
||||||
|
|
||||||
_formatError(event) {
|
|
||||||
return `http: ${event.status} - ${event.body}`;
|
|
||||||
},
|
|
||||||
|
|
||||||
deleteSSORecord() {
|
deleteSSORecord() {
|
||||||
return ajax(`/admin/users/${this.id}/sso_record.json`, {
|
return ajax(`/admin/users/${this.id}/sso_record.json`, {
|
||||||
type: "DELETE",
|
type: "DELETE",
|
||||||
|
@ -1,10 +1,6 @@
|
|||||||
import EmberObject from "@ember/object";
|
import EmberObject from "@ember/object";
|
||||||
import I18n from "I18n";
|
|
||||||
import MessageBus from "message-bus-client";
|
import MessageBus from "message-bus-client";
|
||||||
import { ajax } from "discourse/lib/ajax";
|
import { ajax } from "discourse/lib/ajax";
|
||||||
import bootbox from "bootbox";
|
|
||||||
import { extractError } from "discourse/lib/ajax-error";
|
|
||||||
import getURL from "discourse-common/lib/get-url";
|
|
||||||
|
|
||||||
const Backup = EmberObject.extend({
|
const Backup = EmberObject.extend({
|
||||||
destroy() {
|
destroy() {
|
||||||
@ -21,16 +17,7 @@ const Backup = EmberObject.extend({
|
|||||||
|
|
||||||
Backup.reopenClass({
|
Backup.reopenClass({
|
||||||
find() {
|
find() {
|
||||||
return ajax("/admin/backups.json")
|
return ajax("/admin/backups.json");
|
||||||
.then((backups) => backups.map((backup) => Backup.create(backup)))
|
|
||||||
.catch((error) => {
|
|
||||||
bootbox.alert(
|
|
||||||
I18n.t("admin.backups.backup_storage_error", {
|
|
||||||
error_message: extractError(error),
|
|
||||||
})
|
|
||||||
);
|
|
||||||
return [];
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
start(withUploads) {
|
start(withUploads) {
|
||||||
@ -43,33 +30,18 @@ Backup.reopenClass({
|
|||||||
with_uploads: withUploads,
|
with_uploads: withUploads,
|
||||||
client_id: MessageBus.clientId,
|
client_id: MessageBus.clientId,
|
||||||
},
|
},
|
||||||
}).then((result) => {
|
|
||||||
if (!result.success) {
|
|
||||||
bootbox.alert(result.message);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
cancel() {
|
cancel() {
|
||||||
return ajax("/admin/backups/cancel.json", {
|
return ajax("/admin/backups/cancel.json", {
|
||||||
type: "DELETE",
|
type: "DELETE",
|
||||||
}).then((result) => {
|
|
||||||
if (!result.success) {
|
|
||||||
bootbox.alert(result.message);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
rollback() {
|
rollback() {
|
||||||
return ajax("/admin/backups/rollback.json", {
|
return ajax("/admin/backups/rollback.json", {
|
||||||
type: "POST",
|
type: "POST",
|
||||||
}).then((result) => {
|
|
||||||
if (!result.success) {
|
|
||||||
bootbox.alert(result.message);
|
|
||||||
} else {
|
|
||||||
// redirect to homepage (session might be lost)
|
|
||||||
window.location = getURL("/");
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -12,7 +12,9 @@ export default Route.extend({
|
|||||||
},
|
},
|
||||||
|
|
||||||
model() {
|
model() {
|
||||||
return Backup.find();
|
return Backup.find().then((backups) =>
|
||||||
|
backups.map((backup) => Backup.create(backup))
|
||||||
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
deactivate() {
|
deactivate() {
|
||||||
|
@ -7,6 +7,7 @@ import PreloadStore from "discourse/lib/preload-store";
|
|||||||
import User from "discourse/models/user";
|
import User from "discourse/models/user";
|
||||||
import { ajax } from "discourse/lib/ajax";
|
import { ajax } from "discourse/lib/ajax";
|
||||||
import bootbox from "bootbox";
|
import bootbox from "bootbox";
|
||||||
|
import { extractError } from "discourse/lib/ajax-error";
|
||||||
import getURL from "discourse-common/lib/get-url";
|
import getURL from "discourse-common/lib/get-url";
|
||||||
import showModal from "discourse/lib/show-modal";
|
import showModal from "discourse/lib/show-modal";
|
||||||
|
|
||||||
@ -74,7 +75,11 @@ export default DiscourseRoute.extend({
|
|||||||
|
|
||||||
startBackup(withUploads) {
|
startBackup(withUploads) {
|
||||||
this.transitionTo("admin.backups.logs");
|
this.transitionTo("admin.backups.logs");
|
||||||
Backup.start(withUploads);
|
Backup.start(withUploads).then((result) => {
|
||||||
|
if (!result.success) {
|
||||||
|
bootbox.alert(result.message);
|
||||||
|
}
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
destroyBackup(backup) {
|
destroyBackup(backup) {
|
||||||
@ -135,7 +140,14 @@ export default DiscourseRoute.extend({
|
|||||||
I18n.t("yes_value"),
|
I18n.t("yes_value"),
|
||||||
(confirmed) => {
|
(confirmed) => {
|
||||||
if (confirmed) {
|
if (confirmed) {
|
||||||
Backup.rollback();
|
Backup.rollback().then((result) => {
|
||||||
|
if (!result.success) {
|
||||||
|
bootbox.alert(result.message);
|
||||||
|
} else {
|
||||||
|
// redirect to homepage (session might be lost)
|
||||||
|
window.location = getURL("/");
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -152,12 +164,22 @@ export default DiscourseRoute.extend({
|
|||||||
},
|
},
|
||||||
|
|
||||||
remoteUploadSuccess() {
|
remoteUploadSuccess() {
|
||||||
Backup.find().then((backups) => {
|
Backup.find()
|
||||||
this.controllerFor("adminBackupsIndex").set(
|
.then((backups) => backups.map((backup) => Backup.create(backup)))
|
||||||
"model",
|
.then((backups) => {
|
||||||
backups.map((backup) => Backup.create(backup))
|
this.controllerFor("adminBackupsIndex").set(
|
||||||
);
|
"model",
|
||||||
});
|
backups.map((backup) => Backup.create(backup))
|
||||||
|
);
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
bootbox.alert(
|
||||||
|
I18n.t("admin.backups.backup_storage_error", {
|
||||||
|
error_message: extractError(error),
|
||||||
|
})
|
||||||
|
);
|
||||||
|
return [];
|
||||||
|
});
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -0,0 +1,4 @@
|
|||||||
|
{{#d-modal-body title="admin.user.delete_posts.progress.title" dismissable=false}}
|
||||||
|
<p>{{I18n "admin.user.delete_posts_progress"}}</p>
|
||||||
|
<div class="progress-bar"><span style={{html-safe (concat "width: " deletedPercentage "%")}}></span></div>
|
||||||
|
{{/d-modal-body}}
|
@ -0,0 +1,3 @@
|
|||||||
|
{{#d-modal-body title="admin.user.merge.progress.title" dismissable=false}}
|
||||||
|
{{ message }}
|
||||||
|
{{/d-modal-body}}
|
@ -322,7 +322,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.delete-posts-progress {
|
.admin-delete-user-posts-progress-modal {
|
||||||
.progress-bar {
|
.progress-bar {
|
||||||
height: 15px;
|
height: 15px;
|
||||||
position: relative;
|
position: relative;
|
||||||
|
@ -4663,6 +4663,9 @@ en:
|
|||||||
anonymize_yes: "Yes, anonymize this account"
|
anonymize_yes: "Yes, anonymize this account"
|
||||||
anonymize_failed: "There was a problem anonymizing the account."
|
anonymize_failed: "There was a problem anonymizing the account."
|
||||||
delete: "Delete User"
|
delete: "Delete User"
|
||||||
|
delete_posts:
|
||||||
|
progress:
|
||||||
|
title: "Progress of deleting posts"
|
||||||
merge:
|
merge:
|
||||||
button: "Merge"
|
button: "Merge"
|
||||||
prompt:
|
prompt:
|
||||||
@ -4675,6 +4678,8 @@ en:
|
|||||||
target_username_placeholder: "Username of new owner"
|
target_username_placeholder: "Username of new owner"
|
||||||
transfer_and_delete: "Transfer & Delete @%{username}"
|
transfer_and_delete: "Transfer & Delete @%{username}"
|
||||||
cancel: "Cancel"
|
cancel: "Cancel"
|
||||||
|
progress:
|
||||||
|
title: "Merge progress"
|
||||||
confirmation:
|
confirmation:
|
||||||
title: "Transfer & Delete @%{username}"
|
title: "Transfer & Delete @%{username}"
|
||||||
description: |
|
description: |
|
||||||
|
Reference in New Issue
Block a user