2021-03-30 15:53:43 +00:00
|
|
|
import { CoreApi, PropertyMapping, PropertymappingsApi, PropertyMappingTestResult } from "authentik-api";
|
2021-04-03 17:26:43 +00:00
|
|
|
import { t } from "@lingui/macro";
|
2021-03-30 15:53:43 +00:00
|
|
|
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-property-mapping-test-form")
|
|
|
|
export class PolicyTestForm extends Form<PolicyTest> {
|
|
|
|
|
|
|
|
@property({attribute: false})
|
|
|
|
mapping?: PropertyMapping;
|
|
|
|
|
|
|
|
@property({ attribute: false})
|
|
|
|
result?: PropertyMappingTestResult;
|
|
|
|
|
|
|
|
getSuccessMessage(): string {
|
2021-04-03 17:26:43 +00:00
|
|
|
return t`Successfully sent test-request.`;
|
2021-03-30 15:53:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
send = (data: PolicyTest): Promise<PropertyMappingTestResult> => {
|
|
|
|
return new PropertymappingsApi(DEFAULT_CONFIG).propertymappingsAllTest({
|
|
|
|
pmUuid: this.mapping?.pk || "",
|
|
|
|
data: data
|
|
|
|
}).then(result => this.result = result);
|
|
|
|
};
|
|
|
|
|
|
|
|
renderResult(): TemplateResult {
|
|
|
|
return html`<ak-form-element-horizontal
|
2021-04-03 17:26:43 +00:00
|
|
|
label=${t`Result`}>
|
2021-03-30 15:53:43 +00:00
|
|
|
${this.result?.successful ?
|
2021-03-30 16:20:48 +00:00
|
|
|
html`<ak-codemirror mode="javascript" ?readOnly=${true} value="${ifDefined(this.result?.result)}">
|
2021-03-30 15:53:43 +00:00
|
|
|
</ak-codemirror>`:
|
|
|
|
html`
|
|
|
|
<div class="pf-c-form__group-label">
|
|
|
|
<div class="c-form__horizontal-group">
|
|
|
|
<span class="pf-c-form__label-text">${this.result?.result}</span>
|
|
|
|
</div>
|
|
|
|
</div>`}
|
|
|
|
</ak-form-element-horizontal>`;
|
|
|
|
}
|
|
|
|
|
|
|
|
renderForm(): TemplateResult {
|
|
|
|
return html`<form class="pf-c-form pf-m-horizontal">
|
|
|
|
<ak-form-element-horizontal
|
2021-04-03 17:26:43 +00:00
|
|
|
label=${t`User`}
|
2021-03-30 15:53:43 +00:00
|
|
|
?required=${true}
|
|
|
|
name="user">
|
|
|
|
<select class="pf-c-form-control">
|
|
|
|
${until(new CoreApi(DEFAULT_CONFIG).coreUsersList({
|
|
|
|
ordering: "username",
|
|
|
|
}).then(users => {
|
|
|
|
return users.results.map(user => {
|
|
|
|
return html`<option value=${ifDefined(user.pk)}>${user.username}</option>`;
|
|
|
|
});
|
2021-04-03 22:24:06 +00:00
|
|
|
}), html`<option>${t`Loading...`}</option>`)}
|
2021-03-30 15:53:43 +00:00
|
|
|
</select>
|
|
|
|
</ak-form-element-horizontal>
|
|
|
|
<ak-form-element-horizontal
|
2021-04-03 17:26:43 +00:00
|
|
|
label=${t`Context`}
|
2021-03-30 15:53:43 +00:00
|
|
|
name="context">
|
|
|
|
<ak-codemirror mode="yaml">
|
|
|
|
</ak-codemirror>
|
|
|
|
</ak-form-element-horizontal>
|
|
|
|
${this.result ? this.renderResult(): html``}
|
|
|
|
</form>`;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|