2018-06-15 11:03:24 -04: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-12 19:04:36 -04:00
|
|
|
|
2015-08-11 12:27:07 -04:00
|
|
|
export default Ember.Controller.extend(CanCheckEmails, {
|
2017-09-12 17:07:42 -04:00
|
|
|
adminTools: Ember.inject.service(),
|
2017-04-02 13:35:30 -04:00
|
|
|
editingUsername: false,
|
|
|
|
editingName: false,
|
2013-06-25 18:39:20 -04:00
|
|
|
editingTitle: false,
|
2014-07-23 16:54:04 -04:00
|
|
|
originalPrimaryGroupId: null,
|
|
|
|
availableGroups: null,
|
2016-04-18 23:12:14 -04:00
|
|
|
userTitleValue: null,
|
2013-06-25 18:39:20 -04:00
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
showApproval: setting("must_approve_users"),
|
|
|
|
showBadges: setting("enable_badges"),
|
2014-03-05 07:52:20 -05:00
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
primaryGroupDirty: propertyNotEqual(
|
|
|
|
"originalPrimaryGroupId",
|
|
|
|
"model.primary_group_id"
|
|
|
|
),
|
2014-02-10 16:59:36 -05:00
|
|
|
|
2018-02-20 01:44:51 -05:00
|
|
|
canDisableSecondFactor: Ember.computed.and(
|
2018-06-15 11:03:24 -04:00
|
|
|
"model.second_factor_enabled",
|
|
|
|
"model.can_disable_second_factor"
|
2018-02-20 01:44:51 -05:00
|
|
|
),
|
|
|
|
|
2018-04-12 22:41:29 -04:00
|
|
|
@computed("model.automaticGroups")
|
|
|
|
automaticGroups(automaticGroups) {
|
2018-06-15 11:03:24 -04:00
|
|
|
return automaticGroups
|
|
|
|
.map(group => {
|
|
|
|
const name = Ember.String.htmlSafe(group.name);
|
|
|
|
return `<a href="/groups/${name}">${name}</a>`;
|
|
|
|
})
|
|
|
|
.join(", ");
|
2018-04-12 22:41:29 -04:00
|
|
|
},
|
2014-07-13 14:11:38 -04:00
|
|
|
|
2014-09-26 14:48:34 -04:00
|
|
|
userFields: function() {
|
2018-06-15 11:03:24 -04:00
|
|
|
const siteUserFields = this.site.get("user_fields"),
|
|
|
|
userFields = this.get("model.user_fields");
|
2014-09-26 14:48:34 -04:00
|
|
|
|
2014-12-10 13:15:30 -05:00
|
|
|
if (!Ember.isEmpty(siteUserFields)) {
|
2014-09-26 14:48:34 -04:00
|
|
|
return siteUserFields.map(function(uf) {
|
2018-06-15 11:03:24 -04:00
|
|
|
let value = userFields ? userFields[uf.get("id").toString()] : null;
|
|
|
|
return { name: uf.get("name"), value: value };
|
2014-09-26 14:48:34 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
return [];
|
2018-06-15 11:03:24 -04:00
|
|
|
}.property("model.user_fields.[]"),
|
2014-09-26 14:48:34 -04:00
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
@computed("model.username_lower")
|
2017-05-26 15:00:31 -04:00
|
|
|
preferencesPath(username) {
|
|
|
|
return userPath(`${username}/preferences`);
|
|
|
|
},
|
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
@computed("model.can_delete_all_posts", "model.staff", "model.post_count")
|
2018-05-25 11:33:01 -04:00
|
|
|
deleteAllPostsExplanation(canDeleteAllPosts, staff, postCount) {
|
|
|
|
if (canDeleteAllPosts) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (staff) {
|
2018-06-15 11:03:24 -04:00
|
|
|
return I18n.t("admin.user.delete_posts_forbidden_because_staff");
|
2018-05-25 11:33:01 -04:00
|
|
|
}
|
|
|
|
if (postCount > this.siteSettings.delete_all_posts_max) {
|
2018-06-15 11:03:24 -04:00
|
|
|
return I18n.t("admin.user.cant_delete_all_too_many_posts", {
|
|
|
|
count: this.siteSettings.delete_all_posts_max
|
|
|
|
});
|
2018-05-25 11:33:01 -04:00
|
|
|
} else {
|
2018-06-15 11:03:24 -04:00
|
|
|
return I18n.t("admin.user.cant_delete_all_posts", {
|
|
|
|
count: this.siteSettings.delete_user_max_post_age
|
|
|
|
});
|
2018-05-25 11:33:01 -04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
@computed("model.canBeDeleted", "model.staff")
|
2018-05-25 11:33:01 -04:00
|
|
|
deleteExplanation(canBeDeleted, staff) {
|
|
|
|
if (canBeDeleted) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (staff) {
|
2018-06-15 11:03:24 -04:00
|
|
|
return I18n.t("admin.user.delete_forbidden_because_staff");
|
2018-05-25 11:33:01 -04:00
|
|
|
} else {
|
2018-06-15 11:03:24 -04:00
|
|
|
return I18n.t("admin.user.delete_forbidden", {
|
|
|
|
count: this.siteSettings.delete_user_max_post_age
|
|
|
|
});
|
2018-05-25 11:33:01 -04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-09-16 14:08:55 -04:00
|
|
|
actions: {
|
2018-06-15 11:03:24 -04: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 11:45:42 -04:00
|
|
|
|
|
|
|
clearPenaltyHistory() {
|
2018-06-15 11:03:24 -04: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 11:45:42 -04:00
|
|
|
},
|
|
|
|
|
2018-03-04 23:32:23 -05:00
|
|
|
destroy() {
|
2018-06-15 11:03:24 -04:00
|
|
|
const postCount = this.get("model.post_count");
|
2018-03-04 23:32:23 -05:00
|
|
|
if (postCount <= 5) {
|
2018-06-15 11:03:24 -04:00
|
|
|
return this.get("model").destroy({ deletePosts: true });
|
2018-03-04 23:32:23 -05:00
|
|
|
} else {
|
2018-06-15 11:03:24 -04:00
|
|
|
return this.get("model").destroy();
|
2018-03-04 23:32:23 -05:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-01-26 15:40:03 -05:00
|
|
|
viewActionLogs() {
|
2018-06-15 11:03:24 -04:00
|
|
|
this.get("adminTools").showActionLogs(this, {
|
|
|
|
target_user: this.get("model.username")
|
2018-01-26 15:40:03 -05:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2018-01-17 13:03:14 -05:00
|
|
|
showFlagsReceived() {
|
2018-06-15 11:03:24 -04:00
|
|
|
this.get("adminTools").showFlagsReceived(this.get("model"));
|
2018-01-17 13:03:14 -05:00
|
|
|
},
|
2017-09-12 17:07:42 -04:00
|
|
|
showSuspendModal() {
|
2018-06-15 11:03:24 -04:00
|
|
|
this.get("adminTools").showSuspendModal(this.get("model"));
|
2017-09-12 17:07:42 -04:00
|
|
|
},
|
2017-09-13 14:11:33 -04:00
|
|
|
unsuspend() {
|
2018-06-15 11:03:24 -04:00
|
|
|
this.get("model")
|
|
|
|
.unsuspend()
|
|
|
|
.catch(popupAjaxError);
|
2017-09-13 14:11:33 -04:00
|
|
|
},
|
2017-11-13 13:41:36 -05:00
|
|
|
showSilenceModal() {
|
2018-06-15 11:03:24 -04:00
|
|
|
this.get("adminTools").showSilenceModal(this.get("model"));
|
2017-11-13 13:41:36 -05:00
|
|
|
},
|
2017-09-12 17:07:42 -04:00
|
|
|
|
2017-04-02 13:35:30 -04:00
|
|
|
toggleUsernameEdit() {
|
2018-06-15 11:03:24 -04:00
|
|
|
this.set("userUsernameValue", this.get("model.username"));
|
|
|
|
this.toggleProperty("editingUsername");
|
2017-04-02 13:35:30 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
saveUsername() {
|
2018-06-15 11:03:24 -04:00
|
|
|
const oldUsername = this.get("model.username");
|
|
|
|
this.set("model.username", this.get("userUsernameValue"));
|
2017-04-02 13:35:30 -04:00
|
|
|
|
|
|
|
return ajax(`/users/${oldUsername.toLowerCase()}/preferences/username`, {
|
2018-06-15 11:03:24 -04:00
|
|
|
data: { new_username: this.get("userUsernameValue") },
|
|
|
|
type: "PUT"
|
|
|
|
})
|
|
|
|
.catch(e => {
|
|
|
|
this.set("model.username", oldUsername);
|
|
|
|
popupAjaxError(e);
|
|
|
|
})
|
|
|
|
.finally(() => this.toggleProperty("editingUsername"));
|
2017-04-02 13:35:30 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
toggleNameEdit() {
|
2018-06-15 11:03:24 -04:00
|
|
|
this.set("userNameValue", this.get("model.name"));
|
|
|
|
this.toggleProperty("editingName");
|
2017-04-02 13:35:30 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
saveName() {
|
2018-06-15 11:03:24 -04:00
|
|
|
const oldName = this.get("model.name");
|
|
|
|
this.set("model.name", this.get("userNameValue"));
|
|
|
|
|
|
|
|
return ajax(
|
|
|
|
userPath(`${this.get("model.username").toLowerCase()}.json`),
|
|
|
|
{
|
|
|
|
data: { name: this.get("userNameValue") },
|
|
|
|
type: "PUT"
|
|
|
|
}
|
|
|
|
)
|
|
|
|
.catch(e => {
|
|
|
|
this.set("model.name", oldName);
|
|
|
|
popupAjaxError(e);
|
|
|
|
})
|
|
|
|
.finally(() => this.toggleProperty("editingName"));
|
2017-04-02 13:35:30 -04:00
|
|
|
},
|
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
toggleTitleEdit() {
|
2018-06-15 11:03:24 -04:00
|
|
|
this.set("userTitleValue", this.get("model.title"));
|
|
|
|
this.toggleProperty("editingTitle");
|
2013-09-16 14:08:55 -04:00
|
|
|
},
|
2013-06-25 18:39:20 -04:00
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
saveTitle() {
|
2018-06-15 11:03:24 -04:00
|
|
|
const prevTitle = this.get("userTitleValue");
|
|
|
|
|
|
|
|
this.set("model.title", this.get("userTitleValue"));
|
|
|
|
return ajax(
|
|
|
|
userPath(`${this.get("model.username").toLowerCase()}.json`),
|
|
|
|
{
|
|
|
|
data: { title: this.get("userTitleValue") },
|
|
|
|
type: "PUT"
|
|
|
|
}
|
|
|
|
)
|
|
|
|
.catch(e => {
|
|
|
|
this.set("model.title", prevTitle);
|
|
|
|
popupAjaxError(e);
|
|
|
|
})
|
|
|
|
.finally(() => this.toggleProperty("editingTitle"));
|
2013-10-22 15:53:08 -04:00
|
|
|
},
|
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
generateApiKey() {
|
2018-06-15 11:03:24 -04:00
|
|
|
this.get("model").generateApiKey();
|
2013-10-22 15:53:08 -04:00
|
|
|
},
|
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
groupAdded(added) {
|
2018-06-15 11:03:24 -04:00
|
|
|
this.get("model")
|
|
|
|
.groupAdded(added)
|
|
|
|
.catch(function() {
|
|
|
|
bootbox.alert(I18n.t("generic_error"));
|
|
|
|
});
|
2014-07-13 14:11:38 -04:00
|
|
|
},
|
2014-07-15 10:11:39 -04:00
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
groupRemoved(groupId) {
|
2018-06-15 11:03:24 -04:00
|
|
|
this.get("model")
|
|
|
|
.groupRemoved(groupId)
|
|
|
|
.catch(function() {
|
|
|
|
bootbox.alert(I18n.t("generic_error"));
|
|
|
|
});
|
2014-07-13 14:11:38 -04:00
|
|
|
},
|
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
savePrimaryGroup() {
|
|
|
|
const self = this;
|
|
|
|
|
2018-06-15 11:03:24 -04: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-10 16:59:36 -05:00
|
|
|
},
|
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
resetPrimaryGroup() {
|
2018-06-15 11:03:24 -04:00
|
|
|
this.set("model.primary_group_id", this.get("originalPrimaryGroupId"));
|
2014-02-10 16:59:36 -05:00
|
|
|
},
|
|
|
|
|
2015-03-17 17:59:05 -04: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 11:03:24 -04:00
|
|
|
if (result) {
|
|
|
|
self.get("model").generateApiKey();
|
|
|
|
}
|
2013-10-22 15:53:08 -04:00
|
|
|
}
|
2015-03-17 17:59:05 -04:00
|
|
|
);
|
2013-10-22 15:53:08 -04:00
|
|
|
},
|
|
|
|
|
2015-03-17 17:59:05 -04: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 11:03:24 -04:00
|
|
|
if (result) {
|
|
|
|
self.get("model").revokeApiKey();
|
|
|
|
}
|
2013-10-22 15:53:08 -04:00
|
|
|
}
|
2015-03-17 17:59:05 -04:00
|
|
|
);
|
2013-09-16 14:08:55 -04:00
|
|
|
}
|
|
|
|
}
|
2013-07-08 19:32:16 -04:00
|
|
|
});
|