2020-06-03 12:45:26 -04:00
|
|
|
import getURL from "discourse-common/lib/get-url";
|
2020-05-13 16:23:41 -04:00
|
|
|
import I18n from "I18n";
|
2019-11-07 16:38:28 -05:00
|
|
|
import discourseComputed from "discourse-common/utils/decorators";
|
2019-10-30 16:28:29 -04:00
|
|
|
import { filter, or, gt, lt, not } from "@ember/object/computed";
|
2017-07-26 16:33:17 -04:00
|
|
|
import { iconHTML } from "discourse-common/lib/icon-library";
|
2016-06-30 13:55:44 -04:00
|
|
|
import { ajax } from "discourse/lib/ajax";
|
2015-08-07 15:08:27 -04:00
|
|
|
import { propertyNotEqual } from "discourse/lib/computed";
|
2015-05-19 10:56:32 -04:00
|
|
|
import { popupAjaxError } from "discourse/lib/ajax-error";
|
2015-11-20 20:27:06 -05:00
|
|
|
import Group from "discourse/models/group";
|
2020-04-30 11:29:33 -04:00
|
|
|
import DiscourseURL, { userPath } from "discourse/lib/url";
|
2019-11-05 11:37:32 -05:00
|
|
|
import { Promise } from "rsvp";
|
2019-11-12 11:38:51 -05:00
|
|
|
import User from "discourse/models/user";
|
2015-05-19 10:56:32 -04:00
|
|
|
|
2017-11-13 13:41:36 -05:00
|
|
|
const wrapAdmin = user => (user ? AdminUser.create(user) : null);
|
|
|
|
|
2019-11-12 11:38:51 -05:00
|
|
|
const AdminUser = User.extend({
|
2017-09-14 14:10:39 -04:00
|
|
|
adminUserView: true,
|
2019-10-30 19:18:29 -04:00
|
|
|
customGroups: filter("groups", g => !g.automatic && Group.create(g)),
|
|
|
|
automaticGroups: filter("groups", g => g.automatic && Group.create(g)),
|
2015-03-17 17:59:05 -04:00
|
|
|
|
2019-10-30 16:28:29 -04:00
|
|
|
canViewProfile: or("active", "staged"),
|
2016-01-19 10:41:07 -05:00
|
|
|
|
2019-11-07 16:38:28 -05:00
|
|
|
@discourseComputed("bounce_score", "reset_bounce_score_after")
|
2016-05-06 13:34:33 -04:00
|
|
|
bounceScore(bounce_score, reset_bounce_score_after) {
|
|
|
|
if (bounce_score > 0) {
|
|
|
|
return `${bounce_score} - ${moment(reset_bounce_score_after).format(
|
|
|
|
"LL"
|
|
|
|
)}`;
|
|
|
|
} else {
|
|
|
|
return bounce_score;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2019-11-07 16:38:28 -05:00
|
|
|
@discourseComputed("bounce_score")
|
2016-05-06 13:34:33 -04:00
|
|
|
bounceScoreExplanation(bounce_score) {
|
|
|
|
if (bounce_score === 0) {
|
|
|
|
return I18n.t("admin.user.bounce_score_explanation.none");
|
2020-07-14 12:31:03 -04:00
|
|
|
} else if (bounce_score < this.siteSettings.bounce_score_threshold) {
|
2016-05-06 13:34:33 -04:00
|
|
|
return I18n.t("admin.user.bounce_score_explanation.some");
|
|
|
|
} else {
|
|
|
|
return I18n.t("admin.user.bounce_score_explanation.threshold_reached");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2019-11-07 16:38:28 -05:00
|
|
|
@discourseComputed
|
2016-05-18 16:38:35 -04:00
|
|
|
bounceLink() {
|
2020-06-03 12:45:26 -04:00
|
|
|
return getURL("/admin/email/bounced");
|
2016-05-18 16:38:35 -04:00
|
|
|
},
|
|
|
|
|
2019-10-30 16:28:29 -04:00
|
|
|
canResetBounceScore: gt("bounce_score", 0),
|
2016-05-06 13:34:33 -04:00
|
|
|
|
|
|
|
resetBounceScore() {
|
2019-05-07 04:53:21 -04:00
|
|
|
return ajax(`/admin/users/${this.id}/reset_bounce_score`, {
|
2016-05-06 13:34:33 -04:00
|
|
|
type: "POST"
|
|
|
|
}).then(() =>
|
|
|
|
this.setProperties({
|
|
|
|
bounce_score: 0,
|
|
|
|
reset_bounce_score_after: null
|
|
|
|
})
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
groupAdded(added) {
|
2019-05-07 04:53:21 -04:00
|
|
|
return ajax(`/admin/users/${this.id}/groups`, {
|
2014-07-15 10:11:39 -04:00
|
|
|
type: "POST",
|
2015-03-17 17:59:05 -04:00
|
|
|
data: { group_id: added.id }
|
2019-05-27 04:15:39 -04:00
|
|
|
}).then(() => this.groups.pushObject(added));
|
2014-07-15 10:11:39 -04:00
|
|
|
},
|
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
groupRemoved(groupId) {
|
2019-05-07 04:53:21 -04:00
|
|
|
return ajax(`/admin/users/${this.id}/groups/${groupId}`, {
|
2014-07-15 10:11:39 -04:00
|
|
|
type: "DELETE"
|
2017-05-17 12:42:04 -04:00
|
|
|
}).then(() => {
|
2019-05-27 04:15:39 -04:00
|
|
|
this.set("groups.[]", this.groups.rejectBy("id", groupId));
|
|
|
|
if (this.primary_group_id === groupId) {
|
2017-05-17 12:42:04 -04:00
|
|
|
this.set("primary_group_id", null);
|
|
|
|
}
|
|
|
|
});
|
2014-07-15 10:11:39 -04:00
|
|
|
},
|
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
deleteAllPosts() {
|
2018-12-14 05:04:18 -05:00
|
|
|
let deletedPosts = 0;
|
2019-05-07 04:53:21 -04:00
|
|
|
const user = this;
|
|
|
|
const message = I18n.messageFormat(
|
|
|
|
"admin.user.delete_all_posts_confirm_MF",
|
|
|
|
{
|
2016-08-10 13:24:28 -04:00
|
|
|
POSTS: user.get("post_count"),
|
|
|
|
TOPICS: user.get("topic_count")
|
2019-05-07 04:53:21 -04:00
|
|
|
}
|
|
|
|
);
|
|
|
|
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}%`
|
|
|
|
});
|
2018-12-14 05:04:18 -05:00
|
|
|
performDelete();
|
2015-03-17 17:59:05 -04:00
|
|
|
}
|
2018-12-14 05:04:18 -05:00
|
|
|
})
|
2019-05-07 04:53:21 -04:00
|
|
|
.catch(e => {
|
|
|
|
bootbox.hideAll();
|
|
|
|
let error;
|
|
|
|
AdminUser.find(user.get("id")).then(u => user.setProperties(u));
|
|
|
|
if (e.responseJSON && e.responseJSON.errors) {
|
|
|
|
error = e.responseJSON.errors[0];
|
|
|
|
}
|
|
|
|
error = error || I18n.t("admin.user.delete_posts_failed");
|
|
|
|
bootbox.alert(error);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
bootbox.dialog(message, buttons, { classes: "delete-all-posts" });
|
2013-02-22 15:41:12 -05:00
|
|
|
},
|
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
revokeAdmin() {
|
2019-05-07 04:53:21 -04:00
|
|
|
return ajax(`/admin/users/${this.id}/revoke_admin`, {
|
2015-03-17 17:59:05 -04:00
|
|
|
type: "PUT"
|
2017-04-04 13:59:22 -04:00
|
|
|
}).then(() => {
|
|
|
|
this.setProperties({
|
2015-03-17 17:59:05 -04:00
|
|
|
admin: false,
|
|
|
|
can_grant_admin: true,
|
|
|
|
can_revoke_admin: false
|
|
|
|
});
|
|
|
|
});
|
2013-02-22 15:41:12 -05:00
|
|
|
},
|
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
grantAdmin() {
|
2019-05-07 04:53:21 -04:00
|
|
|
return ajax(`/admin/users/${this.id}/grant_admin`, {
|
2015-03-17 17:59:05 -04:00
|
|
|
type: "PUT"
|
2017-04-04 13:59:22 -04:00
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
bootbox.alert(I18n.t("admin.user.grant_admin_confirm"));
|
2015-05-19 10:56:32 -04:00
|
|
|
})
|
|
|
|
.catch(popupAjaxError);
|
2013-02-22 15:41:12 -05:00
|
|
|
},
|
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
revokeModeration() {
|
2019-05-07 04:53:21 -04:00
|
|
|
return ajax(`/admin/users/${this.id}/revoke_moderation`, {
|
2015-03-17 17:59:05 -04:00
|
|
|
type: "PUT"
|
|
|
|
})
|
2019-05-07 04:53:21 -04:00
|
|
|
.then(() => {
|
|
|
|
this.setProperties({
|
2015-03-17 17:59:05 -04:00
|
|
|
moderator: false,
|
|
|
|
can_grant_moderation: true,
|
|
|
|
can_revoke_moderation: false
|
|
|
|
});
|
2015-05-19 10:56:32 -04:00
|
|
|
})
|
|
|
|
.catch(popupAjaxError);
|
2013-02-22 15:41:12 -05:00
|
|
|
},
|
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
grantModeration() {
|
2019-05-07 04:53:21 -04:00
|
|
|
return ajax(`/admin/users/${this.id}/grant_moderation`, {
|
2015-03-17 17:59:05 -04:00
|
|
|
type: "PUT"
|
|
|
|
})
|
2019-05-07 04:53:21 -04:00
|
|
|
.then(() => {
|
|
|
|
this.setProperties({
|
2015-03-17 17:59:05 -04:00
|
|
|
moderator: true,
|
|
|
|
can_grant_moderation: false,
|
|
|
|
can_revoke_moderation: true
|
|
|
|
});
|
2015-05-19 10:56:32 -04:00
|
|
|
})
|
|
|
|
.catch(popupAjaxError);
|
2013-02-22 15:41:12 -05:00
|
|
|
},
|
|
|
|
|
2017-12-21 20:18:12 -05:00
|
|
|
disableSecondFactor() {
|
2019-05-07 04:53:21 -04:00
|
|
|
return ajax(`/admin/users/${this.id}/disable_second_factor`, {
|
2017-12-21 20:18:12 -05:00
|
|
|
type: "PUT"
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
this.set("second_factor_enabled", false);
|
|
|
|
})
|
|
|
|
.catch(popupAjaxError);
|
|
|
|
},
|
|
|
|
|
2019-07-26 05:20:11 -04:00
|
|
|
approve(approvedBy) {
|
2019-05-07 04:53:21 -04:00
|
|
|
return ajax(`/admin/users/${this.id}/approve`, {
|
2015-03-17 17:59:05 -04:00
|
|
|
type: "PUT"
|
2019-05-07 04:53:21 -04:00
|
|
|
}).then(() => {
|
|
|
|
this.setProperties({
|
2015-03-17 17:59:05 -04:00
|
|
|
can_approve: false,
|
|
|
|
approved: true,
|
2019-07-26 05:20:11 -04:00
|
|
|
approved_by: approvedBy
|
2015-03-17 17:59:05 -04:00
|
|
|
});
|
|
|
|
});
|
2013-02-22 15:41:12 -05:00
|
|
|
},
|
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
setOriginalTrustLevel() {
|
2019-05-27 04:15:39 -04:00
|
|
|
this.set("originalTrustLevel", this.trust_level);
|
2013-07-04 07:01:01 -04:00
|
|
|
},
|
|
|
|
|
2019-10-03 08:52:07 -04:00
|
|
|
dirty: propertyNotEqual("originalTrustLevel", "trust_level"),
|
2013-07-01 10:22:21 -04:00
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
saveTrustLevel() {
|
2019-05-07 04:53:21 -04:00
|
|
|
return ajax(`/admin/users/${this.id}/trust_level`, {
|
2013-07-01 10:22:21 -04:00
|
|
|
type: "PUT",
|
2019-10-03 08:52:07 -04:00
|
|
|
data: { level: this.trust_level }
|
2015-03-17 17:59:05 -04:00
|
|
|
})
|
2019-05-07 04:53:21 -04:00
|
|
|
.then(() => window.location.reload())
|
|
|
|
.catch(e => {
|
2015-03-17 17:59:05 -04:00
|
|
|
let error;
|
2014-07-29 15:54:20 -04:00
|
|
|
if (e.responseJSON && e.responseJSON.errors) {
|
|
|
|
error = e.responseJSON.errors[0];
|
|
|
|
}
|
|
|
|
error =
|
|
|
|
error ||
|
|
|
|
I18n.t("admin.user.trust_level_change_failed", {
|
2019-05-07 04:53:21 -04:00
|
|
|
error: this._formatError(e)
|
2014-07-29 15:54:20 -04:00
|
|
|
});
|
2013-07-01 10:22:21 -04:00
|
|
|
bootbox.alert(error);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
restoreTrustLevel() {
|
2019-10-03 08:52:07 -04:00
|
|
|
this.set("trust_level", this.originalTrustLevel);
|
2013-07-01 10:22:21 -04:00
|
|
|
},
|
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
lockTrustLevel(locked) {
|
2019-05-07 04:53:21 -04:00
|
|
|
return ajax(`/admin/users/${this.id}/trust_level_lock`, {
|
2014-09-13 16:55:26 -04:00
|
|
|
type: "PUT",
|
|
|
|
data: { locked: !!locked }
|
|
|
|
})
|
2019-05-07 04:53:21 -04:00
|
|
|
.then(() => window.location.reload())
|
|
|
|
.catch(e => {
|
2015-03-17 17:59:05 -04:00
|
|
|
let error;
|
2014-09-13 16:55:26 -04:00
|
|
|
if (e.responseJSON && e.responseJSON.errors) {
|
|
|
|
error = e.responseJSON.errors[0];
|
|
|
|
}
|
|
|
|
error =
|
|
|
|
error ||
|
|
|
|
I18n.t("admin.user.trust_level_change_failed", {
|
2019-05-07 04:53:21 -04:00
|
|
|
error: this._formatError(e)
|
2014-09-13 16:55:26 -04:00
|
|
|
});
|
|
|
|
bootbox.alert(error);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2019-10-30 16:28:29 -04:00
|
|
|
canLockTrustLevel: lt("trust_level", 4),
|
2014-09-29 23:12:33 -04:00
|
|
|
|
2019-10-30 16:28:29 -04:00
|
|
|
canSuspend: not("staff"),
|
2013-03-20 20:25:41 -04:00
|
|
|
|
2019-11-07 16:38:28 -05:00
|
|
|
@discourseComputed("suspended_till", "suspended_at")
|
2019-04-26 06:16:21 -04:00
|
|
|
suspendDuration(suspendedTill, suspendedAt) {
|
|
|
|
suspendedAt = moment(suspendedAt);
|
|
|
|
suspendedTill = moment(suspendedTill);
|
|
|
|
return suspendedAt.format("L") + " - " + suspendedTill.format("L");
|
|
|
|
},
|
2013-02-22 15:41:12 -05:00
|
|
|
|
2017-09-13 14:11:33 -04:00
|
|
|
suspend(data) {
|
|
|
|
return ajax(`/admin/users/${this.id}/suspend`, {
|
2013-11-01 10:47:03 -04:00
|
|
|
type: "PUT",
|
2017-09-13 14:11:33 -04:00
|
|
|
data
|
2017-09-13 14:43:36 -04:00
|
|
|
}).then(result => this.setProperties(result.suspension));
|
2013-02-22 15:41:12 -05:00
|
|
|
},
|
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
unsuspend() {
|
2017-09-13 14:11:33 -04:00
|
|
|
return ajax(`/admin/users/${this.id}/unsuspend`, {
|
2013-04-03 16:06:55 -04:00
|
|
|
type: "PUT"
|
2017-09-13 14:43:36 -04:00
|
|
|
}).then(result => this.setProperties(result.suspension));
|
2013-02-22 15:41:12 -05:00
|
|
|
},
|
|
|
|
|
2016-12-20 06:26:53 -05:00
|
|
|
logOut() {
|
2016-06-30 13:55:44 -04:00
|
|
|
return ajax("/admin/users/" + this.id + "/log_out", {
|
2014-06-05 23:02:52 -04:00
|
|
|
type: "POST",
|
2019-05-27 04:15:39 -04:00
|
|
|
data: { username_or_email: this.username }
|
2019-05-07 04:53:21 -04:00
|
|
|
}).then(() => bootbox.alert(I18n.t("admin.user.logged_out")));
|
2014-06-05 23:02:52 -04:00
|
|
|
},
|
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
impersonate() {
|
2016-06-30 13:55:44 -04:00
|
|
|
return ajax("/admin/impersonate", {
|
2013-02-22 15:41:12 -05:00
|
|
|
type: "POST",
|
2019-05-27 04:15:39 -04:00
|
|
|
data: { username_or_email: this.username }
|
2013-04-03 16:06:55 -04:00
|
|
|
})
|
2020-06-03 12:45:26 -04:00
|
|
|
.then(() => (document.location = getURL("/")))
|
2019-05-07 04:53:21 -04:00
|
|
|
.catch(e => {
|
2013-04-03 16:06:55 -04:00
|
|
|
if (e.status === 404) {
|
2013-07-08 19:32:16 -04:00
|
|
|
bootbox.alert(I18n.t("admin.impersonate.not_found"));
|
2013-04-03 16:06:55 -04:00
|
|
|
} else {
|
2013-07-08 19:32:16 -04:00
|
|
|
bootbox.alert(I18n.t("admin.impersonate.invalid"));
|
2013-02-22 15:41:12 -05:00
|
|
|
}
|
|
|
|
});
|
2013-04-11 16:04:20 -04:00
|
|
|
},
|
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
activate() {
|
2019-05-07 04:53:21 -04:00
|
|
|
return ajax(`/admin/users/${this.id}/activate`, {
|
2015-03-17 17:59:05 -04:00
|
|
|
type: "PUT"
|
|
|
|
})
|
2019-05-07 04:53:21 -04:00
|
|
|
.then(() => window.location.reload())
|
|
|
|
.catch(e => {
|
|
|
|
const error = I18n.t("admin.user.activate_failed", {
|
|
|
|
error: this._formatError(e)
|
2013-07-08 19:32:16 -04:00
|
|
|
});
|
2013-05-07 21:58:34 -04:00
|
|
|
bootbox.alert(error);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
deactivate() {
|
2019-05-07 04:53:21 -04:00
|
|
|
return ajax(`/admin/users/${this.id}/deactivate`, {
|
2018-05-07 22:44:49 -04:00
|
|
|
type: "PUT",
|
|
|
|
data: { context: document.location.pathname }
|
2015-03-17 17:59:05 -04:00
|
|
|
})
|
2019-05-07 04:53:21 -04:00
|
|
|
.then(() => window.location.reload())
|
|
|
|
.catch(e => {
|
|
|
|
const error = I18n.t("admin.user.deactivate_failed", {
|
|
|
|
error: this._formatError(e)
|
2013-07-08 19:32:16 -04:00
|
|
|
});
|
2013-05-07 21:58:34 -04:00
|
|
|
bootbox.alert(error);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2017-11-10 12:18:08 -05:00
|
|
|
unsilence() {
|
|
|
|
this.set("silencingUser", true);
|
2017-11-13 13:41:36 -05:00
|
|
|
|
|
|
|
return ajax(`/admin/users/${this.id}/unsilence`, {
|
2015-03-17 17:59:05 -04:00
|
|
|
type: "PUT"
|
2017-11-13 13:41:36 -05:00
|
|
|
})
|
2019-05-07 04:53:21 -04:00
|
|
|
.then(result => this.setProperties(result.unsilence))
|
2017-11-13 13:41:36 -05:00
|
|
|
.catch(e => {
|
2019-05-07 04:53:21 -04:00
|
|
|
const error = I18n.t("admin.user.unsilence_failed", {
|
|
|
|
error: this._formatError(e)
|
2018-06-15 11:03:24 -04:00
|
|
|
});
|
2017-11-13 13:41:36 -05:00
|
|
|
bootbox.alert(error);
|
2018-06-15 11:03:24 -04:00
|
|
|
})
|
2019-05-07 04:53:21 -04:00
|
|
|
.finally(() => this.set("silencingUser", false));
|
2013-05-31 11:41:40 -04:00
|
|
|
},
|
|
|
|
|
2017-11-13 13:41:36 -05:00
|
|
|
silence(data) {
|
|
|
|
this.set("silencingUser", true);
|
|
|
|
return ajax(`/admin/users/${this.id}/silence`, {
|
|
|
|
type: "PUT",
|
|
|
|
data
|
|
|
|
})
|
2019-05-07 04:53:21 -04:00
|
|
|
.then(result => this.setProperties(result.silence))
|
2017-11-13 13:41:36 -05:00
|
|
|
.catch(e => {
|
2019-05-07 04:53:21 -04:00
|
|
|
const error = I18n.t("admin.user.silence_failed", {
|
|
|
|
error: this._formatError(e)
|
2018-06-15 11:03:24 -04:00
|
|
|
});
|
2017-11-13 13:41:36 -05:00
|
|
|
bootbox.alert(error);
|
2018-06-15 11:03:24 -04:00
|
|
|
})
|
2019-05-07 04:53:21 -04:00
|
|
|
.finally(() => this.set("silencingUser", false));
|
2013-05-31 11:41:40 -04:00
|
|
|
},
|
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
sendActivationEmail() {
|
2017-03-28 14:27:54 -04:00
|
|
|
return ajax(userPath("action/send_activation_email"), {
|
2015-03-17 17:59:05 -04:00
|
|
|
type: "POST",
|
2019-05-27 04:15:39 -04:00
|
|
|
data: { username: this.username }
|
2015-03-17 17:59:05 -04:00
|
|
|
})
|
2019-05-07 04:53:21 -04:00
|
|
|
.then(() => bootbox.alert(I18n.t("admin.user.activation_email_sent")))
|
2015-10-27 16:25:30 -04:00
|
|
|
.catch(popupAjaxError);
|
2013-05-07 21:58:34 -04:00
|
|
|
},
|
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
anonymize() {
|
2019-05-07 04:53:21 -04:00
|
|
|
const user = this;
|
|
|
|
const message = I18n.t("admin.user.anonymize_confirm");
|
2015-03-06 16:44:54 -05:00
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
const performAnonymize = function() {
|
2019-05-07 04:53:21 -04:00
|
|
|
return ajax(`/admin/users/${user.get("id")}/anonymize.json`, {
|
2015-03-17 17:59:05 -04:00
|
|
|
type: "PUT"
|
|
|
|
})
|
|
|
|
.then(function(data) {
|
2015-03-06 16:44:54 -05:00
|
|
|
if (data.success) {
|
|
|
|
if (data.username) {
|
2020-06-03 12:45:26 -04:00
|
|
|
document.location = getURL(
|
2019-05-07 04:53:21 -04:00
|
|
|
`/admin/users/${user.get("id")}/${data.username}`
|
2018-06-15 11:03:24 -04:00
|
|
|
);
|
|
|
|
} else {
|
2020-06-03 12:45:26 -04:00
|
|
|
document.location = getURL("/admin/users/list/active");
|
2018-06-15 11:03:24 -04:00
|
|
|
}
|
2015-03-06 16:44:54 -05:00
|
|
|
} else {
|
2015-05-21 15:02:52 -04:00
|
|
|
bootbox.alert(I18n.t("admin.user.anonymize_failed"));
|
2013-07-25 16:51:24 -04:00
|
|
|
if (data.user) {
|
2015-05-21 15:02:52 -04:00
|
|
|
user.setProperties(data.user);
|
2018-06-15 11:03:24 -04:00
|
|
|
}
|
2015-03-06 16:44:54 -05:00
|
|
|
}
|
|
|
|
})
|
2019-05-07 04:53:21 -04:00
|
|
|
.catch(() => bootbox.alert(I18n.t("admin.user.anonymize_failed")));
|
2015-03-06 16:44:54 -05:00
|
|
|
};
|
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
const buttons = [
|
|
|
|
{
|
2015-03-06 16:44:54 -05:00
|
|
|
label: I18n.t("composer.cancel"),
|
|
|
|
class: "cancel",
|
|
|
|
link: true
|
|
|
|
},
|
|
|
|
{
|
2017-07-26 16:33:17 -04:00
|
|
|
label:
|
|
|
|
`${iconHTML("exclamation-triangle")} ` +
|
|
|
|
I18n.t("admin.user.anonymize_yes"),
|
2015-03-06 16:44:54 -05:00
|
|
|
class: "btn btn-danger",
|
2015-03-17 17:59:05 -04:00
|
|
|
callback: function() {
|
|
|
|
performAnonymize();
|
|
|
|
}
|
2015-03-06 16:44:54 -05:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
bootbox.dialog(message, buttons, { classes: "delete-user-modal" });
|
2015-03-06 16:44:54 -05:00
|
|
|
},
|
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
destroy(opts) {
|
2019-05-07 04:53:21 -04:00
|
|
|
const user = this;
|
|
|
|
const message = I18n.t("admin.user.delete_confirm");
|
|
|
|
const location = document.location.pathname;
|
2013-07-25 16:51:24 -04:00
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
const performDestroy = function(block) {
|
2018-05-03 16:18:19 -04:00
|
|
|
bootbox.dialog(I18n.t("admin.user.deleting_user"));
|
2015-03-17 17:59:05 -04:00
|
|
|
let formData = { context: location };
|
2013-07-25 18:04:51 -04:00
|
|
|
if (block) {
|
|
|
|
formData["block_email"] = true;
|
2013-08-14 11:05:53 -04:00
|
|
|
formData["block_urls"] = true;
|
2013-10-21 14:49:51 -04:00
|
|
|
formData["block_ip"] = true;
|
2013-07-25 18:04:51 -04:00
|
|
|
}
|
2014-11-14 15:23:09 -05:00
|
|
|
if (opts && opts.deletePosts) {
|
|
|
|
formData["delete_posts"] = true;
|
|
|
|
}
|
2019-05-07 04:53:21 -04:00
|
|
|
return ajax(`/admin/users/${user.get("id")}.json`, {
|
2013-07-25 16:51:24 -04:00
|
|
|
type: "DELETE",
|
2013-07-25 18:04:51 -04:00
|
|
|
data: formData
|
2013-07-25 16:51:24 -04:00
|
|
|
})
|
|
|
|
.then(function(data) {
|
|
|
|
if (data.deleted) {
|
2014-12-25 12:25:07 -05:00
|
|
|
if (/^\/admin\/users\/list\//.test(location)) {
|
|
|
|
document.location = location;
|
2018-06-15 11:03:24 -04:00
|
|
|
} else {
|
2020-06-03 12:45:26 -04:00
|
|
|
document.location = getURL("/admin/users/list/active");
|
2018-06-15 11:03:24 -04:00
|
|
|
}
|
2014-12-25 12:25:07 -05:00
|
|
|
} else {
|
2015-05-21 15:02:52 -04:00
|
|
|
bootbox.alert(I18n.t("admin.user.delete_failed"));
|
2013-07-25 16:51:24 -04:00
|
|
|
if (data.user) {
|
2015-05-21 15:02:52 -04:00
|
|
|
user.setProperties(data.user);
|
2018-06-15 11:03:24 -04:00
|
|
|
}
|
2014-12-25 12:25:07 -05:00
|
|
|
}
|
2013-07-25 16:51:24 -04:00
|
|
|
})
|
|
|
|
.catch(function() {
|
|
|
|
AdminUser.find(user.get("id")).then(u => user.setProperties(u));
|
2013-07-08 19:32:16 -04:00
|
|
|
bootbox.alert(I18n.t("admin.user.delete_failed"));
|
2013-07-25 16:51:24 -04:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
const buttons = [
|
|
|
|
{
|
2013-07-25 16:51:24 -04:00
|
|
|
label: I18n.t("composer.cancel"),
|
|
|
|
class: "btn",
|
2015-09-30 19:06:55 -04:00
|
|
|
link: true
|
2013-07-25 16:51:24 -04:00
|
|
|
},
|
|
|
|
{
|
2017-07-26 16:33:17 -04:00
|
|
|
label:
|
|
|
|
`${iconHTML("exclamation-triangle")} ` +
|
|
|
|
I18n.t("admin.user.delete_and_block"),
|
2014-05-04 03:38:29 -04:00
|
|
|
class: "btn btn-danger",
|
2015-03-17 17:59:05 -04:00
|
|
|
callback: function() {
|
|
|
|
performDestroy(true);
|
|
|
|
}
|
2015-09-30 19:06:55 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
label: I18n.t("admin.user.delete_dont_block"),
|
|
|
|
class: "btn btn-primary",
|
|
|
|
callback: function() {
|
|
|
|
performDestroy(false);
|
|
|
|
}
|
2013-07-25 16:51:24 -04:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
bootbox.dialog(message, buttons, { classes: "delete-user-modal" });
|
2013-06-13 13:46:50 -04:00
|
|
|
},
|
|
|
|
|
2020-04-22 04:37:51 -04:00
|
|
|
merge(opts) {
|
|
|
|
const user = this;
|
|
|
|
const location = document.location.pathname;
|
|
|
|
|
|
|
|
bootbox.dialog(I18n.t("admin.user.merging_user"));
|
|
|
|
let formData = { context: location };
|
|
|
|
|
|
|
|
if (opts && opts.targetUsername) {
|
|
|
|
formData["target_username"] = opts.targetUsername;
|
|
|
|
}
|
|
|
|
|
2020-04-30 11:29:33 -04:00
|
|
|
return ajax(`/admin/users/${user.id}/merge.json`, {
|
2020-04-22 04:37:51 -04:00
|
|
|
type: "POST",
|
|
|
|
data: formData
|
|
|
|
})
|
2020-04-30 11:29:33 -04:00
|
|
|
.then(data => {
|
2020-04-22 04:37:51 -04:00
|
|
|
if (data.merged) {
|
|
|
|
if (/^\/admin\/users\/list\//.test(location)) {
|
2020-04-30 11:29:33 -04:00
|
|
|
DiscourseURL.redirectTo(location);
|
2020-04-22 04:37:51 -04:00
|
|
|
} else {
|
2020-04-30 11:29:33 -04:00
|
|
|
DiscourseURL.redirectTo(
|
2020-04-22 04:37:51 -04:00
|
|
|
`/admin/users/${data.user.id}/${data.user.username}`
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
bootbox.alert(I18n.t("admin.user.merge_failed"));
|
|
|
|
if (data.user) {
|
|
|
|
user.setProperties(data.user);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2020-04-30 11:29:33 -04:00
|
|
|
.catch(() => {
|
|
|
|
AdminUser.find(user.id).then(u => user.setProperties(u));
|
2020-04-22 04:37:51 -04:00
|
|
|
bootbox.alert(I18n.t("admin.user.merge_failed"));
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
loadDetails() {
|
2019-05-27 04:15:39 -04:00
|
|
|
if (this.loadedDetails) {
|
2019-11-05 11:37:32 -05:00
|
|
|
return Promise.resolve(this);
|
2015-03-17 17:59:05 -04:00
|
|
|
}
|
2013-06-13 13:46:50 -04:00
|
|
|
|
2019-05-07 04:53:21 -04:00
|
|
|
return AdminUser.find(this.id).then(result => {
|
|
|
|
const userProperties = Object.assign(result, { loadedDetails: true });
|
|
|
|
this.setProperties(userProperties);
|
2013-06-13 13:46:50 -04:00
|
|
|
});
|
2014-01-23 16:40:10 -05:00
|
|
|
},
|
|
|
|
|
2019-11-07 16:38:28 -05:00
|
|
|
@discourseComputed("tl3_requirements")
|
2018-04-24 13:29:15 -04:00
|
|
|
tl3Requirements(requirements) {
|
|
|
|
if (requirements) {
|
|
|
|
return this.store.createRecord("tl3Requirements", requirements);
|
2014-01-23 16:40:10 -05:00
|
|
|
}
|
2018-04-24 13:29:15 -04:00
|
|
|
},
|
2014-03-24 10:19:15 -04:00
|
|
|
|
2019-11-07 16:38:28 -05:00
|
|
|
@discourseComputed("suspended_by")
|
2018-07-30 11:56:48 -04:00
|
|
|
suspendedBy: wrapAdmin,
|
2017-11-13 13:41:36 -05:00
|
|
|
|
2019-11-07 16:38:28 -05:00
|
|
|
@discourseComputed("silenced_by")
|
2018-07-30 11:56:48 -04:00
|
|
|
silencedBy: wrapAdmin,
|
2013-02-22 15:41:12 -05:00
|
|
|
|
2019-11-07 16:38:28 -05:00
|
|
|
@discourseComputed("approved_by")
|
2019-05-07 04:53:21 -04:00
|
|
|
approvedBy: wrapAdmin,
|
|
|
|
|
|
|
|
_formatError(event) {
|
|
|
|
return `http: ${event.status} - ${event.body}`;
|
|
|
|
}
|
2013-02-22 15:41:12 -05:00
|
|
|
});
|
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
AdminUser.reopenClass({
|
2015-09-26 09:56:36 -04:00
|
|
|
find(user_id) {
|
2019-05-07 04:53:21 -04:00
|
|
|
return ajax(`/admin/users/${user_id}.json`).then(result => {
|
2013-06-13 13:46:50 -04:00
|
|
|
result.loadedDetails = true;
|
2015-11-20 20:27:06 -05:00
|
|
|
return AdminUser.create(result);
|
2013-04-11 16:04:20 -04:00
|
|
|
});
|
2013-02-22 15:41:12 -05:00
|
|
|
},
|
|
|
|
|
2019-10-30 16:28:29 -04:00
|
|
|
findAll(query, userFilter) {
|
2019-05-07 04:53:21 -04:00
|
|
|
return ajax(`/admin/users/list/${query}.json`, {
|
2019-10-30 16:28:29 -04:00
|
|
|
data: userFilter
|
2019-05-07 04:53:21 -04:00
|
|
|
}).then(users => users.map(u => AdminUser.create(u)));
|
2013-02-22 15:41:12 -05:00
|
|
|
}
|
|
|
|
});
|
2015-03-17 17:59:05 -04:00
|
|
|
|
|
|
|
export default AdminUser;
|