import { Application, CoreApi, PolicyTestResult } from "authentik-api"; import { t } from "@lingui/macro"; import { customElement, property } from "lit-element"; import { html, TemplateResult } from "lit-html"; import { DEFAULT_CONFIG } from "../../api/Config"; import { Form } from "../../elements/forms/Form"; import { until } from "lit-html/directives/until"; import "../../elements/forms/HorizontalFormElement"; @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; } 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`
  • -
  • `}
`; } renderForm(): TemplateResult { return html`
${this.result ? this.renderResult() : html``}
`; } }