2019-10-31 04:28:29 +08:00
|
|
|
import { filter, gt, lt, not, or } from "@ember/object/computed";
|
2019-11-06 00:37:32 +08:00
|
|
|
import { Promise } from "rsvp";
|
2016-07-01 01:55:44 +08:00
|
|
|
import { ajax } from "discourse/lib/ajax";
|
2015-05-19 22:56:32 +08:00
|
|
|
import { popupAjaxError } from "discourse/lib/ajax-error";
|
2015-08-08 03:08:27 +08:00
|
|
|
import { propertyNotEqual } from "discourse/lib/computed";
|
2021-01-20 13:04:21 +08:00
|
|
|
import { userPath } from "discourse/lib/url";
|
2023-10-11 02:38:59 +08:00
|
|
|
import Group from "discourse/models/group";
|
|
|
|
import User from "discourse/models/user";
|
|
|
|
import getURL from "discourse-common/lib/get-url";
|
|
|
|
import discourseComputed from "discourse-common/utils/decorators";
|
|
|
|
import I18n from "I18n";
|
2015-05-19 22:56:32 +08:00
|
|
|
|
2023-03-17 18:18:42 +08:00
|
|
|
export default class AdminUser extends User {
|
|
|
|
static find(user_id) {
|
|
|
|
return ajax(`/admin/users/${user_id}.json`).then((result) => {
|
|
|
|
result.loadedDetails = true;
|
|
|
|
return AdminUser.create(result);
|
|
|
|
});
|
|
|
|
}
|
2017-11-14 02:41:36 +08:00
|
|
|
|
2023-03-17 18:18:42 +08:00
|
|
|
static findAll(query, userFilter) {
|
|
|
|
return ajax(`/admin/users/list/${query}.json`, {
|
|
|
|
data: userFilter,
|
|
|
|
}).then((users) => users.map((u) => AdminUser.create(u)));
|
|
|
|
}
|
|
|
|
|
|
|
|
adminUserView = true;
|
2015-03-18 05:59:05 +08:00
|
|
|
|
2023-03-17 18:18:42 +08:00
|
|
|
@filter("groups", (g) => !g.automatic && Group.create(g)) customGroups;
|
|
|
|
@filter("groups", (g) => g.automatic && Group.create(g)) automaticGroups;
|
|
|
|
@or("active", "staged") canViewProfile;
|
|
|
|
@gt("bounce_score", 0) canResetBounceScore;
|
|
|
|
@propertyNotEqual("originalTrustLevel", "trust_level") dirty;
|
|
|
|
@lt("trust_level", 4) canLockTrustLevel;
|
|
|
|
@not("staff") canSuspend;
|
|
|
|
@not("staff") canSilence;
|
2016-01-19 23:41:07 +08:00
|
|
|
|
2019-11-08 05:38:28 +08:00
|
|
|
@discourseComputed("bounce_score", "reset_bounce_score_after")
|
2016-05-07 01:34:33 +08: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;
|
|
|
|
}
|
2023-03-17 18:18:42 +08:00
|
|
|
}
|
2016-05-07 01:34:33 +08:00
|
|
|
|
2019-11-08 05:38:28 +08:00
|
|
|
@discourseComputed("bounce_score")
|
2016-05-07 01:34:33 +08:00
|
|
|
bounceScoreExplanation(bounce_score) {
|
|
|
|
if (bounce_score === 0) {
|
|
|
|
return I18n.t("admin.user.bounce_score_explanation.none");
|
2020-07-15 00:31:03 +08:00
|
|
|
} else if (bounce_score < this.siteSettings.bounce_score_threshold) {
|
2016-05-07 01:34:33 +08:00
|
|
|
return I18n.t("admin.user.bounce_score_explanation.some");
|
|
|
|
} else {
|
|
|
|
return I18n.t("admin.user.bounce_score_explanation.threshold_reached");
|
|
|
|
}
|
2023-03-17 18:18:42 +08:00
|
|
|
}
|
2016-05-07 01:34:33 +08:00
|
|
|
|
2019-11-08 05:38:28 +08:00
|
|
|
@discourseComputed
|
2016-05-19 04:38:35 +08:00
|
|
|
bounceLink() {
|
2020-06-04 00:45:26 +08:00
|
|
|
return getURL("/admin/email/bounced");
|
2023-03-17 18:18:42 +08:00
|
|
|
}
|
2016-05-07 01:34:33 +08:00
|
|
|
|
|
|
|
resetBounceScore() {
|
2023-03-21 22:26:26 +08:00
|
|
|
return ajax(`/admin/users/${this.id}/reset-bounce-score`, {
|
2016-05-07 01:34:33 +08:00
|
|
|
type: "POST",
|
|
|
|
}).then(() =>
|
|
|
|
this.setProperties({
|
|
|
|
bounce_score: 0,
|
|
|
|
reset_bounce_score_after: null,
|
|
|
|
})
|
|
|
|
);
|
2023-03-17 18:18:42 +08:00
|
|
|
}
|
2016-05-07 01:34:33 +08:00
|
|
|
|
2015-03-18 05:59:05 +08:00
|
|
|
groupAdded(added) {
|
2019-05-07 16:53:21 +08:00
|
|
|
return ajax(`/admin/users/${this.id}/groups`, {
|
2014-07-15 22:11:39 +08:00
|
|
|
type: "POST",
|
2015-03-18 05:59:05 +08:00
|
|
|
data: { group_id: added.id },
|
2019-05-27 16:15:39 +08:00
|
|
|
}).then(() => this.groups.pushObject(added));
|
2023-03-17 18:18:42 +08:00
|
|
|
}
|
2014-07-15 22:11:39 +08:00
|
|
|
|
2015-03-18 05:59:05 +08:00
|
|
|
groupRemoved(groupId) {
|
2019-05-07 16:53:21 +08:00
|
|
|
return ajax(`/admin/users/${this.id}/groups/${groupId}`, {
|
2014-07-15 22:11:39 +08:00
|
|
|
type: "DELETE",
|
2017-05-18 00:42:04 +08:00
|
|
|
}).then(() => {
|
2019-05-27 16:15:39 +08:00
|
|
|
this.set("groups.[]", this.groups.rejectBy("id", groupId));
|
|
|
|
if (this.primary_group_id === groupId) {
|
2017-05-18 00:42:04 +08:00
|
|
|
this.set("primary_group_id", null);
|
|
|
|
}
|
|
|
|
});
|
2023-03-17 18:18:42 +08:00
|
|
|
}
|
2014-07-15 22:11:39 +08:00
|
|
|
|
2015-03-18 05:59:05 +08:00
|
|
|
deleteAllPosts() {
|
2021-01-20 13:04:21 +08:00
|
|
|
return ajax(`/admin/users/${this.get("id")}/delete_posts_batch`, {
|
|
|
|
type: "PUT",
|
|
|
|
});
|
2023-03-17 18:18:42 +08:00
|
|
|
}
|
2013-02-23 04:41:12 +08:00
|
|
|
|
2015-03-18 05:59:05 +08:00
|
|
|
revokeAdmin() {
|
2019-05-07 16:53:21 +08:00
|
|
|
return ajax(`/admin/users/${this.id}/revoke_admin`, {
|
2015-03-18 05:59:05 +08:00
|
|
|
type: "PUT",
|
FIX: Revoking admin or moderator status doesn't require refresh to delete/anonymize/merge user (#14073)
* FIX: Revoking admin or moderator status doesn't require refresh to delete/anonymize/merge user
On the /admin/users/<id>/<username> page, there are action buttons that are either visible or hidden depending on a few fields from the AdminDetailsSerializer: `can_be_deleted`, `can_be_anonymized`, `can_be_merged`, `can_delete_all_posts`.
These fields are updated when granting/revoking admin or moderator status. However, those updates were not being reflected on the page. E.g. if a user is granted moderation privileges, the 'anonymize user' and 'merge' buttons still appear on the page, which is inconsistent with the backend state of the user. It requires refreshing the page to update the state.
This commit fixes that issue, by syncing the client model state with the server state when handling a successful response from the server. Now, when revoking privileges, the buttons automatically appear without refreshing the page. Similarly, when granting moderator privileges, the buttons automatically disappear without refreshing the page.
* Add detailed user response to spec for changed routes.
Add tests to verify that the revoke_moderation, grant_moderation, and revoke_admin routes return a response formatted according to the AdminDetailedUserSerializer.
2021-08-19 09:57:16 +08:00
|
|
|
}).then((resp) => {
|
2017-04-05 01:59:22 +08:00
|
|
|
this.setProperties({
|
2015-03-18 05:59:05 +08:00
|
|
|
admin: false,
|
|
|
|
can_grant_admin: true,
|
|
|
|
can_revoke_admin: false,
|
FIX: Revoking admin or moderator status doesn't require refresh to delete/anonymize/merge user (#14073)
* FIX: Revoking admin or moderator status doesn't require refresh to delete/anonymize/merge user
On the /admin/users/<id>/<username> page, there are action buttons that are either visible or hidden depending on a few fields from the AdminDetailsSerializer: `can_be_deleted`, `can_be_anonymized`, `can_be_merged`, `can_delete_all_posts`.
These fields are updated when granting/revoking admin or moderator status. However, those updates were not being reflected on the page. E.g. if a user is granted moderation privileges, the 'anonymize user' and 'merge' buttons still appear on the page, which is inconsistent with the backend state of the user. It requires refreshing the page to update the state.
This commit fixes that issue, by syncing the client model state with the server state when handling a successful response from the server. Now, when revoking privileges, the buttons automatically appear without refreshing the page. Similarly, when granting moderator privileges, the buttons automatically disappear without refreshing the page.
* Add detailed user response to spec for changed routes.
Add tests to verify that the revoke_moderation, grant_moderation, and revoke_admin routes return a response formatted according to the AdminDetailedUserSerializer.
2021-08-19 09:57:16 +08:00
|
|
|
can_be_merged: resp.can_be_merged,
|
|
|
|
can_be_anonymized: resp.can_be_anonymized,
|
|
|
|
can_be_deleted: resp.can_be_deleted,
|
|
|
|
can_delete_all_posts: resp.can_delete_all_posts,
|
2015-03-18 05:59:05 +08:00
|
|
|
});
|
|
|
|
});
|
2023-03-17 18:18:42 +08:00
|
|
|
}
|
2013-02-23 04:41:12 +08:00
|
|
|
|
2021-09-14 20:19:28 +08:00
|
|
|
grantAdmin(data) {
|
2019-05-07 16:53:21 +08:00
|
|
|
return ajax(`/admin/users/${this.id}/grant_admin`, {
|
2015-03-18 05:59:05 +08:00
|
|
|
type: "PUT",
|
2021-09-14 20:19:28 +08:00
|
|
|
data,
|
|
|
|
}).then((resp) => {
|
|
|
|
if (resp.success && !resp.email_confirmation_required) {
|
|
|
|
this.setProperties({
|
|
|
|
admin: true,
|
|
|
|
can_grant_admin: false,
|
|
|
|
can_revoke_admin: true,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return resp;
|
2021-01-20 13:04:21 +08:00
|
|
|
});
|
2023-03-17 18:18:42 +08:00
|
|
|
}
|
2013-02-23 04:41:12 +08:00
|
|
|
|
2015-03-18 05:59:05 +08:00
|
|
|
revokeModeration() {
|
2019-05-07 16:53:21 +08:00
|
|
|
return ajax(`/admin/users/${this.id}/revoke_moderation`, {
|
2015-03-18 05:59:05 +08:00
|
|
|
type: "PUT",
|
|
|
|
})
|
FIX: Revoking admin or moderator status doesn't require refresh to delete/anonymize/merge user (#14073)
* FIX: Revoking admin or moderator status doesn't require refresh to delete/anonymize/merge user
On the /admin/users/<id>/<username> page, there are action buttons that are either visible or hidden depending on a few fields from the AdminDetailsSerializer: `can_be_deleted`, `can_be_anonymized`, `can_be_merged`, `can_delete_all_posts`.
These fields are updated when granting/revoking admin or moderator status. However, those updates were not being reflected on the page. E.g. if a user is granted moderation privileges, the 'anonymize user' and 'merge' buttons still appear on the page, which is inconsistent with the backend state of the user. It requires refreshing the page to update the state.
This commit fixes that issue, by syncing the client model state with the server state when handling a successful response from the server. Now, when revoking privileges, the buttons automatically appear without refreshing the page. Similarly, when granting moderator privileges, the buttons automatically disappear without refreshing the page.
* Add detailed user response to spec for changed routes.
Add tests to verify that the revoke_moderation, grant_moderation, and revoke_admin routes return a response formatted according to the AdminDetailedUserSerializer.
2021-08-19 09:57:16 +08:00
|
|
|
.then((resp) => {
|
2019-05-07 16:53:21 +08:00
|
|
|
this.setProperties({
|
2015-03-18 05:59:05 +08:00
|
|
|
moderator: false,
|
|
|
|
can_grant_moderation: true,
|
|
|
|
can_revoke_moderation: false,
|
FIX: Revoking admin or moderator status doesn't require refresh to delete/anonymize/merge user (#14073)
* FIX: Revoking admin or moderator status doesn't require refresh to delete/anonymize/merge user
On the /admin/users/<id>/<username> page, there are action buttons that are either visible or hidden depending on a few fields from the AdminDetailsSerializer: `can_be_deleted`, `can_be_anonymized`, `can_be_merged`, `can_delete_all_posts`.
These fields are updated when granting/revoking admin or moderator status. However, those updates were not being reflected on the page. E.g. if a user is granted moderation privileges, the 'anonymize user' and 'merge' buttons still appear on the page, which is inconsistent with the backend state of the user. It requires refreshing the page to update the state.
This commit fixes that issue, by syncing the client model state with the server state when handling a successful response from the server. Now, when revoking privileges, the buttons automatically appear without refreshing the page. Similarly, when granting moderator privileges, the buttons automatically disappear without refreshing the page.
* Add detailed user response to spec for changed routes.
Add tests to verify that the revoke_moderation, grant_moderation, and revoke_admin routes return a response formatted according to the AdminDetailedUserSerializer.
2021-08-19 09:57:16 +08:00
|
|
|
can_be_merged: resp.can_be_merged,
|
|
|
|
can_be_anonymized: resp.can_be_anonymized,
|
2015-03-18 05:59:05 +08:00
|
|
|
});
|
2015-05-19 22:56:32 +08:00
|
|
|
})
|
|
|
|
.catch(popupAjaxError);
|
2023-03-17 18:18:42 +08:00
|
|
|
}
|
2013-02-23 04:41:12 +08:00
|
|
|
|
2015-03-18 05:59:05 +08:00
|
|
|
grantModeration() {
|
2019-05-07 16:53:21 +08:00
|
|
|
return ajax(`/admin/users/${this.id}/grant_moderation`, {
|
2015-03-18 05:59:05 +08:00
|
|
|
type: "PUT",
|
|
|
|
})
|
FIX: Revoking admin or moderator status doesn't require refresh to delete/anonymize/merge user (#14073)
* FIX: Revoking admin or moderator status doesn't require refresh to delete/anonymize/merge user
On the /admin/users/<id>/<username> page, there are action buttons that are either visible or hidden depending on a few fields from the AdminDetailsSerializer: `can_be_deleted`, `can_be_anonymized`, `can_be_merged`, `can_delete_all_posts`.
These fields are updated when granting/revoking admin or moderator status. However, those updates were not being reflected on the page. E.g. if a user is granted moderation privileges, the 'anonymize user' and 'merge' buttons still appear on the page, which is inconsistent with the backend state of the user. It requires refreshing the page to update the state.
This commit fixes that issue, by syncing the client model state with the server state when handling a successful response from the server. Now, when revoking privileges, the buttons automatically appear without refreshing the page. Similarly, when granting moderator privileges, the buttons automatically disappear without refreshing the page.
* Add detailed user response to spec for changed routes.
Add tests to verify that the revoke_moderation, grant_moderation, and revoke_admin routes return a response formatted according to the AdminDetailedUserSerializer.
2021-08-19 09:57:16 +08:00
|
|
|
.then((resp) => {
|
2019-05-07 16:53:21 +08:00
|
|
|
this.setProperties({
|
2015-03-18 05:59:05 +08:00
|
|
|
moderator: true,
|
|
|
|
can_grant_moderation: false,
|
|
|
|
can_revoke_moderation: true,
|
FIX: Revoking admin or moderator status doesn't require refresh to delete/anonymize/merge user (#14073)
* FIX: Revoking admin or moderator status doesn't require refresh to delete/anonymize/merge user
On the /admin/users/<id>/<username> page, there are action buttons that are either visible or hidden depending on a few fields from the AdminDetailsSerializer: `can_be_deleted`, `can_be_anonymized`, `can_be_merged`, `can_delete_all_posts`.
These fields are updated when granting/revoking admin or moderator status. However, those updates were not being reflected on the page. E.g. if a user is granted moderation privileges, the 'anonymize user' and 'merge' buttons still appear on the page, which is inconsistent with the backend state of the user. It requires refreshing the page to update the state.
This commit fixes that issue, by syncing the client model state with the server state when handling a successful response from the server. Now, when revoking privileges, the buttons automatically appear without refreshing the page. Similarly, when granting moderator privileges, the buttons automatically disappear without refreshing the page.
* Add detailed user response to spec for changed routes.
Add tests to verify that the revoke_moderation, grant_moderation, and revoke_admin routes return a response formatted according to the AdminDetailedUserSerializer.
2021-08-19 09:57:16 +08:00
|
|
|
can_be_merged: resp.can_be_merged,
|
|
|
|
can_be_anonymized: resp.can_be_anonymized,
|
2015-03-18 05:59:05 +08:00
|
|
|
});
|
2015-05-19 22:56:32 +08:00
|
|
|
})
|
|
|
|
.catch(popupAjaxError);
|
2023-03-17 18:18:42 +08:00
|
|
|
}
|
2013-02-23 04:41:12 +08:00
|
|
|
|
2017-12-22 09:18:12 +08:00
|
|
|
disableSecondFactor() {
|
2019-05-07 16:53:21 +08:00
|
|
|
return ajax(`/admin/users/${this.id}/disable_second_factor`, {
|
2017-12-22 09:18:12 +08:00
|
|
|
type: "PUT",
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
this.set("second_factor_enabled", false);
|
|
|
|
})
|
|
|
|
.catch(popupAjaxError);
|
2023-03-17 18:18:42 +08:00
|
|
|
}
|
2017-12-22 09:18:12 +08:00
|
|
|
|
2019-07-26 17:20:11 +08:00
|
|
|
approve(approvedBy) {
|
2019-05-07 16:53:21 +08:00
|
|
|
return ajax(`/admin/users/${this.id}/approve`, {
|
2015-03-18 05:59:05 +08:00
|
|
|
type: "PUT",
|
2019-05-07 16:53:21 +08:00
|
|
|
}).then(() => {
|
|
|
|
this.setProperties({
|
2015-03-18 05:59:05 +08:00
|
|
|
can_approve: false,
|
|
|
|
approved: true,
|
2019-07-26 17:20:11 +08:00
|
|
|
approved_by: approvedBy,
|
2015-03-18 05:59:05 +08:00
|
|
|
});
|
|
|
|
});
|
2023-03-17 18:18:42 +08:00
|
|
|
}
|
2013-02-23 04:41:12 +08:00
|
|
|
|
2015-03-18 05:59:05 +08:00
|
|
|
setOriginalTrustLevel() {
|
2019-05-27 16:15:39 +08:00
|
|
|
this.set("originalTrustLevel", this.trust_level);
|
2023-03-17 18:18:42 +08:00
|
|
|
}
|
2013-07-01 22:22:21 +08:00
|
|
|
|
2015-03-18 05:59:05 +08:00
|
|
|
saveTrustLevel() {
|
2019-05-07 16:53:21 +08:00
|
|
|
return ajax(`/admin/users/${this.id}/trust_level`, {
|
2013-07-01 22:22:21 +08:00
|
|
|
type: "PUT",
|
2019-10-03 20:52:07 +08:00
|
|
|
data: { level: this.trust_level },
|
2021-01-20 13:04:21 +08:00
|
|
|
});
|
2023-03-17 18:18:42 +08:00
|
|
|
}
|
2013-07-01 22:22:21 +08:00
|
|
|
|
2015-03-18 05:59:05 +08:00
|
|
|
restoreTrustLevel() {
|
2019-10-03 20:52:07 +08:00
|
|
|
this.set("trust_level", this.originalTrustLevel);
|
2023-03-17 18:18:42 +08:00
|
|
|
}
|
2013-07-01 22:22:21 +08:00
|
|
|
|
2015-03-18 05:59:05 +08:00
|
|
|
lockTrustLevel(locked) {
|
2019-05-07 16:53:21 +08:00
|
|
|
return ajax(`/admin/users/${this.id}/trust_level_lock`, {
|
2014-09-14 04:55:26 +08:00
|
|
|
type: "PUT",
|
|
|
|
data: { locked: !!locked },
|
2021-01-20 13:04:21 +08:00
|
|
|
});
|
2023-03-17 18:18:42 +08:00
|
|
|
}
|
2013-03-21 08:25:41 +08:00
|
|
|
|
2019-11-08 05:38:28 +08:00
|
|
|
@discourseComputed("suspended_till", "suspended_at")
|
2019-04-26 18:16:21 +08:00
|
|
|
suspendDuration(suspendedTill, suspendedAt) {
|
|
|
|
suspendedAt = moment(suspendedAt);
|
|
|
|
suspendedTill = moment(suspendedTill);
|
|
|
|
return suspendedAt.format("L") + " - " + suspendedTill.format("L");
|
2023-03-17 18:18:42 +08:00
|
|
|
}
|
2013-02-23 04:41:12 +08:00
|
|
|
|
2017-09-14 02:11:33 +08:00
|
|
|
suspend(data) {
|
|
|
|
return ajax(`/admin/users/${this.id}/suspend`, {
|
2013-11-01 22:47:03 +08:00
|
|
|
type: "PUT",
|
2017-09-14 02:11:33 +08:00
|
|
|
data,
|
2017-09-14 02:43:36 +08:00
|
|
|
}).then((result) => this.setProperties(result.suspension));
|
2023-03-17 18:18:42 +08:00
|
|
|
}
|
2013-02-23 04:41:12 +08:00
|
|
|
|
2015-03-18 05:59:05 +08:00
|
|
|
unsuspend() {
|
2017-09-14 02:11:33 +08:00
|
|
|
return ajax(`/admin/users/${this.id}/unsuspend`, {
|
2013-04-04 04:06:55 +08:00
|
|
|
type: "PUT",
|
2017-09-14 02:43:36 +08:00
|
|
|
}).then((result) => this.setProperties(result.suspension));
|
2023-03-17 18:18:42 +08:00
|
|
|
}
|
2013-02-23 04:41:12 +08:00
|
|
|
|
2016-12-20 19:26:53 +08:00
|
|
|
logOut() {
|
2016-07-01 01:55:44 +08:00
|
|
|
return ajax("/admin/users/" + this.id + "/log_out", {
|
2014-06-06 11:02:52 +08:00
|
|
|
type: "POST",
|
2019-05-27 16:15:39 +08:00
|
|
|
data: { username_or_email: this.username },
|
2021-01-20 13:04:21 +08:00
|
|
|
});
|
2023-03-17 18:18:42 +08:00
|
|
|
}
|
2014-06-06 11:02:52 +08:00
|
|
|
|
2015-03-18 05:59:05 +08:00
|
|
|
impersonate() {
|
2016-07-01 01:55:44 +08:00
|
|
|
return ajax("/admin/impersonate", {
|
2013-02-23 04:41:12 +08:00
|
|
|
type: "POST",
|
2019-05-27 16:15:39 +08:00
|
|
|
data: { username_or_email: this.username },
|
2021-01-20 13:04:21 +08:00
|
|
|
});
|
2023-03-17 18:18:42 +08:00
|
|
|
}
|
2013-04-12 04:04:20 +08:00
|
|
|
|
2015-03-18 05:59:05 +08:00
|
|
|
activate() {
|
2019-05-07 16:53:21 +08:00
|
|
|
return ajax(`/admin/users/${this.id}/activate`, {
|
2015-03-18 05:59:05 +08:00
|
|
|
type: "PUT",
|
2021-01-20 13:04:21 +08:00
|
|
|
});
|
2023-03-17 18:18:42 +08:00
|
|
|
}
|
2013-05-08 09:58:34 +08:00
|
|
|
|
2015-03-18 05:59:05 +08:00
|
|
|
deactivate() {
|
2019-05-07 16:53:21 +08:00
|
|
|
return ajax(`/admin/users/${this.id}/deactivate`, {
|
2018-05-08 10:44:49 +08:00
|
|
|
type: "PUT",
|
|
|
|
data: { context: document.location.pathname },
|
2021-01-20 13:04:21 +08:00
|
|
|
});
|
2023-03-17 18:18:42 +08:00
|
|
|
}
|
2013-05-08 09:58:34 +08:00
|
|
|
|
2017-11-11 01:18:08 +08:00
|
|
|
unsilence() {
|
|
|
|
this.set("silencingUser", true);
|
2017-11-14 02:41:36 +08:00
|
|
|
|
|
|
|
return ajax(`/admin/users/${this.id}/unsilence`, {
|
2015-03-18 05:59:05 +08:00
|
|
|
type: "PUT",
|
2017-11-14 02:41:36 +08:00
|
|
|
})
|
2019-05-07 16:53:21 +08:00
|
|
|
.then((result) => this.setProperties(result.unsilence))
|
|
|
|
.finally(() => this.set("silencingUser", false));
|
2023-03-17 18:18:42 +08:00
|
|
|
}
|
2013-05-31 23:41:40 +08:00
|
|
|
|
2017-11-14 02:41:36 +08:00
|
|
|
silence(data) {
|
|
|
|
this.set("silencingUser", true);
|
2020-11-03 23:38:56 +08:00
|
|
|
|
2017-11-14 02:41:36 +08:00
|
|
|
return ajax(`/admin/users/${this.id}/silence`, {
|
|
|
|
type: "PUT",
|
|
|
|
data,
|
|
|
|
})
|
2019-05-07 16:53:21 +08:00
|
|
|
.then((result) => this.setProperties(result.silence))
|
|
|
|
.finally(() => this.set("silencingUser", false));
|
2023-03-17 18:18:42 +08:00
|
|
|
}
|
2013-05-31 23:41:40 +08:00
|
|
|
|
2015-03-18 05:59:05 +08:00
|
|
|
sendActivationEmail() {
|
2017-03-29 02:27:54 +08:00
|
|
|
return ajax(userPath("action/send_activation_email"), {
|
2015-03-18 05:59:05 +08:00
|
|
|
type: "POST",
|
2019-05-27 16:15:39 +08:00
|
|
|
data: { username: this.username },
|
2021-01-20 13:04:21 +08:00
|
|
|
});
|
2023-03-17 18:18:42 +08:00
|
|
|
}
|
2013-05-08 09:58:34 +08:00
|
|
|
|
2015-03-18 05:59:05 +08:00
|
|
|
anonymize() {
|
2021-01-20 13:04:21 +08:00
|
|
|
return ajax(`/admin/users/${this.id}/anonymize.json`, {
|
|
|
|
type: "PUT",
|
|
|
|
});
|
2023-03-17 18:18:42 +08:00
|
|
|
}
|
2015-03-07 05:44:54 +08:00
|
|
|
|
2021-01-20 13:04:21 +08:00
|
|
|
destroy(formData) {
|
|
|
|
return ajax(`/admin/users/${this.id}.json`, {
|
|
|
|
type: "DELETE",
|
|
|
|
data: formData,
|
2021-01-27 00:10:46 +08:00
|
|
|
})
|
|
|
|
.then((data) => {
|
|
|
|
if (!data.deleted && data.user) {
|
|
|
|
this.setProperties(data.user);
|
|
|
|
}
|
|
|
|
|
|
|
|
return data;
|
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
this.find(this.id).then((u) => this.setProperties(u));
|
|
|
|
});
|
2023-03-17 18:18:42 +08:00
|
|
|
}
|
2020-04-22 16:37:51 +08:00
|
|
|
|
2021-01-20 13:04:21 +08:00
|
|
|
merge(formData) {
|
|
|
|
return ajax(`/admin/users/${this.id}/merge.json`, {
|
2020-04-22 16:37:51 +08:00
|
|
|
type: "POST",
|
|
|
|
data: formData,
|
2021-01-20 13:04:21 +08:00
|
|
|
});
|
2023-03-17 18:18:42 +08:00
|
|
|
}
|
2020-04-22 16:37:51 +08:00
|
|
|
|
2015-03-18 05:59:05 +08:00
|
|
|
loadDetails() {
|
2019-05-27 16:15:39 +08:00
|
|
|
if (this.loadedDetails) {
|
2019-11-06 00:37:32 +08:00
|
|
|
return Promise.resolve(this);
|
2015-03-18 05:59:05 +08:00
|
|
|
}
|
2013-06-14 01:46:50 +08:00
|
|
|
|
2019-05-07 16:53:21 +08:00
|
|
|
return AdminUser.find(this.id).then((result) => {
|
|
|
|
const userProperties = Object.assign(result, { loadedDetails: true });
|
|
|
|
this.setProperties(userProperties);
|
2013-06-14 01:46:50 +08:00
|
|
|
});
|
2023-03-17 18:18:42 +08:00
|
|
|
}
|
2014-01-24 05:40:10 +08:00
|
|
|
|
2019-11-08 05:38:28 +08:00
|
|
|
@discourseComputed("tl3_requirements")
|
2018-04-25 01:29:15 +08:00
|
|
|
tl3Requirements(requirements) {
|
|
|
|
if (requirements) {
|
|
|
|
return this.store.createRecord("tl3Requirements", requirements);
|
2014-01-24 05:40:10 +08:00
|
|
|
}
|
2023-03-17 18:18:42 +08:00
|
|
|
}
|
2014-03-24 22:19:15 +08:00
|
|
|
|
2019-11-08 05:38:28 +08:00
|
|
|
@discourseComputed("suspended_by")
|
2023-03-17 18:18:42 +08:00
|
|
|
suspendedBy(user) {
|
|
|
|
return user ? AdminUser.create(user) : null;
|
|
|
|
}
|
2017-11-14 02:41:36 +08:00
|
|
|
|
2019-11-08 05:38:28 +08:00
|
|
|
@discourseComputed("silenced_by")
|
2023-03-17 18:18:42 +08:00
|
|
|
silencedBy(user) {
|
|
|
|
return user ? AdminUser.create(user) : null;
|
|
|
|
}
|
2013-02-23 04:41:12 +08:00
|
|
|
|
2019-11-08 05:38:28 +08:00
|
|
|
@discourseComputed("approved_by")
|
2023-03-17 18:18:42 +08:00
|
|
|
approvedBy(user) {
|
|
|
|
return user ? AdminUser.create(user) : null;
|
|
|
|
}
|
2019-05-07 16:53:21 +08:00
|
|
|
|
2020-09-15 22:00:10 +08:00
|
|
|
deleteSSORecord() {
|
|
|
|
return ajax(`/admin/users/${this.id}/sso_record.json`, {
|
|
|
|
type: "DELETE",
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
this.set("single_sign_on_record", null);
|
|
|
|
})
|
|
|
|
.catch(popupAjaxError);
|
2023-03-17 18:18:42 +08:00
|
|
|
}
|
|
|
|
}
|