2016-07-01 01:55:44 +08:00
|
|
|
import { ajax } from 'discourse/lib/ajax';
|
2014-09-30 04:31:05 +08:00
|
|
|
import CanCheckEmails from 'discourse/mixins/can-check-emails';
|
2015-08-08 03:08:27 +08:00
|
|
|
import { propertyNotEqual, setting } from 'discourse/lib/computed';
|
2014-08-13 07:04:36 +08:00
|
|
|
|
2015-08-12 00:27:07 +08:00
|
|
|
export default Ember.Controller.extend(CanCheckEmails, {
|
2013-06-26 06:39:20 +08:00
|
|
|
editingTitle: false,
|
2014-07-24 04:54:04 +08:00
|
|
|
originalPrimaryGroupId: null,
|
|
|
|
availableGroups: null,
|
2016-04-19 11:12:14 +08:00
|
|
|
userTitleValue: null,
|
2013-06-26 06:39:20 +08:00
|
|
|
|
2015-08-08 03:08:27 +08:00
|
|
|
showApproval: setting('must_approve_users'),
|
|
|
|
showBadges: setting('enable_badges'),
|
2014-03-05 20:52:20 +08:00
|
|
|
|
2015-08-08 03:08:27 +08:00
|
|
|
primaryGroupDirty: propertyNotEqual('originalPrimaryGroupId', 'model.primary_group_id'),
|
2014-02-11 05:59:36 +08:00
|
|
|
|
2015-03-18 05:59:05 +08:00
|
|
|
automaticGroups: function() {
|
|
|
|
return this.get("model.automaticGroups").map((g) => g.name).join(", ");
|
|
|
|
}.property("model.automaticGroups"),
|
2014-07-14 02:11:38 +08:00
|
|
|
|
2014-09-27 02:48:34 +08:00
|
|
|
userFields: function() {
|
2015-03-18 05:59:05 +08:00
|
|
|
const siteUserFields = this.site.get('user_fields'),
|
2015-05-19 22:56:32 +08:00
|
|
|
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) {
|
2015-03-18 05:59:05 +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 [];
|
2016-04-29 04:49:24 +08:00
|
|
|
}.property('model.user_fields.[]'),
|
2014-09-27 02:48:34 +08:00
|
|
|
|
2013-09-17 02:08:55 +08:00
|
|
|
actions: {
|
2016-12-20 19:26:53 +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); },
|
|
|
|
unsuspend() { return this.get("model").unsuspend(); },
|
|
|
|
unblock() { return this.get("model").unblock(); },
|
|
|
|
block() { return this.get("model").block(); },
|
|
|
|
deleteAllPosts() { return this.get("model").deleteAllPosts(); },
|
|
|
|
anonymize() { return this.get('model').anonymize(); },
|
|
|
|
destroy() { return this.get('model').destroy(); },
|
|
|
|
|
2015-03-18 05:59:05 +08:00
|
|
|
toggleTitleEdit() {
|
2016-04-19 11:12:14 +08:00
|
|
|
this.set('userTitleValue', this.get('model.title'));
|
2013-09-17 02:08:55 +08:00
|
|
|
this.toggleProperty('editingTitle');
|
|
|
|
},
|
2013-06-26 06:39:20 +08:00
|
|
|
|
2015-03-18 05:59:05 +08:00
|
|
|
saveTitle() {
|
|
|
|
const self = this;
|
|
|
|
|
2016-12-30 01:37:57 +08:00
|
|
|
return ajax(`/users/${this.get('model.username').toLowerCase()}.json`, {
|
2016-04-19 11:12:14 +08:00
|
|
|
data: {title: this.get('userTitleValue')},
|
2013-09-17 02:08:55 +08:00
|
|
|
type: 'PUT'
|
2015-03-18 05:59:05 +08:00
|
|
|
}).catch(function(e) {
|
2013-09-17 02:08:55 +08:00
|
|
|
bootbox.alert(I18n.t("generic_error_with_reason", {error: "http: " + e.status + " - " + e.body}));
|
2015-03-18 05:59:05 +08:00
|
|
|
}).finally(function() {
|
2016-04-19 11:12:14 +08:00
|
|
|
self.set('model.title', self.get('userTitleValue'));
|
|
|
|
self.toggleProperty('editingTitle');
|
2013-09-17 02:08:55 +08:00
|
|
|
});
|
2013-10-23 03:53:08 +08:00
|
|
|
},
|
|
|
|
|
2015-03-18 05:59:05 +08:00
|
|
|
generateApiKey() {
|
2013-10-23 03:53:08 +08:00
|
|
|
this.get('model').generateApiKey();
|
|
|
|
},
|
|
|
|
|
2015-03-18 05:59:05 +08:00
|
|
|
groupAdded(added) {
|
2014-07-15 22:11:39 +08:00
|
|
|
this.get('model').groupAdded(added).catch(function() {
|
2014-07-14 02:11:38 +08:00
|
|
|
bootbox.alert(I18n.t('generic_error'));
|
|
|
|
});
|
|
|
|
},
|
2014-07-15 22:11:39 +08:00
|
|
|
|
2015-03-18 05:59:05 +08:00
|
|
|
groupRemoved(groupId) {
|
|
|
|
this.get('model').groupRemoved(groupId).catch(function() {
|
2014-07-14 02:11:38 +08:00
|
|
|
bootbox.alert(I18n.t('generic_error'));
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-03-18 05:59:05 +08:00
|
|
|
savePrimaryGroup() {
|
|
|
|
const self = this;
|
|
|
|
|
2016-07-01 01:55:44 +08:00
|
|
|
return ajax("/admin/users/" + this.get('model.id') + "/primary_group", {
|
2014-02-11 05:59:36 +08:00
|
|
|
type: 'PUT',
|
2015-05-19 22:56:32 +08:00
|
|
|
data: {primary_group_id: this.get('model.primary_group_id')}
|
2014-02-11 05:59:36 +08:00
|
|
|
}).then(function () {
|
2015-05-19 22:56:32 +08:00
|
|
|
self.set('originalPrimaryGroupId', self.get('model.primary_group_id'));
|
2014-02-11 05:59:36 +08:00
|
|
|
}).catch(function() {
|
|
|
|
bootbox.alert(I18n.t('generic_error'));
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-03-18 05:59:05 +08:00
|
|
|
resetPrimaryGroup() {
|
2015-05-19 22:56:32 +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) {
|
|
|
|
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) {
|
|
|
|
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-09-10 00:21:47 +08:00
|
|
|
|
2013-07-09 07:32:16 +08:00
|
|
|
});
|