2021-06-13 20:40:51 +00:00
|
|
|
import { Application, CoreApi, PolicyTestResult } from "authentik-api";
|
2021-05-26 10:05:17 +00:00
|
|
|
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")
|
2021-06-13 20:40:51 +00:00
|
|
|
export class ApplicationCheckAccessForm extends Form<number> {
|
2021-05-26 10:05:17 +00:00
|
|
|
|
|
|
|
@property({attribute: false})
|
|
|
|
application!: Application;
|
|
|
|
|
|
|
|
@property({ attribute: false})
|
|
|
|
result?: PolicyTestResult;
|
|
|
|
|
|
|
|
@property({ attribute: false})
|
2021-06-13 20:40:51 +00:00
|
|
|
request?: number;
|
2021-05-26 10:05:17 +00:00
|
|
|
|
|
|
|
getSuccessMessage(): string {
|
|
|
|
return t`Successfully sent test-request.`;
|
|
|
|
}
|
|
|
|
|
2021-06-13 20:40:51 +00:00
|
|
|
send = (data: number): Promise<PolicyTestResult> => {
|
2021-05-26 10:05:17 +00:00
|
|
|
this.request = data;
|
2021-06-13 20:40:51 +00:00
|
|
|
return new CoreApi(DEFAULT_CONFIG).coreApplicationsCheckAccessRetrieve({
|
2021-05-26 10:05:17 +00:00
|
|
|
slug: this.application?.slug,
|
2021-06-13 20:40:51 +00:00
|
|
|
forUser: data,
|
2021-05-26 10:05:17 +00:00
|
|
|
}).then(result => this.result = result);
|
|
|
|
};
|
|
|
|
|
|
|
|
renderResult(): TemplateResult {
|
|
|
|
return html`
|
|
|
|
<ak-form-element-horizontal
|
|
|
|
label=${t`Passing`}>
|
|
|
|
<div class="pf-c-form__group-label">
|
|
|
|
<div class="c-form__horizontal-group">
|
|
|
|
<span class="pf-c-form__label-text">${this.result?.passing ? t`Yes` : t`No`}</span>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</ak-form-element-horizontal>
|
|
|
|
<ak-form-element-horizontal
|
|
|
|
label=${t`Messages`}>
|
|
|
|
<div class="pf-c-form__group-label">
|
|
|
|
<div class="c-form__horizontal-group">
|
|
|
|
<ul>
|
|
|
|
${(this.result?.messages || []).length > 0 ?
|
|
|
|
this.result?.messages?.map(m => {
|
|
|
|
return html`<li><span class="pf-c-form__label-text">${m}</span></li>`;
|
|
|
|
}) :
|
|
|
|
html`<li><span class="pf-c-form__label-text">-</span></li>`}
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</ak-form-element-horizontal>`;
|
|
|
|
}
|
|
|
|
|
|
|
|
renderForm(): TemplateResult {
|
|
|
|
return html`<form class="pf-c-form pf-m-horizontal">
|
|
|
|
<ak-form-element-horizontal
|
|
|
|
label=${t`User`}
|
|
|
|
?required=${true}
|
|
|
|
name="forUser">
|
|
|
|
<select class="pf-c-form-control">
|
|
|
|
${until(new CoreApi(DEFAULT_CONFIG).coreUsersList({
|
|
|
|
ordering: "username",
|
|
|
|
}).then(users => {
|
|
|
|
return users.results.map(user => {
|
2021-06-13 20:40:51 +00:00
|
|
|
return html`<option ?selected=${user.pk.toString() === this.request?.toString()} value=${user.pk}>${user.username}</option>`;
|
2021-05-26 10:05:17 +00:00
|
|
|
});
|
|
|
|
}), html`<option>${t`Loading...`}</option>`)}
|
|
|
|
</select>
|
|
|
|
</ak-form-element-horizontal>
|
|
|
|
${this.result ? this.renderResult(): html``}
|
|
|
|
</form>`;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|