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