2023-03-15 05:42:12 -04:00
|
|
|
import { action } from "@ember/object";
|
|
|
|
import { empty } from "@ember/object/computed";
|
2020-02-05 11:14:42 -05:00
|
|
|
import Controller from "@ember/controller";
|
2019-11-05 09:10:23 -05:00
|
|
|
import { bufferedProperty } from "discourse/mixins/buffered-content";
|
2020-02-05 11:14:42 -05:00
|
|
|
import { isEmpty } from "@ember/utils";
|
2019-11-05 09:10:23 -05:00
|
|
|
import { popupAjaxError } from "discourse/lib/ajax-error";
|
2020-08-18 14:12:04 -04:00
|
|
|
import showModal from "discourse/lib/show-modal";
|
2019-11-05 09:10:23 -05:00
|
|
|
|
2023-03-15 05:42:12 -04:00
|
|
|
export default class AdminApiKeysShowController extends Controller.extend(
|
|
|
|
bufferedProperty("model")
|
|
|
|
) {
|
|
|
|
@empty("model.id") isNew;
|
2019-11-05 09:10:23 -05:00
|
|
|
|
2023-03-15 05:42:12 -04:00
|
|
|
@action
|
|
|
|
saveDescription() {
|
|
|
|
const buffered = this.buffered;
|
|
|
|
const attrs = buffered.getProperties("description");
|
2019-11-05 09:10:23 -05:00
|
|
|
|
2023-03-15 05:42:12 -04:00
|
|
|
this.model
|
|
|
|
.save(attrs)
|
|
|
|
.then(() => {
|
|
|
|
this.set("editingDescription", false);
|
2019-11-05 09:10:23 -05:00
|
|
|
this.rollbackBuffer();
|
2023-03-15 05:42:12 -04:00
|
|
|
})
|
|
|
|
.catch(popupAjaxError);
|
|
|
|
}
|
2019-11-05 09:10:23 -05:00
|
|
|
|
2023-03-15 05:42:12 -04: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 09:10:23 -05:00
|
|
|
|
2023-03-15 05:42:12 -04:00
|
|
|
@action
|
|
|
|
revokeKey(key) {
|
|
|
|
key.revoke().catch(popupAjaxError);
|
|
|
|
}
|
2019-11-05 09:10:23 -05:00
|
|
|
|
2023-03-15 05:42:12 -04:00
|
|
|
@action
|
|
|
|
deleteKey(key) {
|
|
|
|
key
|
|
|
|
.destroyRecord()
|
|
|
|
.then(() => this.transitionToRoute("adminApiKeys.index"))
|
|
|
|
.catch(popupAjaxError);
|
|
|
|
}
|
2019-11-05 09:10:23 -05:00
|
|
|
|
2023-03-15 05:42:12 -04:00
|
|
|
@action
|
|
|
|
undoRevokeKey(key) {
|
|
|
|
key.undoRevoke().catch(popupAjaxError);
|
|
|
|
}
|
2020-08-18 14:12:04 -04:00
|
|
|
|
2023-03-15 05:42:12 -04:00
|
|
|
@action
|
|
|
|
showURLs(urls) {
|
|
|
|
return showModal("admin-api-key-urls", {
|
|
|
|
admin: true,
|
|
|
|
model: {
|
|
|
|
urls,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|