2018-06-15 23:03:24 +08:00
|
|
|
import ApiKey from "admin/models/api-key";
|
2019-01-24 00:40:05 +08:00
|
|
|
import { default as computed } from "ember-addons/ember-computed-decorators";
|
2015-11-21 09:27:06 +08:00
|
|
|
|
2016-10-21 01:26:41 +08:00
|
|
|
export default Ember.Controller.extend({
|
2019-01-24 00:40:05 +08:00
|
|
|
@computed("model.[]")
|
|
|
|
hasMasterKey(model) {
|
|
|
|
return !!model.findBy("user", null);
|
|
|
|
},
|
|
|
|
|
2013-10-23 03:53:08 +08:00
|
|
|
actions: {
|
2016-10-21 01:26:41 +08:00
|
|
|
generateMasterKey() {
|
2019-05-27 16:15:39 +08:00
|
|
|
ApiKey.generateMasterKey().then(key => this.model.pushObject(key));
|
2013-10-23 03:53:08 +08:00
|
|
|
},
|
|
|
|
|
2016-10-21 01:26:41 +08:00
|
|
|
regenerateKey(key) {
|
2018-06-15 23:03:24 +08:00
|
|
|
bootbox.confirm(
|
|
|
|
I18n.t("admin.api.confirm_regen"),
|
|
|
|
I18n.t("no_value"),
|
|
|
|
I18n.t("yes_value"),
|
|
|
|
result => {
|
|
|
|
if (result) {
|
|
|
|
key.regenerate();
|
|
|
|
}
|
2013-10-23 03:53:08 +08:00
|
|
|
}
|
2018-06-15 23:03:24 +08:00
|
|
|
);
|
2013-10-23 03:53:08 +08:00
|
|
|
},
|
|
|
|
|
2016-10-21 01:26:41 +08:00
|
|
|
revokeKey(key) {
|
2018-06-15 23:03:24 +08:00
|
|
|
bootbox.confirm(
|
|
|
|
I18n.t("admin.api.confirm_revoke"),
|
|
|
|
I18n.t("no_value"),
|
|
|
|
I18n.t("yes_value"),
|
|
|
|
result => {
|
|
|
|
if (result) {
|
2019-05-27 16:15:39 +08:00
|
|
|
key.revoke().then(() => this.model.removeObject(key));
|
2018-06-15 23:03:24 +08:00
|
|
|
}
|
2013-10-23 03:53:08 +08:00
|
|
|
}
|
2018-06-15 23:03:24 +08:00
|
|
|
);
|
2013-10-23 03:53:08 +08:00
|
|
|
}
|
2019-01-24 00:40:05 +08:00
|
|
|
}
|
2013-10-23 03:53:08 +08:00
|
|
|
});
|