2023-03-15 17:42:12 +08:00
|
|
|
import { action } from "@ember/object";
|
|
|
|
import { empty } from "@ember/object/computed";
|
2020-02-06 00:14:42 +08:00
|
|
|
import Controller from "@ember/controller";
|
2019-11-05 22:10:23 +08:00
|
|
|
import { bufferedProperty } from "discourse/mixins/buffered-content";
|
2020-02-06 00:14:42 +08:00
|
|
|
import { isEmpty } from "@ember/utils";
|
2019-11-05 22:10:23 +08:00
|
|
|
import { popupAjaxError } from "discourse/lib/ajax-error";
|
2023-07-19 03:53:23 +08:00
|
|
|
import { inject as service } from "@ember/service";
|
2023-08-02 03:51:18 +08:00
|
|
|
import ApiKeyUrlsModal from "../components/modal/api-key-urls";
|
2019-11-05 22:10:23 +08:00
|
|
|
|
2023-03-15 17:42:12 +08:00
|
|
|
export default class AdminApiKeysShowController extends Controller.extend(
|
|
|
|
bufferedProperty("model")
|
|
|
|
) {
|
2023-07-19 03:53:23 +08:00
|
|
|
@service router;
|
2023-08-02 03:51:18 +08:00
|
|
|
@service modal;
|
2023-07-19 03:53:23 +08:00
|
|
|
|
2023-03-15 17:42:12 +08:00
|
|
|
@empty("model.id") isNew;
|
2019-11-05 22:10:23 +08:00
|
|
|
|
2023-03-15 17:42:12 +08:00
|
|
|
@action
|
|
|
|
saveDescription() {
|
|
|
|
const buffered = this.buffered;
|
|
|
|
const attrs = buffered.getProperties("description");
|
2019-11-05 22:10:23 +08:00
|
|
|
|
2023-03-15 17:42:12 +08:00
|
|
|
this.model
|
|
|
|
.save(attrs)
|
|
|
|
.then(() => {
|
|
|
|
this.set("editingDescription", false);
|
2019-11-05 22:10:23 +08:00
|
|
|
this.rollbackBuffer();
|
2023-03-15 17:42:12 +08:00
|
|
|
})
|
|
|
|
.catch(popupAjaxError);
|
|
|
|
}
|
2019-11-05 22:10:23 +08:00
|
|
|
|
2023-03-15 17:42:12 +08:00
|
|
|
@action
|
|
|
|
cancel() {
|
|
|
|
const id = this.get("userField.id");
|
|
|
|
if (isEmpty(id)) {
|
|
|
|
this.destroyAction(this.userField);
|
|
|
|
} else {
|
|
|
|
this.rollbackBuffer();
|
|
|
|
this.set("editing", false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
editDescription() {
|
|
|
|
this.toggleProperty("editingDescription");
|
|
|
|
if (!this.editingDescription) {
|
|
|
|
this.rollbackBuffer();
|
|
|
|
}
|
|
|
|
}
|
2019-11-05 22:10:23 +08:00
|
|
|
|
2023-03-15 17:42:12 +08:00
|
|
|
@action
|
|
|
|
revokeKey(key) {
|
|
|
|
key.revoke().catch(popupAjaxError);
|
|
|
|
}
|
2019-11-05 22:10:23 +08:00
|
|
|
|
2023-03-15 17:42:12 +08:00
|
|
|
@action
|
|
|
|
deleteKey(key) {
|
|
|
|
key
|
|
|
|
.destroyRecord()
|
2023-07-19 03:53:23 +08:00
|
|
|
.then(() => this.router.transitionTo("adminApiKeys.index"))
|
2023-03-15 17:42:12 +08:00
|
|
|
.catch(popupAjaxError);
|
|
|
|
}
|
2019-11-05 22:10:23 +08:00
|
|
|
|
2023-03-15 17:42:12 +08:00
|
|
|
@action
|
|
|
|
undoRevokeKey(key) {
|
|
|
|
key.undoRevoke().catch(popupAjaxError);
|
|
|
|
}
|
2020-08-19 02:12:04 +08:00
|
|
|
|
2023-03-15 17:42:12 +08:00
|
|
|
@action
|
|
|
|
showURLs(urls) {
|
2023-08-02 03:51:18 +08:00
|
|
|
this.modal.show(ApiKeyUrlsModal, {
|
2023-03-15 17:42:12 +08:00
|
|
|
model: {
|
|
|
|
urls,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|