2019-10-30 16:28:29 -04:00
|
|
|
import { filter, gt, lt, not, or } from "@ember/object/computed";
|
2015-11-20 20:27:06 -05:00
|
|
|
import Group from "discourse/models/group";
|
2020-05-13 16:23:41 -04:00
|
|
|
import I18n from "I18n";
|
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";
|
2016-06-30 13:55:44 -04:00
|
|
|
import { ajax } from "discourse/lib/ajax";
|
2019-11-07 16:38:28 -05:00
|
|
|
import discourseComputed from "discourse-common/utils/decorators";
|
2020-06-03 12:45:26 -04:00
|
|
|
import getURL from "discourse-common/lib/get-url";
|
2015-05-19 10:56:32 -04:00
|
|
|
import { popupAjaxError } from "discourse/lib/ajax-error";
|
2015-08-07 15:08:27 -04:00
|
|
|
import { propertyNotEqual } from "discourse/lib/computed";
|
2021-01-20 00:04:21 -05:00
|
|
|
import { userPath } from "discourse/lib/url";
|
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() {
|
2021-01-20 00:04:21 -05:00
|
|
|
return ajax(`/admin/users/${this.get("id")}/delete_posts_batch`, {
|
|
|
|
type: "PUT",
|
|
|
|
});
|
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",
|
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-18 21:57:16 -04:00
|
|
|
}).then((resp) => {
|
2017-04-04 13:59:22 -04:00
|
|
|
this.setProperties({
|
2015-03-17 17:59:05 -04: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-18 21:57:16 -04: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-17 17:59:05 -04:00
|
|
|
});
|
|
|
|
});
|
2013-02-22 15:41:12 -05:00
|
|
|
},
|
|
|
|
|
2021-09-14 08:19:28 -04:00
|
|
|
grantAdmin(data) {
|
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",
|
2021-09-14 08:19:28 -04: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 00:04:21 -05:00
|
|
|
});
|
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",
|
|
|
|
})
|
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-18 21:57:16 -04:00
|
|
|
.then((resp) => {
|
2019-05-07 04:53:21 -04:00
|
|
|
this.setProperties({
|
2015-03-17 17:59:05 -04: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-18 21:57:16 -04:00
|
|
|
can_be_merged: resp.can_be_merged,
|
|
|
|
can_be_anonymized: resp.can_be_anonymized,
|
2015-03-17 17:59:05 -04:00
|
|
|
});
|
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",
|
|
|
|
})
|
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-18 21:57:16 -04:00
|
|
|
.then((resp) => {
|
2019-05-07 04:53:21 -04:00
|
|
|
this.setProperties({
|
2015-03-17 17:59:05 -04: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-18 21:57:16 -04:00
|
|
|
can_be_merged: resp.can_be_merged,
|
|
|
|
can_be_anonymized: resp.can_be_anonymized,
|
2015-03-17 17:59:05 -04:00
|
|
|
});
|
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 },
|
2021-01-20 00:04:21 -05:00
|
|
|
});
|
2013-07-01 10:22:21 -04:00
|
|
|
},
|
|
|
|
|
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 },
|
2021-01-20 00:04:21 -05:00
|
|
|
});
|
2014-09-13 16:55:26 -04:00
|
|
|
},
|
|
|
|
|
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"),
|
2022-12-19 12:36:03 -05:00
|
|
|
canSilence: 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 },
|
2021-01-20 00:04:21 -05:00
|
|
|
});
|
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 },
|
2021-01-20 00:04:21 -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",
|
2021-01-20 00:04:21 -05:00
|
|
|
});
|
2013-05-07 21:58:34 -04:00
|
|
|
},
|
|
|
|
|
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 },
|
2021-01-20 00:04:21 -05:00
|
|
|
});
|
2013-05-07 21:58:34 -04:00
|
|
|
},
|
|
|
|
|
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))
|
|
|
|
.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);
|
2020-11-03 10:38:56 -05:00
|
|
|
|
2017-11-13 13:41:36 -05:00
|
|
|
return ajax(`/admin/users/${this.id}/silence`, {
|
|
|
|
type: "PUT",
|
|
|
|
data,
|
|
|
|
})
|
2019-05-07 04:53:21 -04:00
|
|
|
.then((result) => this.setProperties(result.silence))
|
|
|
|
.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 },
|
2021-01-20 00:04:21 -05:00
|
|
|
});
|
2013-05-07 21:58:34 -04:00
|
|
|
},
|
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
anonymize() {
|
2021-01-20 00:04:21 -05:00
|
|
|
return ajax(`/admin/users/${this.id}/anonymize.json`, {
|
|
|
|
type: "PUT",
|
|
|
|
});
|
|
|
|
},
|
2015-03-06 16:44:54 -05:00
|
|
|
|
2021-01-20 00:04:21 -05:00
|
|
|
destroy(formData) {
|
|
|
|
return ajax(`/admin/users/${this.id}.json`, {
|
|
|
|
type: "DELETE",
|
|
|
|
data: formData,
|
2021-01-26 11:10:46 -05:00
|
|
|
})
|
|
|
|
.then((data) => {
|
|
|
|
if (!data.deleted && data.user) {
|
|
|
|
this.setProperties(data.user);
|
|
|
|
}
|
|
|
|
|
|
|
|
return data;
|
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
this.find(this.id).then((u) => this.setProperties(u));
|
|
|
|
});
|
2021-01-20 00:04:21 -05:00
|
|
|
},
|
2020-04-22 04:37:51 -04:00
|
|
|
|
2021-01-20 00:04:21 -05:00
|
|
|
merge(formData) {
|
|
|
|
return ajax(`/admin/users/${this.id}/merge.json`, {
|
2020-04-22 04:37:51 -04:00
|
|
|
type: "POST",
|
|
|
|
data: formData,
|
2021-01-20 00:04:21 -05:00
|
|
|
});
|
2020-04-22 04:37:51 -04:00
|
|
|
},
|
|
|
|
|
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,
|
|
|
|
|
2020-09-15 10:00:10 -04:00
|
|
|
deleteSSORecord() {
|
|
|
|
return ajax(`/admin/users/${this.id}/sso_record.json`, {
|
|
|
|
type: "DELETE",
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
this.set("single_sign_on_record", null);
|
|
|
|
})
|
|
|
|
.catch(popupAjaxError);
|
|
|
|
},
|
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;
|