import { t } from "@lingui/macro"; import { CSSResult, TemplateResult, html } from "lit"; import { customElement, property } from "lit/decorators.js"; import { until } from "lit/directives/until.js"; import PFDescriptionList from "@patternfly/patternfly/components/DescriptionList/description-list.css"; import { Application, CoreApi, PolicyTestResult } from "@goauthentik/api"; import { DEFAULT_CONFIG } from "../../api/Config"; import { PFColor } from "../../elements/Label"; import { Form } from "../../elements/forms/Form"; import "../../elements/forms/HorizontalFormElement"; import { UserOption } from "../../elements/user/utils"; @customElement("ak-application-check-access-form") export class ApplicationCheckAccessForm extends Form<{ forUser: number }> { @property({ attribute: false }) application!: Application; @property({ attribute: false }) result?: PolicyTestResult; @property({ attribute: false }) request?: number; getSuccessMessage(): string { return t`Successfully sent test-request.`; } send = (data: { forUser: number }): Promise => { this.request = data.forUser; return new CoreApi(DEFAULT_CONFIG) .coreApplicationsCheckAccessRetrieve({ slug: this.application?.slug, forUser: data.forUser, }) .then((result) => (this.result = result)); }; resetForm(): void { super.resetForm(); this.result = undefined; } static get styles(): CSSResult[] { return super.styles.concat(PFDescriptionList); } renderResult(): TemplateResult { return html`
${this.result?.passing ? t`Yes` : t`No`}
    ${(this.result?.messages || []).length > 0 ? this.result?.messages?.map((m) => { return html`
  • ${m}
  • `; }) : html`
  • -
  • `}
${(this.result?.logMessages || []).length > 0 ? this.result?.logMessages?.map((m) => { return html`
${m.log_level}
${m.event}
`; }) : html`
${t`No log messages.`}
`}
`; } renderForm(): TemplateResult { return html`
${this.result ? this.renderResult() : html``}
`; } }