2018-06-15 23:03:24 +08:00
|
|
|
import { ajax } from "discourse/lib/ajax";
|
|
|
|
import CanCheckEmails from "discourse/mixins/can-check-emails";
|
|
|
|
import { propertyNotEqual, setting } from "discourse/lib/computed";
|
|
|
|
import { userPath } from "discourse/lib/url";
|
|
|
|
import { popupAjaxError } from "discourse/lib/ajax-error";
|
|
|
|
import computed from "ember-addons/ember-computed-decorators";
|
2014-08-13 07:04:36 +08:00
|
|
|
|
2015-08-12 00:27:07 +08:00
|
|
|
export default Ember.Controller.extend(CanCheckEmails, {
|
2017-09-13 05:07:42 +08:00
|
|
|
adminTools: Ember.inject.service(),
|
2014-07-24 04:54:04 +08:00
|
|
|
originalPrimaryGroupId: null,
|
2018-10-02 12:34:08 +08:00
|
|
|
customGroupIdsBuffer: null,
|
2014-07-24 04:54:04 +08:00
|
|
|
availableGroups: null,
|
2016-04-19 11:12:14 +08:00
|
|
|
userTitleValue: null,
|
2013-06-26 06:39:20 +08:00
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
showApproval: setting("must_approve_users"),
|
|
|
|
showBadges: setting("enable_badges"),
|
2018-06-20 09:07:41 +08:00
|
|
|
hasLockedTrustLevel: Ember.computed.notEmpty(
|
|
|
|
"model.manual_locked_trust_level"
|
|
|
|
),
|
2014-03-05 20:52:20 +08:00
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
primaryGroupDirty: propertyNotEqual(
|
|
|
|
"originalPrimaryGroupId",
|
|
|
|
"model.primary_group_id"
|
|
|
|
),
|
2014-02-11 05:59:36 +08:00
|
|
|
|
2018-02-20 14:44:51 +08:00
|
|
|
canDisableSecondFactor: Ember.computed.and(
|
2018-06-15 23:03:24 +08:00
|
|
|
"model.second_factor_enabled",
|
|
|
|
"model.can_disable_second_factor"
|
2018-02-20 14:44:51 +08:00
|
|
|
),
|
|
|
|
|
2018-10-02 12:34:08 +08:00
|
|
|
@computed("model.customGroups")
|
|
|
|
customGroupIds(customGroups) {
|
|
|
|
return customGroups.mapBy("id");
|
|
|
|
},
|
|
|
|
|
|
|
|
@computed("customGroupIdsBuffer", "customGroupIds")
|
|
|
|
customGroupsDirty(buffer, original) {
|
|
|
|
if (buffer === null) return false;
|
|
|
|
|
|
|
|
return buffer.length === original.length
|
|
|
|
? buffer.any(id => !original.includes(id))
|
|
|
|
: true;
|
|
|
|
},
|
|
|
|
|
2018-04-13 10:41:29 +08:00
|
|
|
@computed("model.automaticGroups")
|
|
|
|
automaticGroups(automaticGroups) {
|
2018-06-15 23:03:24 +08:00
|
|
|
return automaticGroups
|
|
|
|
.map(group => {
|
|
|
|
const name = Ember.String.htmlSafe(group.name);
|
|
|
|
return `<a href="/groups/${name}">${name}</a>`;
|
|
|
|
})
|
|
|
|
.join(", ");
|
2018-04-13 10:41:29 +08:00
|
|
|
},
|
2014-07-14 02:11:38 +08:00
|
|
|
|
2018-07-23 23:51:57 +08:00
|
|
|
@computed("model.associated_accounts")
|
|
|
|
associatedAccountsLoaded(associatedAccounts) {
|
|
|
|
return typeof associatedAccounts !== "undefined";
|
|
|
|
},
|
|
|
|
|
|
|
|
@computed("model.associated_accounts")
|
|
|
|
associatedAccounts(associatedAccounts) {
|
|
|
|
return associatedAccounts
|
|
|
|
.map(provider => `${provider.name} (${provider.description})`)
|
|
|
|
.join(", ");
|
|
|
|
},
|
|
|
|
|
2014-09-27 02:48:34 +08:00
|
|
|
userFields: function() {
|
2018-06-15 23:03:24 +08:00
|
|
|
const siteUserFields = this.site.get("user_fields"),
|
|
|
|
userFields = this.get("model.user_fields");
|
2014-09-27 02:48:34 +08:00
|
|
|
|
2014-12-11 02:15:30 +08:00
|
|
|
if (!Ember.isEmpty(siteUserFields)) {
|
2014-09-27 02:48:34 +08:00
|
|
|
return siteUserFields.map(function(uf) {
|
2018-06-15 23:03:24 +08:00
|
|
|
let value = userFields ? userFields[uf.get("id").toString()] : null;
|
|
|
|
return { name: uf.get("name"), value: value };
|
2014-09-27 02:48:34 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
return [];
|
2018-06-15 23:03:24 +08:00
|
|
|
}.property("model.user_fields.[]"),
|
2014-09-27 02:48:34 +08:00
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
@computed("model.username_lower")
|
2017-05-27 03:00:31 +08:00
|
|
|
preferencesPath(username) {
|
|
|
|
return userPath(`${username}/preferences`);
|
|
|
|
},
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
@computed("model.can_delete_all_posts", "model.staff", "model.post_count")
|
2018-05-25 23:33:01 +08:00
|
|
|
deleteAllPostsExplanation(canDeleteAllPosts, staff, postCount) {
|
|
|
|
if (canDeleteAllPosts) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (staff) {
|
2018-06-15 23:03:24 +08:00
|
|
|
return I18n.t("admin.user.delete_posts_forbidden_because_staff");
|
2018-05-25 23:33:01 +08:00
|
|
|
}
|
|
|
|
if (postCount > this.siteSettings.delete_all_posts_max) {
|
2018-06-15 23:03:24 +08:00
|
|
|
return I18n.t("admin.user.cant_delete_all_too_many_posts", {
|
|
|
|
count: this.siteSettings.delete_all_posts_max
|
|
|
|
});
|
2018-05-25 23:33:01 +08:00
|
|
|
} else {
|
2018-06-15 23:03:24 +08:00
|
|
|
return I18n.t("admin.user.cant_delete_all_posts", {
|
|
|
|
count: this.siteSettings.delete_user_max_post_age
|
|
|
|
});
|
2018-05-25 23:33:01 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
@computed("model.canBeDeleted", "model.staff")
|
2018-05-25 23:33:01 +08:00
|
|
|
deleteExplanation(canBeDeleted, staff) {
|
|
|
|
if (canBeDeleted) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (staff) {
|
2018-06-15 23:03:24 +08:00
|
|
|
return I18n.t("admin.user.delete_forbidden_because_staff");
|
2018-05-25 23:33:01 +08:00
|
|
|
} else {
|
2018-06-15 23:03:24 +08:00
|
|
|
return I18n.t("admin.user.delete_forbidden", {
|
|
|
|
count: this.siteSettings.delete_user_max_post_age
|
|
|
|
});
|
2018-05-25 23:33:01 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-10-02 12:34:08 +08:00
|
|
|
groupAdded(added) {
|
|
|
|
this.get("model")
|
|
|
|
.groupAdded(added)
|
|
|
|
.catch(function() {
|
|
|
|
bootbox.alert(I18n.t("generic_error"));
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
groupRemoved(groupId) {
|
|
|
|
this.get("model")
|
|
|
|
.groupRemoved(groupId)
|
|
|
|
.then(() => {
|
|
|
|
if (groupId === this.get("originalPrimaryGroupId")) {
|
|
|
|
this.set("originalPrimaryGroupId", null);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(function() {
|
|
|
|
bootbox.alert(I18n.t("generic_error"));
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2013-09-17 02:08:55 +08:00
|
|
|
actions: {
|
2018-06-15 23:03:24 +08:00
|
|
|
impersonate() {
|
|
|
|
return this.get("model").impersonate();
|
|
|
|
},
|
|
|
|
logOut() {
|
|
|
|
return this.get("model").logOut();
|
|
|
|
},
|
|
|
|
resetBounceScore() {
|
|
|
|
return this.get("model").resetBounceScore();
|
|
|
|
},
|
|
|
|
refreshBrowsers() {
|
|
|
|
return this.get("model").refreshBrowsers();
|
|
|
|
},
|
|
|
|
approve() {
|
|
|
|
return this.get("model").approve();
|
|
|
|
},
|
|
|
|
deactivate() {
|
|
|
|
return this.get("model").deactivate();
|
|
|
|
},
|
|
|
|
sendActivationEmail() {
|
|
|
|
return this.get("model").sendActivationEmail();
|
|
|
|
},
|
|
|
|
activate() {
|
|
|
|
return this.get("model").activate();
|
|
|
|
},
|
|
|
|
revokeAdmin() {
|
|
|
|
return this.get("model").revokeAdmin();
|
|
|
|
},
|
|
|
|
grantAdmin() {
|
|
|
|
return this.get("model").grantAdmin();
|
|
|
|
},
|
|
|
|
revokeModeration() {
|
|
|
|
return this.get("model").revokeModeration();
|
|
|
|
},
|
|
|
|
grantModeration() {
|
|
|
|
return this.get("model").grantModeration();
|
|
|
|
},
|
|
|
|
saveTrustLevel() {
|
|
|
|
return this.get("model").saveTrustLevel();
|
|
|
|
},
|
|
|
|
restoreTrustLevel() {
|
|
|
|
return this.get("model").restoreTrustLevel();
|
|
|
|
},
|
|
|
|
lockTrustLevel(locked) {
|
|
|
|
return this.get("model").lockTrustLevel(locked);
|
|
|
|
},
|
|
|
|
unsilence() {
|
|
|
|
return this.get("model").unsilence();
|
|
|
|
},
|
|
|
|
silence() {
|
|
|
|
return this.get("model").silence();
|
|
|
|
},
|
|
|
|
deleteAllPosts() {
|
|
|
|
return this.get("model").deleteAllPosts();
|
|
|
|
},
|
|
|
|
anonymize() {
|
|
|
|
return this.get("model").anonymize();
|
|
|
|
},
|
|
|
|
disableSecondFactor() {
|
|
|
|
return this.get("model").disableSecondFactor();
|
|
|
|
},
|
2018-05-25 23:45:42 +08:00
|
|
|
|
|
|
|
clearPenaltyHistory() {
|
2018-06-15 23:03:24 +08:00
|
|
|
let user = this.get("model");
|
|
|
|
return ajax(`/admin/users/${user.get("id")}/penalty_history`, {
|
|
|
|
type: "DELETE"
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
user.set("tl3_requirements.penalty_counts.total", 0);
|
|
|
|
})
|
|
|
|
.catch(popupAjaxError);
|
2018-05-25 23:45:42 +08:00
|
|
|
},
|
|
|
|
|
2018-03-05 12:32:23 +08:00
|
|
|
destroy() {
|
2018-06-15 23:03:24 +08:00
|
|
|
const postCount = this.get("model.post_count");
|
2018-03-05 12:32:23 +08:00
|
|
|
if (postCount <= 5) {
|
2018-06-15 23:03:24 +08:00
|
|
|
return this.get("model").destroy({ deletePosts: true });
|
2018-03-05 12:32:23 +08:00
|
|
|
} else {
|
2018-06-15 23:03:24 +08:00
|
|
|
return this.get("model").destroy();
|
2018-03-05 12:32:23 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-01-27 04:40:03 +08:00
|
|
|
viewActionLogs() {
|
2018-06-15 23:03:24 +08:00
|
|
|
this.get("adminTools").showActionLogs(this, {
|
|
|
|
target_user: this.get("model.username")
|
2018-01-27 04:40:03 +08:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2018-01-18 02:03:14 +08:00
|
|
|
showFlagsReceived() {
|
2018-06-15 23:03:24 +08:00
|
|
|
this.get("adminTools").showFlagsReceived(this.get("model"));
|
2018-01-18 02:03:14 +08:00
|
|
|
},
|
2017-09-13 05:07:42 +08:00
|
|
|
showSuspendModal() {
|
2018-06-15 23:03:24 +08:00
|
|
|
this.get("adminTools").showSuspendModal(this.get("model"));
|
2017-09-13 05:07:42 +08:00
|
|
|
},
|
2017-09-14 02:11:33 +08:00
|
|
|
unsuspend() {
|
2018-06-15 23:03:24 +08:00
|
|
|
this.get("model")
|
|
|
|
.unsuspend()
|
|
|
|
.catch(popupAjaxError);
|
2017-09-14 02:11:33 +08:00
|
|
|
},
|
2017-11-14 02:41:36 +08:00
|
|
|
showSilenceModal() {
|
2018-06-15 23:03:24 +08:00
|
|
|
this.get("adminTools").showSilenceModal(this.get("model"));
|
2017-11-14 02:41:36 +08:00
|
|
|
},
|
2017-09-13 05:07:42 +08:00
|
|
|
|
2018-12-17 22:28:29 +08:00
|
|
|
saveUsername(newUsername) {
|
2018-06-15 23:03:24 +08:00
|
|
|
const oldUsername = this.get("model.username");
|
2018-12-17 22:28:29 +08:00
|
|
|
this.set("model.username", newUsername);
|
2017-04-03 01:35:30 +08:00
|
|
|
|
|
|
|
return ajax(`/users/${oldUsername.toLowerCase()}/preferences/username`, {
|
2018-12-17 22:28:29 +08:00
|
|
|
data: { new_username: newUsername },
|
2018-06-15 23:03:24 +08:00
|
|
|
type: "PUT"
|
|
|
|
})
|
|
|
|
.catch(e => {
|
|
|
|
this.set("model.username", oldUsername);
|
|
|
|
popupAjaxError(e);
|
|
|
|
})
|
|
|
|
.finally(() => this.toggleProperty("editingUsername"));
|
2017-04-03 01:35:30 +08:00
|
|
|
},
|
|
|
|
|
2018-12-17 22:28:29 +08:00
|
|
|
saveName(newName) {
|
2018-06-15 23:03:24 +08:00
|
|
|
const oldName = this.get("model.name");
|
2018-12-17 22:28:29 +08:00
|
|
|
this.set("model.name", newName);
|
2018-06-15 23:03:24 +08:00
|
|
|
|
|
|
|
return ajax(
|
|
|
|
userPath(`${this.get("model.username").toLowerCase()}.json`),
|
|
|
|
{
|
2018-12-17 22:28:29 +08:00
|
|
|
data: { name: newName },
|
2018-06-15 23:03:24 +08:00
|
|
|
type: "PUT"
|
|
|
|
}
|
|
|
|
)
|
|
|
|
.catch(e => {
|
|
|
|
this.set("model.name", oldName);
|
|
|
|
popupAjaxError(e);
|
|
|
|
})
|
|
|
|
.finally(() => this.toggleProperty("editingName"));
|
2017-04-03 01:35:30 +08:00
|
|
|
},
|
|
|
|
|
2018-12-17 22:28:29 +08:00
|
|
|
saveTitle(newTitle) {
|
|
|
|
const oldTitle = this.get("model.title");
|
2018-06-15 23:03:24 +08:00
|
|
|
|
2018-12-17 22:28:29 +08:00
|
|
|
this.set("model.title", newTitle);
|
2018-06-15 23:03:24 +08:00
|
|
|
return ajax(
|
|
|
|
userPath(`${this.get("model.username").toLowerCase()}.json`),
|
|
|
|
{
|
2018-12-17 22:28:29 +08:00
|
|
|
data: { title: newTitle },
|
2018-06-15 23:03:24 +08:00
|
|
|
type: "PUT"
|
|
|
|
}
|
|
|
|
)
|
|
|
|
.catch(e => {
|
2018-12-17 22:28:29 +08:00
|
|
|
this.set("model.title", oldTitle);
|
2018-06-15 23:03:24 +08:00
|
|
|
popupAjaxError(e);
|
|
|
|
})
|
|
|
|
.finally(() => this.toggleProperty("editingTitle"));
|
2013-10-23 03:53:08 +08:00
|
|
|
},
|
|
|
|
|
2015-03-18 05:59:05 +08:00
|
|
|
generateApiKey() {
|
2018-06-15 23:03:24 +08:00
|
|
|
this.get("model").generateApiKey();
|
2013-10-23 03:53:08 +08:00
|
|
|
},
|
|
|
|
|
2018-10-02 12:34:08 +08:00
|
|
|
saveCustomGroups() {
|
|
|
|
const currentIds = this.get("customGroupIds");
|
|
|
|
const bufferedIds = this.get("customGroupIdsBuffer");
|
|
|
|
const availableGroups = this.get("availableGroups");
|
|
|
|
|
2019-01-18 02:05:39 +08:00
|
|
|
bufferedIds
|
|
|
|
.filter(id => !currentIds.includes(id))
|
|
|
|
.forEach(id => {
|
|
|
|
this.groupAdded(availableGroups.findBy("id", id));
|
|
|
|
});
|
2018-10-02 12:34:08 +08:00
|
|
|
|
|
|
|
currentIds
|
|
|
|
.filter(id => !bufferedIds.includes(id))
|
|
|
|
.forEach(id => this.groupRemoved(id));
|
2014-07-14 02:11:38 +08:00
|
|
|
},
|
2014-07-15 22:11:39 +08:00
|
|
|
|
2018-10-02 12:34:08 +08:00
|
|
|
resetCustomGroups() {
|
|
|
|
this.set("customGroupIdsBuffer", null);
|
2014-07-14 02:11:38 +08:00
|
|
|
},
|
|
|
|
|
2015-03-18 05:59:05 +08:00
|
|
|
savePrimaryGroup() {
|
|
|
|
const self = this;
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
return ajax("/admin/users/" + this.get("model.id") + "/primary_group", {
|
|
|
|
type: "PUT",
|
|
|
|
data: { primary_group_id: this.get("model.primary_group_id") }
|
|
|
|
})
|
|
|
|
.then(function() {
|
|
|
|
self.set(
|
|
|
|
"originalPrimaryGroupId",
|
|
|
|
self.get("model.primary_group_id")
|
|
|
|
);
|
|
|
|
})
|
|
|
|
.catch(function() {
|
|
|
|
bootbox.alert(I18n.t("generic_error"));
|
|
|
|
});
|
2014-02-11 05:59:36 +08:00
|
|
|
},
|
|
|
|
|
2015-03-18 05:59:05 +08:00
|
|
|
resetPrimaryGroup() {
|
2018-06-15 23:03:24 +08:00
|
|
|
this.set("model.primary_group_id", this.get("originalPrimaryGroupId"));
|
2014-02-11 05:59:36 +08:00
|
|
|
},
|
|
|
|
|
2015-03-18 05:59:05 +08:00
|
|
|
regenerateApiKey() {
|
|
|
|
const self = this;
|
|
|
|
|
|
|
|
bootbox.confirm(
|
|
|
|
I18n.t("admin.api.confirm_regen"),
|
|
|
|
I18n.t("no_value"),
|
|
|
|
I18n.t("yes_value"),
|
|
|
|
function(result) {
|
2018-06-15 23:03:24 +08:00
|
|
|
if (result) {
|
|
|
|
self.get("model").generateApiKey();
|
|
|
|
}
|
2013-10-23 03:53:08 +08:00
|
|
|
}
|
2015-03-18 05:59:05 +08:00
|
|
|
);
|
2013-10-23 03:53:08 +08:00
|
|
|
},
|
|
|
|
|
2015-03-18 05:59:05 +08:00
|
|
|
revokeApiKey() {
|
|
|
|
const self = this;
|
|
|
|
|
|
|
|
bootbox.confirm(
|
|
|
|
I18n.t("admin.api.confirm_revoke"),
|
|
|
|
I18n.t("no_value"),
|
|
|
|
I18n.t("yes_value"),
|
|
|
|
function(result) {
|
2018-06-15 23:03:24 +08:00
|
|
|
if (result) {
|
|
|
|
self.get("model").revokeApiKey();
|
|
|
|
}
|
2013-10-23 03:53:08 +08:00
|
|
|
}
|
2015-03-18 05:59:05 +08:00
|
|
|
);
|
2013-09-17 02:08:55 +08:00
|
|
|
}
|
|
|
|
}
|
2013-07-09 07:32:16 +08:00
|
|
|
});
|