mirror of
https://github.com/discourse/discourse.git
synced 2024-11-28 22:08:33 +08:00
a5542eeab0
<img width="681" alt="Screenshot 2023-08-03 at 12 55 08 PM" src="https://github.com/discourse/discourse/assets/50783505/79cc045a-523d-45a2-8c33-04b556331358"> <img width="763" alt="Screenshot 2023-08-03 at 12 55 05 PM" src="https://github.com/discourse/discourse/assets/50783505/7196a97f-e4f4-4870-b8ac-77255d604c27"> <img width="711" alt="Screenshot 2023-08-03 at 12 55 11 PM" src="https://github.com/discourse/discourse/assets/50783505/a916a85d-8bdb-41fb-8210-1e0c06cf7cf1">
126 lines
3.7 KiB
JavaScript
126 lines
3.7 KiB
JavaScript
import AdminUser from "admin/models/admin-user";
|
|
import I18n from "I18n";
|
|
import { Promise } from "rsvp";
|
|
import Service, { inject as service } from "@ember/service";
|
|
import { ajax } from "discourse/lib/ajax";
|
|
import { getOwner } from "discourse-common/lib/get-owner";
|
|
import { htmlSafe } from "@ember/template";
|
|
import { action } from "@ember/object";
|
|
import PenalizeUserModal from "admin/components/modal/penalize-user";
|
|
|
|
// A service that can act as a bridge between the front end Discourse application
|
|
// and the admin application. Use this if you need front end code to access admin
|
|
// modules. Inject it optionally, and if it exists go to town!
|
|
export default class AdminToolsService extends Service {
|
|
@service dialog;
|
|
@service modal;
|
|
|
|
showActionLogs(target, filters) {
|
|
const controller = getOwner(target).lookup(
|
|
"controller:adminLogs.staffActionLogs"
|
|
);
|
|
target.transitionToRoute("adminLogs.staffActionLogs").then(() => {
|
|
controller.changeFilters(filters);
|
|
});
|
|
}
|
|
|
|
checkSpammer(userId) {
|
|
return AdminUser.find(userId).then((au) => this.spammerDetails(au));
|
|
}
|
|
|
|
deleteUser(id, formData) {
|
|
return AdminUser.find(id).then((user) => user.destroy(formData));
|
|
}
|
|
|
|
spammerDetails(adminUser) {
|
|
return {
|
|
deleteUser: () => this._deleteSpammer(adminUser),
|
|
canDelete:
|
|
adminUser.get("can_be_deleted") &&
|
|
adminUser.get("can_delete_all_posts"),
|
|
};
|
|
}
|
|
|
|
@action
|
|
async showControlModal(type, user, opts) {
|
|
opts = opts || {};
|
|
const loadedUser = user.adminUserView
|
|
? user
|
|
: await AdminUser.find(user.get("id"));
|
|
this.modal.show(PenalizeUserModal, {
|
|
model: {
|
|
penaltyType: type,
|
|
postId: opts.postId,
|
|
postEdit: opts.postEdit,
|
|
user: loadedUser,
|
|
before: opts.before,
|
|
successCallback: opts.successCallback,
|
|
},
|
|
});
|
|
}
|
|
|
|
showSilenceModal(user, opts) {
|
|
this.showControlModal("silence", user, opts);
|
|
}
|
|
|
|
showSuspendModal(user, opts) {
|
|
this.showControlModal("suspend", user, opts);
|
|
}
|
|
|
|
_deleteSpammer(adminUser) {
|
|
// Try loading the email if the site supports it
|
|
let tryEmail = this.siteSettings.moderators_view_emails
|
|
? adminUser.checkEmail()
|
|
: Promise.resolve();
|
|
|
|
return tryEmail.then(() => {
|
|
let message = htmlSafe(
|
|
I18n.messageFormat("flagging.delete_confirm_MF", {
|
|
POSTS: adminUser.get("post_count"),
|
|
TOPICS: adminUser.get("topic_count"),
|
|
email:
|
|
adminUser.get("email") || I18n.t("flagging.hidden_email_address"),
|
|
ip_address:
|
|
adminUser.get("ip_address") ||
|
|
I18n.t("flagging.ip_address_missing"),
|
|
})
|
|
);
|
|
|
|
let userId = adminUser.get("id");
|
|
|
|
return new Promise((resolve, reject) => {
|
|
this.dialog.deleteConfirm({
|
|
message,
|
|
class: "flagging-delete-spammer",
|
|
confirmButtonLabel: "flagging.yes_delete_spammer",
|
|
confirmButtonIcon: "exclamation-triangle",
|
|
didConfirm: () => {
|
|
return ajax(`/admin/users/${userId}.json`, {
|
|
type: "DELETE",
|
|
data: {
|
|
delete_posts: true,
|
|
block_email: true,
|
|
block_urls: true,
|
|
block_ip: true,
|
|
delete_as_spammer: true,
|
|
context: window.location.pathname,
|
|
},
|
|
})
|
|
.then((result) => {
|
|
if (result.deleted) {
|
|
resolve();
|
|
} else {
|
|
throw new Error("failed to delete");
|
|
}
|
|
})
|
|
.catch(() => {
|
|
this.dialog.alert(I18n.t("admin.user.delete_failed"));
|
|
reject();
|
|
});
|
|
},
|
|
});
|
|
});
|
|
});
|
|
}
|
|
}
|