import { CoreApi, PoliciesApi, Policy, PolicyTestResult } from "authentik-api"; import { gettext } from "django"; 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 { ifDefined } from "lit-html/directives/if-defined"; import "../../elements/forms/HorizontalFormElement"; import "../../elements/CodeMirror"; import { PolicyTest } from "authentik-api/src"; @customElement("ak-policy-test-form") export class PolicyTestForm extends Form { @property({attribute: false}) policy?: Policy; @property({ attribute: false}) result?: PolicyTestResult; getSuccessMessage(): string { return gettext("Successfully sent test-request."); } send = (data: PolicyTest): Promise => { return new PoliciesApi(DEFAULT_CONFIG).policiesAllTest({ policyUuid: this.policy?.pk || "", data: data }).then(result => this.result = result); }; renderResult(): TemplateResult { return html`
${this.result?.passing ? gettext("Yes") : gettext("No")}
    ${(this.result?.messages || []).length > 0 ? this.result?.messages?.map(m => { return html`
  • ${m}
  • `; }) : html`
  • -
  • `}
`; } renderForm(): TemplateResult { return html`
${this.result ? this.renderResult(): html``}
`; } }