2019-11-05 22:10:23 +08:00
|
|
|
import { bufferedProperty } from "discourse/mixins/buffered-content";
|
2020-02-06 00:14:42 +08:00
|
|
|
import Controller from "@ember/controller";
|
|
|
|
import { isEmpty } from "@ember/utils";
|
2019-11-05 22:10:23 +08:00
|
|
|
import { popupAjaxError } from "discourse/lib/ajax-error";
|
|
|
|
import { empty } from "@ember/object/computed";
|
2020-08-19 02:12:04 +08:00
|
|
|
import showModal from "discourse/lib/show-modal";
|
2019-11-05 22:10:23 +08:00
|
|
|
|
2020-02-06 00:14:42 +08:00
|
|
|
export default Controller.extend(bufferedProperty("model"), {
|
2019-11-05 22:10:23 +08:00
|
|
|
isNew: empty("model.id"),
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
saveDescription() {
|
|
|
|
const buffered = this.buffered;
|
|
|
|
const attrs = buffered.getProperties("description");
|
|
|
|
|
|
|
|
this.model
|
|
|
|
.save(attrs)
|
|
|
|
.then(() => {
|
|
|
|
this.set("editingDescription", false);
|
|
|
|
this.rollbackBuffer();
|
|
|
|
})
|
|
|
|
.catch(popupAjaxError);
|
|
|
|
},
|
|
|
|
|
|
|
|
cancel() {
|
|
|
|
const id = this.get("userField.id");
|
2020-02-06 00:14:42 +08:00
|
|
|
if (isEmpty(id)) {
|
2019-11-05 22:10:23 +08:00
|
|
|
this.destroyAction(this.userField);
|
|
|
|
} else {
|
|
|
|
this.rollbackBuffer();
|
|
|
|
this.set("editing", false);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
editDescription() {
|
|
|
|
this.toggleProperty("editingDescription");
|
|
|
|
if (!this.editingDescription) {
|
|
|
|
this.rollbackBuffer();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
revokeKey(key) {
|
|
|
|
key.revoke().catch(popupAjaxError);
|
|
|
|
},
|
|
|
|
|
|
|
|
deleteKey(key) {
|
|
|
|
key
|
|
|
|
.destroyRecord()
|
|
|
|
.then(() => this.transitionToRoute("adminApiKeys.index"))
|
|
|
|
.catch(popupAjaxError);
|
|
|
|
},
|
|
|
|
|
|
|
|
undoRevokeKey(key) {
|
|
|
|
key.undoRevoke().catch(popupAjaxError);
|
2020-08-19 02:12:04 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
showURLs(urls) {
|
|
|
|
return showModal("admin-api-key-urls", {
|
|
|
|
admin: true,
|
|
|
|
model: {
|
|
|
|
urls
|
|
|
|
}
|
|
|
|
});
|
2019-11-05 22:10:23 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|