import { ExpressionPolicy, PoliciesApi } from "authentik-api"; import { t } from "@lingui/macro"; import { customElement } from "lit-element"; import { html, TemplateResult } from "lit-html"; import { DEFAULT_CONFIG } from "../../../api/Config"; import { ifDefined } from "lit-html/directives/if-defined"; import "../../../elements/forms/HorizontalFormElement"; import "../../../elements/forms/FormGroup"; import "../../../elements/CodeMirror"; import { first } from "../../../utils"; import { ModelForm } from "../../../elements/forms/ModelForm"; @customElement("ak-policy-expression-form") export class ExpressionPolicyForm extends ModelForm { loadInstance(pk: string): Promise { return new PoliciesApi(DEFAULT_CONFIG).policiesExpressionRetrieve({ policyUuid: pk, }); } getSuccessMessage(): string { if (this.instance) { return t`Successfully updated policy.`; } else { return t`Successfully created policy.`; } } send = (data: ExpressionPolicy): Promise => { if (this.instance) { return new PoliciesApi(DEFAULT_CONFIG).policiesExpressionUpdate({ policyUuid: this.instance.pk || "", expressionPolicyRequest: data }); } else { return new PoliciesApi(DEFAULT_CONFIG).policiesExpressionCreate({ expressionPolicyRequest: data }); } }; renderForm(): TemplateResult { return html`
${t`Executes the python snippet to determine whether to allow or deny a request.`}

${t`When this option is enabled, all executions of this policy will be logged. By default, only execution errors are logged.`}

${t`Policy-specific settings`}
`; } }