import { CoreApi, PolicyTestRequest, PropertyMapping, PropertymappingsApi, PropertyMappingTestResult, } 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 { ifDefined } from "lit-html/directives/if-defined"; import "../../elements/forms/HorizontalFormElement"; import "../../elements/CodeMirror"; import YAML from "yaml"; import { first } from "../../utils"; @customElement("ak-property-mapping-test-form") export class PolicyTestForm extends Form { @property({ attribute: false }) mapping?: PropertyMapping; @property({ attribute: false }) result?: PropertyMappingTestResult; @property({ attribute: false }) request?: PolicyTestRequest; getSuccessMessage(): string { return t`Successfully sent test-request.`; } send = (data: PolicyTestRequest): Promise => { this.request = data; return new PropertymappingsApi(DEFAULT_CONFIG) .propertymappingsAllTestCreate({ pmUuid: this.mapping?.pk || "", policyTestRequest: data, formatResult: true, }) .then((result) => (this.result = result)); }; renderResult(): TemplateResult { return html` ${this.result?.successful ? html` ` : html`
${this.result?.result}
`}
`; } renderForm(): TemplateResult { return html`
> ${this.result ? this.renderResult() : html``}
`; } }