import YAML from "yaml"; import { t } from "@lingui/macro"; import { TemplateResult, html } from "lit"; import { customElement, property } from "lit/decorators.js"; import { until } from "lit/directives/until.js"; import { CoreApi, PoliciesApi, Policy, PolicyTestRequest, PolicyTestResult, } from "@goauthentik/api"; import { DEFAULT_CONFIG } from "../../api/Config"; import "../../elements/CodeMirror"; import { PFColor } from "../../elements/Label"; import { Form } from "../../elements/forms/Form"; import "../../elements/forms/HorizontalFormElement"; import { UserOption } from "../../elements/user/utils"; import { first } from "../../utils"; @customElement("ak-policy-test-form") export class PolicyTestForm extends Form { @property({ attribute: false }) policy?: Policy; @property({ attribute: false }) result?: PolicyTestResult; @property({ attribute: false }) request?: PolicyTestRequest; getSuccessMessage(): string { return t`Successfully sent test-request.`; } send = (data: PolicyTestRequest): Promise => { this.request = data; return new PoliciesApi(DEFAULT_CONFIG) .policiesAllTestCreate({ policyUuid: this.policy?.pk || "", policyTestRequest: data, }) .then((result) => (this.result = result)); }; 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`
>

${t`Set custom attributes using YAML or JSON.`}

${this.result ? this.renderResult() : html``}
`; } }