import Component from "@glimmer/component"; import { tracked } from "@glimmer/tracking"; import { Input } from "@ember/component"; import { concat, fn } from "@ember/helper"; import { on } from "@ember/modifier"; import { action, get } from "@ember/object"; import { LinkTo } from "@ember/routing"; import { service } from "@ember/service"; import BackButton from "discourse/components/back-button"; import DButton from "discourse/components/d-button"; import avatar from "discourse/helpers/avatar"; import formatDate from "discourse/helpers/format-date"; import { popupAjaxError } from "discourse/lib/ajax-error"; import { i18n } from "discourse-i18n"; import AdminFormRow from "admin/components/admin-form-row"; import ApiKeyUrlsModal from "admin/components/modal/api-key-urls"; import DTooltip from "float-kit/components/d-tooltip"; export default class AdminConfigAreasApiKeysShow extends Component { @service modal; @service router; @tracked editingDescription = false; @tracked scopes = this.args.apiKey.api_key_scopes; newDescription = ""; @action async revokeKey(key) { try { await key.revoke(); } catch (error) { popupAjaxError(error); } } @action async undoRevokeKey(key) { try { await key.undoRevoke(); } catch (error) { popupAjaxError(error); } } @action async deleteKey(key) { try { await key.destroyRecord(); this.router.transitionTo("adminApiKeys.index"); } catch (error) { popupAjaxError(error); } } @action async showURLs(urls) { await this.modal.show(ApiKeyUrlsModal, { model: { urls }, }); } @action toggleEditDescription() { this.editingDescription = !this.editingDescription; this.newDescription = this.args.apiKey.description; } @action async saveDescription() { try { await this.args.apiKey.save({ description: this.newDescription }); this.editingDescription = false; } catch (error) { popupAjaxError(error); } } @action setNewDescription(event) { this.newDescription = event.currentTarget.value; } }