2017-09-12 13:04:53 -04:00
|
|
|
// 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!
|
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
import AdminUser from "admin/models/admin-user";
|
|
|
|
import { iconHTML } from "discourse-common/lib/icon-library";
|
|
|
|
import { ajax } from "discourse/lib/ajax";
|
|
|
|
import showModal from "discourse/lib/show-modal";
|
|
|
|
import { getOwner } from "discourse-common/lib/get-owner";
|
2017-09-12 13:04:53 -04:00
|
|
|
|
|
|
|
export default Ember.Service.extend({
|
2017-11-15 10:46:09 -05:00
|
|
|
init() {
|
|
|
|
this._super();
|
|
|
|
|
|
|
|
// TODO: Make `siteSettings` a service that can be injected
|
2018-06-15 11:03:24 -04:00
|
|
|
this.siteSettings = getOwner(this).lookup("site-settings:main");
|
2017-11-15 10:46:09 -05:00
|
|
|
},
|
|
|
|
|
2018-01-26 15:40:03 -05:00
|
|
|
showActionLogs(target, filters) {
|
2018-06-15 11:03:24 -04:00
|
|
|
const controller = getOwner(target).lookup(
|
|
|
|
"controller:adminLogs.staffActionLogs"
|
|
|
|
);
|
|
|
|
target.transitionToRoute("adminLogs.staffActionLogs").then(() => {
|
|
|
|
controller.set("filters", Ember.Object.create());
|
2018-01-26 15:40:03 -05:00
|
|
|
controller._changeFilters(filters);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2018-01-17 13:03:14 -05:00
|
|
|
showFlagsReceived(user) {
|
|
|
|
showModal(`admin-flags-received`, { admin: true, model: user });
|
|
|
|
},
|
|
|
|
|
2017-09-12 13:04:53 -04:00
|
|
|
checkSpammer(userId) {
|
|
|
|
return AdminUser.find(userId).then(au => this.spammerDetails(au));
|
|
|
|
},
|
|
|
|
|
2018-01-26 15:40:03 -05:00
|
|
|
deleteUser(id) {
|
|
|
|
AdminUser.find(id).then(user => user.destroy({ deletePosts: true }));
|
|
|
|
},
|
|
|
|
|
2017-09-12 13:04:53 -04:00
|
|
|
spammerDetails(adminUser) {
|
|
|
|
return {
|
|
|
|
deleteUser: () => this._deleteSpammer(adminUser),
|
2018-06-15 11:03:24 -04:00
|
|
|
canDelete:
|
|
|
|
adminUser.get("can_be_deleted") && adminUser.get("can_delete_all_posts")
|
2017-09-12 13:04:53 -04:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2017-11-13 13:41:36 -05:00
|
|
|
_showControlModal(type, user, opts) {
|
2017-09-14 14:10:39 -04:00
|
|
|
opts = opts || {};
|
|
|
|
|
2017-11-13 13:41:36 -05:00
|
|
|
let controller = showModal(`admin-${type}-user`, {
|
2017-09-12 17:07:42 -04:00
|
|
|
admin: true,
|
2017-11-13 13:41:36 -05:00
|
|
|
modalClass: `${type}-user-modal`
|
2017-09-12 17:07:42 -04:00
|
|
|
});
|
2017-09-14 14:10:39 -04:00
|
|
|
if (opts.post) {
|
2018-01-30 16:31:29 -05:00
|
|
|
controller.setProperties({
|
|
|
|
post: opts.post,
|
2018-06-15 11:03:24 -04:00
|
|
|
postEdit: opts.post.get("raw")
|
2018-01-30 16:31:29 -05:00
|
|
|
});
|
2017-09-14 14:10:39 -04:00
|
|
|
}
|
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
return (user.adminUserView
|
|
|
|
? Ember.RSVP.resolve(user)
|
|
|
|
: AdminUser.find(user.get("id"))
|
2018-01-10 14:48:11 -05:00
|
|
|
).then(loadedUser => {
|
2017-09-14 14:10:39 -04:00
|
|
|
controller.setProperties({
|
|
|
|
user: loadedUser,
|
|
|
|
loadingUser: false,
|
2018-01-30 16:31:29 -05:00
|
|
|
before: opts.before,
|
2017-09-14 14:10:39 -04:00
|
|
|
successCallback: opts.successCallback
|
|
|
|
});
|
|
|
|
});
|
2017-09-12 17:07:42 -04:00
|
|
|
},
|
|
|
|
|
2017-11-13 13:41:36 -05:00
|
|
|
showSilenceModal(user, opts) {
|
2018-06-15 11:03:24 -04:00
|
|
|
this._showControlModal("silence", user, opts);
|
2017-11-13 13:41:36 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
showSuspendModal(user, opts) {
|
2018-06-15 11:03:24 -04:00
|
|
|
this._showControlModal("suspend", user, opts);
|
2017-11-13 13:41:36 -05:00
|
|
|
},
|
|
|
|
|
2017-12-04 12:14:43 -05:00
|
|
|
showModerationHistory(target) {
|
2018-06-15 11:03:24 -04:00
|
|
|
let controller = showModal("admin-moderation-history", { admin: true });
|
2017-12-04 12:14:43 -05:00
|
|
|
controller.loadHistory(target);
|
|
|
|
},
|
|
|
|
|
2017-09-12 13:04:53 -04:00
|
|
|
_deleteSpammer(adminUser) {
|
2017-11-15 10:46:09 -05:00
|
|
|
// Try loading the email if the site supports it
|
2018-06-15 11:03:24 -04:00
|
|
|
let tryEmail = this.siteSettings.show_email_on_profile
|
|
|
|
? adminUser.checkEmail()
|
|
|
|
: Ember.RSVP.resolve();
|
2017-11-15 10:46:09 -05:00
|
|
|
|
|
|
|
return tryEmail.then(() => {
|
2018-06-15 11:03:24 -04:00
|
|
|
let message = 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")
|
2017-09-12 13:04:53 -04:00
|
|
|
});
|
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
let userId = adminUser.get("id");
|
2017-09-12 13:04:53 -04:00
|
|
|
|
|
|
|
return new Ember.RSVP.Promise((resolve, reject) => {
|
|
|
|
const buttons = [
|
|
|
|
{
|
|
|
|
label: I18n.t("composer.cancel"),
|
2017-09-13 13:23:19 -04:00
|
|
|
class: "d-modal-cancel",
|
2018-06-15 11:03:24 -04:00
|
|
|
link: true
|
2017-09-12 13:04:53 -04:00
|
|
|
},
|
|
|
|
{
|
2018-06-15 11:03:24 -04:00
|
|
|
label:
|
|
|
|
`${iconHTML("exclamation-triangle")} ` +
|
|
|
|
I18n.t("flagging.yes_delete_spammer"),
|
2017-09-12 13:04:53 -04:00
|
|
|
class: "btn btn-danger confirm-delete",
|
|
|
|
callback() {
|
|
|
|
return ajax(`/admin/users/${userId}.json`, {
|
2018-06-15 11:03:24 -04:00
|
|
|
type: "DELETE",
|
2017-09-12 13:04:53 -04:00
|
|
|
data: {
|
|
|
|
delete_posts: true,
|
|
|
|
block_email: true,
|
|
|
|
block_urls: true,
|
|
|
|
block_ip: true,
|
|
|
|
delete_as_spammer: true,
|
|
|
|
context: window.location.pathname
|
|
|
|
}
|
2018-06-15 11:03:24 -04:00
|
|
|
})
|
|
|
|
.then(result => {
|
|
|
|
if (result.deleted) {
|
|
|
|
resolve();
|
|
|
|
} else {
|
|
|
|
throw new Error("failed to delete");
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
bootbox.alert(I18n.t("admin.user.delete_failed"));
|
|
|
|
reject();
|
|
|
|
});
|
2017-09-12 13:04:53 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
bootbox.dialog(message, buttons, {
|
|
|
|
classes: "flagging-delete-spammer"
|
|
|
|
});
|
2017-09-12 13:04:53 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|