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";
|
2020-08-19 02:12:04 +08:00
|
|
|
import showModal from "discourse/lib/show-modal";
|
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")
|
|
|
|
) {
|
|
|
|
@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()
|
|
|
|
.then(() => this.transitionToRoute("adminApiKeys.index"))
|
|
|
|
.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) {
|
|
|
|
return showModal("admin-api-key-urls", {
|
|
|
|
admin: true,
|
|
|
|
model: {
|
|
|
|
urls,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|