mirror of
https://github.com/discourse/discourse.git
synced 2024-11-29 00:48:33 +08:00
da6ddb638f
<img width="474" alt="Screenshot 2023-08-01 at 1 29 26 PM" src="https://github.com/discourse/discourse/assets/50783505/1a46901f-8231-46fb-8c36-cb441b7fd883">
78 lines
1.7 KiB
JavaScript
78 lines
1.7 KiB
JavaScript
import { action } from "@ember/object";
|
|
import { empty } from "@ember/object/computed";
|
|
import Controller from "@ember/controller";
|
|
import { bufferedProperty } from "discourse/mixins/buffered-content";
|
|
import { isEmpty } from "@ember/utils";
|
|
import { popupAjaxError } from "discourse/lib/ajax-error";
|
|
import { inject as service } from "@ember/service";
|
|
import ApiKeyUrlsModal from "../components/modal/api-key-urls";
|
|
|
|
export default class AdminApiKeysShowController extends Controller.extend(
|
|
bufferedProperty("model")
|
|
) {
|
|
@service router;
|
|
@service modal;
|
|
|
|
@empty("model.id") isNew;
|
|
|
|
@action
|
|
saveDescription() {
|
|
const buffered = this.buffered;
|
|
const attrs = buffered.getProperties("description");
|
|
|
|
this.model
|
|
.save(attrs)
|
|
.then(() => {
|
|
this.set("editingDescription", false);
|
|
this.rollbackBuffer();
|
|
})
|
|
.catch(popupAjaxError);
|
|
}
|
|
|
|
@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();
|
|
}
|
|
}
|
|
|
|
@action
|
|
revokeKey(key) {
|
|
key.revoke().catch(popupAjaxError);
|
|
}
|
|
|
|
@action
|
|
deleteKey(key) {
|
|
key
|
|
.destroyRecord()
|
|
.then(() => this.router.transitionTo("adminApiKeys.index"))
|
|
.catch(popupAjaxError);
|
|
}
|
|
|
|
@action
|
|
undoRevokeKey(key) {
|
|
key.undoRevoke().catch(popupAjaxError);
|
|
}
|
|
|
|
@action
|
|
showURLs(urls) {
|
|
this.modal.show(ApiKeyUrlsModal, {
|
|
model: {
|
|
urls,
|
|
},
|
|
});
|
|
}
|
|
}
|