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