2021-04-03 17:26:43 +00:00
|
|
|
import { t } from "@lingui/macro";
|
2021-09-21 09:31:37 +00:00
|
|
|
|
2021-10-28 07:48:51 +00:00
|
|
|
import { TemplateResult, html } from "lit";
|
2021-11-04 21:34:48 +00:00
|
|
|
import { customElement } from "lit/decorators.js";
|
|
|
|
import { ifDefined } from "lit/directives/if-defined.js";
|
2021-09-21 09:31:37 +00:00
|
|
|
|
|
|
|
import { DummyPolicy, PoliciesApi } from "@goauthentik/api";
|
|
|
|
|
|
|
|
import { DEFAULT_CONFIG } from "../../../api/Config";
|
2021-04-02 14:31:53 +00:00
|
|
|
import "../../../elements/forms/FormGroup";
|
2021-09-21 09:31:37 +00:00
|
|
|
import "../../../elements/forms/HorizontalFormElement";
|
2021-05-11 10:05:30 +00:00
|
|
|
import { ModelForm } from "../../../elements/forms/ModelForm";
|
2021-09-21 09:31:37 +00:00
|
|
|
import { first } from "../../../utils";
|
2021-04-02 14:31:53 +00:00
|
|
|
|
|
|
|
@customElement("ak-policy-dummy-form")
|
2021-05-11 10:05:30 +00:00
|
|
|
export class DummyPolicyForm extends ModelForm<DummyPolicy, string> {
|
|
|
|
loadInstance(pk: string): Promise<DummyPolicy> {
|
2021-05-16 12:43:42 +00:00
|
|
|
return new PoliciesApi(DEFAULT_CONFIG).policiesDummyRetrieve({
|
2021-05-11 10:05:30 +00:00
|
|
|
policyUuid: pk,
|
2021-04-02 14:31:53 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
getSuccessMessage(): string {
|
2021-05-11 10:05:30 +00:00
|
|
|
if (this.instance) {
|
2021-04-03 17:26:43 +00:00
|
|
|
return t`Successfully updated policy.`;
|
2021-04-02 14:31:53 +00:00
|
|
|
} else {
|
2021-04-03 17:26:43 +00:00
|
|
|
return t`Successfully created policy.`;
|
2021-04-02 14:31:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
send = (data: DummyPolicy): Promise<DummyPolicy> => {
|
2021-05-11 10:05:30 +00:00
|
|
|
if (this.instance) {
|
2021-04-02 14:31:53 +00:00
|
|
|
return new PoliciesApi(DEFAULT_CONFIG).policiesDummyUpdate({
|
2021-05-11 10:05:30 +00:00
|
|
|
policyUuid: this.instance.pk || "",
|
2021-08-03 15:52:21 +00:00
|
|
|
dummyPolicyRequest: data,
|
2021-04-02 14:31:53 +00:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
return new PoliciesApi(DEFAULT_CONFIG).policiesDummyCreate({
|
2021-08-03 15:52:21 +00:00
|
|
|
dummyPolicyRequest: data,
|
2021-04-02 14:31:53 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
renderForm(): TemplateResult {
|
|
|
|
return html`<form class="pf-c-form pf-m-horizontal">
|
2021-04-10 10:37:08 +00:00
|
|
|
<div class="form-help-text">
|
|
|
|
${t`A policy used for testing. Always returns the same result as specified below after waiting a random duration.`}
|
|
|
|
</div>
|
2021-08-03 15:52:21 +00:00
|
|
|
<ak-form-element-horizontal label=${t`Name`} ?required=${true} name="name">
|
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
value="${ifDefined(this.instance?.name || "")}"
|
|
|
|
class="pf-c-form-control"
|
|
|
|
required
|
|
|
|
/>
|
2021-04-02 14:31:53 +00:00
|
|
|
</ak-form-element-horizontal>
|
|
|
|
<ak-form-element-horizontal name="executionLogging">
|
|
|
|
<div class="pf-c-check">
|
2021-08-03 15:52:21 +00:00
|
|
|
<input
|
|
|
|
type="checkbox"
|
|
|
|
class="pf-c-check__input"
|
|
|
|
?checked=${first(this.instance?.executionLogging, false)}
|
|
|
|
/>
|
|
|
|
<label class="pf-c-check__label"> ${t`Execution logging`} </label>
|
2021-04-02 14:31:53 +00:00
|
|
|
</div>
|
2021-04-10 10:37:08 +00:00
|
|
|
<p class="pf-c-form__helper-text">
|
|
|
|
${t`When this option is enabled, all executions of this policy will be logged. By default, only execution errors are logged.`}
|
|
|
|
</p>
|
2021-04-02 14:31:53 +00:00
|
|
|
</ak-form-element-horizontal>
|
|
|
|
<ak-form-group .expanded=${true}>
|
2021-08-03 15:52:21 +00:00
|
|
|
<span slot="header"> ${t`Policy-specific settings`} </span>
|
2021-04-02 14:31:53 +00:00
|
|
|
<div slot="body" class="pf-c-form">
|
|
|
|
<ak-form-element-horizontal name="result">
|
|
|
|
<div class="pf-c-check">
|
2021-08-03 15:52:21 +00:00
|
|
|
<input
|
|
|
|
type="checkbox"
|
|
|
|
class="pf-c-check__input"
|
|
|
|
?checked=${first(this.instance?.result, false)}
|
|
|
|
/>
|
|
|
|
<label class="pf-c-check__label"> ${t`Pass policy?`} </label>
|
2021-04-02 14:31:53 +00:00
|
|
|
</div>
|
|
|
|
</ak-form-element-horizontal>
|
|
|
|
<ak-form-element-horizontal
|
2021-04-03 17:26:43 +00:00
|
|
|
label=${t`Wait (min)`}
|
2021-04-02 14:31:53 +00:00
|
|
|
?required=${true}
|
2021-08-03 15:52:21 +00:00
|
|
|
name="waitMin"
|
|
|
|
>
|
|
|
|
<input
|
|
|
|
type="number"
|
|
|
|
value="${first(this.instance?.waitMin, 1)}"
|
|
|
|
class="pf-c-form-control"
|
|
|
|
required
|
|
|
|
/>
|
|
|
|
<p class="pf-c-form__helper-text">
|
|
|
|
${t`The policy takes a random time to execute. This controls the minimum time it will take.`}
|
|
|
|
</p>
|
2021-04-02 14:31:53 +00:00
|
|
|
</ak-form-element-horizontal>
|
|
|
|
<ak-form-element-horizontal
|
2021-04-03 17:26:43 +00:00
|
|
|
label=${t`Wait (max)`}
|
2021-04-02 14:31:53 +00:00
|
|
|
?required=${true}
|
2021-08-03 15:52:21 +00:00
|
|
|
name="waitMax"
|
|
|
|
>
|
|
|
|
<input
|
|
|
|
type="number"
|
|
|
|
value="${first(this.instance?.waitMax, 5)}"
|
|
|
|
class="pf-c-form-control"
|
|
|
|
required
|
|
|
|
/>
|
2021-04-02 14:31:53 +00:00
|
|
|
</ak-form-element-horizontal>
|
|
|
|
</div>
|
|
|
|
</ak-form-group>
|
|
|
|
</form>`;
|
|
|
|
}
|
|
|
|
}
|