2019-11-05 09:10:23 -05:00
|
|
|
import { bufferedProperty } from "discourse/mixins/buffered-content";
|
2020-02-05 11:14:42 -05:00
|
|
|
import Controller from "@ember/controller";
|
|
|
|
import { isEmpty } from "@ember/utils";
|
2019-11-05 09:10:23 -05:00
|
|
|
import { popupAjaxError } from "discourse/lib/ajax-error";
|
|
|
|
import { empty } from "@ember/object/computed";
|
2020-08-18 14:12:04 -04:00
|
|
|
import showModal from "discourse/lib/show-modal";
|
2019-11-05 09:10:23 -05:00
|
|
|
|
2020-02-05 11:14:42 -05:00
|
|
|
export default Controller.extend(bufferedProperty("model"), {
|
2019-11-05 09:10:23 -05: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-05 11:14:42 -05:00
|
|
|
if (isEmpty(id)) {
|
2019-11-05 09:10:23 -05: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-18 14:12:04 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
showURLs(urls) {
|
|
|
|
return showModal("admin-api-key-urls", {
|
|
|
|
admin: true,
|
|
|
|
model: {
|
|
|
|
urls
|
|
|
|
}
|
|
|
|
});
|
2019-11-05 09:10:23 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|