web/admin: migrate policy forms
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
		| @ -1,31 +1,26 @@ | ||||
| import { AdminApi, EventMatcherPolicy, EventsApi, PoliciesApi } from "authentik-api"; | ||||
| import { t } from "@lingui/macro"; | ||||
| import { customElement, property } from "lit-element"; | ||||
| import { customElement } from "lit-element"; | ||||
| import { html, TemplateResult } from "lit-html"; | ||||
| import { DEFAULT_CONFIG } from "../../../api/Config"; | ||||
| import { Form } from "../../../elements/forms/Form"; | ||||
| import { ifDefined } from "lit-html/directives/if-defined"; | ||||
| import "../../../elements/forms/HorizontalFormElement"; | ||||
| import "../../../elements/forms/FormGroup"; | ||||
| import { until } from "lit-html/directives/until"; | ||||
| import { first } from "../../../utils"; | ||||
| import { ModelForm } from "../../../elements/forms/ModelForm"; | ||||
|  | ||||
| @customElement("ak-policy-event-matcher-form") | ||||
| export class EventMatcherPolicyForm extends Form<EventMatcherPolicy> { | ||||
| export class EventMatcherPolicyForm extends ModelForm<EventMatcherPolicy, string> { | ||||
|  | ||||
|     set policyUUID(value: string) { | ||||
|         new PoliciesApi(DEFAULT_CONFIG).policiesEventMatcherRead({ | ||||
|             policyUuid: value, | ||||
|         }).then(policy => { | ||||
|             this.policy = policy; | ||||
|     loadInstance(pk: string): Promise<EventMatcherPolicy> { | ||||
|         return new PoliciesApi(DEFAULT_CONFIG).policiesEventMatcherRead({ | ||||
|             policyUuid: pk, | ||||
|         }); | ||||
|     } | ||||
|  | ||||
|     @property({attribute: false}) | ||||
|     policy?: EventMatcherPolicy; | ||||
|  | ||||
|     getSuccessMessage(): string { | ||||
|         if (this.policy) { | ||||
|         if (this.instance) { | ||||
|             return t`Successfully updated policy.`; | ||||
|         } else { | ||||
|             return t`Successfully created policy.`; | ||||
| @ -33,9 +28,9 @@ export class EventMatcherPolicyForm extends Form<EventMatcherPolicy> { | ||||
|     } | ||||
|  | ||||
|     send = (data: EventMatcherPolicy): Promise<EventMatcherPolicy> => { | ||||
|         if (this.policy) { | ||||
|         if (this.instance) { | ||||
|             return new PoliciesApi(DEFAULT_CONFIG).policiesEventMatcherUpdate({ | ||||
|                 policyUuid: this.policy.pk || "", | ||||
|                 policyUuid: this.instance.pk || "", | ||||
|                 data: data | ||||
|             }); | ||||
|         } else { | ||||
| @ -54,11 +49,11 @@ export class EventMatcherPolicyForm extends Form<EventMatcherPolicy> { | ||||
|                 label=${t`Name`} | ||||
|                 ?required=${true} | ||||
|                 name="name"> | ||||
|                 <input type="text" value="${ifDefined(this.policy?.name || "")}" class="pf-c-form-control" required> | ||||
|                 <input type="text" value="${ifDefined(this.instance?.name || "")}" class="pf-c-form-control" required> | ||||
|             </ak-form-element-horizontal> | ||||
|             <ak-form-element-horizontal name="executionLogging"> | ||||
|                 <div class="pf-c-check"> | ||||
|                     <input type="checkbox" class="pf-c-check__input" ?checked=${first(this.policy?.executionLogging, false)}> | ||||
|                     <input type="checkbox" class="pf-c-check__input" ?checked=${first(this.instance?.executionLogging, false)}> | ||||
|                     <label class="pf-c-check__label"> | ||||
|                         ${t`Execution logging`} | ||||
|                     </label> | ||||
| @ -76,10 +71,10 @@ export class EventMatcherPolicyForm extends Form<EventMatcherPolicy> { | ||||
|                         label=${t`Action`} | ||||
|                         name="action"> | ||||
|                         <select class="pf-c-form-control"> | ||||
|                             <option value="" ?selected=${this.policy?.action === undefined}>---------</option> | ||||
|                             <option value="" ?selected=${this.instance?.action === undefined}>---------</option> | ||||
|                             ${until(new EventsApi(DEFAULT_CONFIG).eventsEventsActions().then(actions => { | ||||
|                                 return actions.map(action => { | ||||
|                                     return html`<option value=${action.component} ?selected=${this.policy?.action === action.component}>${action.name}</option>`; | ||||
|                                     return html`<option value=${action.component} ?selected=${this.instance?.action === action.component}>${action.name}</option>`; | ||||
|                                 }); | ||||
|                             }), html`<option>${t`Loading...`}</option>`)} | ||||
|                         </select> | ||||
| @ -88,17 +83,17 @@ export class EventMatcherPolicyForm extends Form<EventMatcherPolicy> { | ||||
|                     <ak-form-element-horizontal | ||||
|                         label=${t`Client IP`} | ||||
|                         name="clientIp"> | ||||
|                         <input type="text" value="${ifDefined(this.policy?.clientIp || "")}" class="pf-c-form-control"> | ||||
|                         <input type="text" value="${ifDefined(this.instance?.clientIp || "")}" class="pf-c-form-control"> | ||||
|                         <p class="pf-c-form__helper-text">${t`Matches Event's Client IP (strict matching, for network matching use an Expression Policy.`}</p> | ||||
|                     </ak-form-element-horizontal> | ||||
|                     <ak-form-element-horizontal | ||||
|                         label=${t`App`} | ||||
|                         name="app"> | ||||
|                         <select class="pf-c-form-control"> | ||||
|                             <option value="" ?selected=${this.policy?.app === undefined}>---------</option> | ||||
|                             <option value="" ?selected=${this.instance?.app === undefined}>---------</option> | ||||
|                             ${until(new AdminApi(DEFAULT_CONFIG).adminAppsList().then(apps => { | ||||
|                                 return apps.map(app => { | ||||
|                                     return html`<option value=${app.name} ?selected=${this.policy?.app === app.name}>${app.label}</option>`; | ||||
|                                     return html`<option value=${app.name} ?selected=${this.instance?.app === app.name}>${app.label}</option>`; | ||||
|                                 }); | ||||
|                             }), html`<option>${t`Loading...`}</option>`)} | ||||
|                         </select> | ||||
|  | ||||
| @ -1,30 +1,25 @@ | ||||
| import { PasswordExpiryPolicy, PoliciesApi } from "authentik-api"; | ||||
| import { t } from "@lingui/macro"; | ||||
| import { customElement, property } from "lit-element"; | ||||
| import { customElement } from "lit-element"; | ||||
| import { html, TemplateResult } from "lit-html"; | ||||
| import { DEFAULT_CONFIG } from "../../../api/Config"; | ||||
| import { Form } from "../../../elements/forms/Form"; | ||||
| import { ifDefined } from "lit-html/directives/if-defined"; | ||||
| import "../../../elements/forms/HorizontalFormElement"; | ||||
| import "../../../elements/forms/FormGroup"; | ||||
| import { first } from "../../../utils"; | ||||
| import { ModelForm } from "../../../elements/forms/ModelForm"; | ||||
|  | ||||
| @customElement("ak-policy-password-expiry-form") | ||||
| export class PasswordExpiryPolicyForm extends Form<PasswordExpiryPolicy> { | ||||
| export class PasswordExpiryPolicyForm extends ModelForm<PasswordExpiryPolicy, string> { | ||||
|  | ||||
|     set policyUUID(value: string) { | ||||
|         new PoliciesApi(DEFAULT_CONFIG).policiesPasswordExpiryRead({ | ||||
|             policyUuid: value, | ||||
|         }).then(policy => { | ||||
|             this.policy = policy; | ||||
|     loadInstance(pk: string): Promise<PasswordExpiryPolicy> { | ||||
|         return new PoliciesApi(DEFAULT_CONFIG).policiesPasswordExpiryRead({ | ||||
|             policyUuid: pk, | ||||
|         }); | ||||
|     } | ||||
|  | ||||
|     @property({attribute: false}) | ||||
|     policy?: PasswordExpiryPolicy; | ||||
|  | ||||
|     getSuccessMessage(): string { | ||||
|         if (this.policy) { | ||||
|         if (this.instance) { | ||||
|             return t`Successfully updated policy.`; | ||||
|         } else { | ||||
|             return t`Successfully created policy.`; | ||||
| @ -32,9 +27,9 @@ export class PasswordExpiryPolicyForm extends Form<PasswordExpiryPolicy> { | ||||
|     } | ||||
|  | ||||
|     send = (data: PasswordExpiryPolicy): Promise<PasswordExpiryPolicy> => { | ||||
|         if (this.policy) { | ||||
|         if (this.instance) { | ||||
|             return new PoliciesApi(DEFAULT_CONFIG).policiesPasswordExpiryUpdate({ | ||||
|                 policyUuid: this.policy.pk || "", | ||||
|                 policyUuid: this.instance.pk || "", | ||||
|                 data: data | ||||
|             }); | ||||
|         } else { | ||||
| @ -53,11 +48,11 @@ export class PasswordExpiryPolicyForm extends Form<PasswordExpiryPolicy> { | ||||
|                 label=${t`Name`} | ||||
|                 ?required=${true} | ||||
|                 name="name"> | ||||
|                 <input type="text" value="${ifDefined(this.policy?.name || "")}" class="pf-c-form-control" required> | ||||
|                 <input type="text" value="${ifDefined(this.instance?.name || "")}" class="pf-c-form-control" required> | ||||
|             </ak-form-element-horizontal> | ||||
|             <ak-form-element-horizontal name="executionLogging"> | ||||
|                 <div class="pf-c-check"> | ||||
|                     <input type="checkbox" class="pf-c-check__input" ?checked=${first(this.policy?.executionLogging, false)}> | ||||
|                     <input type="checkbox" class="pf-c-check__input" ?checked=${first(this.instance?.executionLogging, false)}> | ||||
|                     <label class="pf-c-check__label"> | ||||
|                         ${t`Execution logging`} | ||||
|                     </label> | ||||
| @ -75,11 +70,11 @@ export class PasswordExpiryPolicyForm extends Form<PasswordExpiryPolicy> { | ||||
|                         label=${t`Maximum age (in days)`} | ||||
|                         ?required=${true} | ||||
|                         name="days"> | ||||
|                         <input type="number" value="${ifDefined(this.policy?.days || "")}" class="pf-c-form-control" required> | ||||
|                         <input type="number" value="${ifDefined(this.instance?.days || "")}" class="pf-c-form-control" required> | ||||
|                     </ak-form-element-horizontal> | ||||
|                     <ak-form-element-horizontal name="denyOnly"> | ||||
|                         <div class="pf-c-check"> | ||||
|                             <input type="checkbox" class="pf-c-check__input" ?checked=${first(this.policy?.denyOnly, false)}> | ||||
|                             <input type="checkbox" class="pf-c-check__input" ?checked=${first(this.instance?.denyOnly, false)}> | ||||
|                             <label class="pf-c-check__label"> | ||||
|                                 ${t`Only fail the policy, don't invalidate user's password.`} | ||||
|                             </label> | ||||
|  | ||||
| @ -1,31 +1,26 @@ | ||||
| import { ExpressionPolicy, PoliciesApi } from "authentik-api"; | ||||
| import { t } from "@lingui/macro"; | ||||
| import { customElement, property } from "lit-element"; | ||||
| import { customElement } from "lit-element"; | ||||
| import { html, TemplateResult } from "lit-html"; | ||||
| import { DEFAULT_CONFIG } from "../../../api/Config"; | ||||
| import { Form } from "../../../elements/forms/Form"; | ||||
| 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 Form<ExpressionPolicy> { | ||||
| export class ExpressionPolicyForm extends ModelForm<ExpressionPolicy, string> { | ||||
|  | ||||
|     set policyUUID(value: string) { | ||||
|         new PoliciesApi(DEFAULT_CONFIG).policiesExpressionRead({ | ||||
|             policyUuid: value, | ||||
|         }).then(policy => { | ||||
|             this.policy = policy; | ||||
|     loadInstance(pk: string): Promise<ExpressionPolicy> { | ||||
|         return new PoliciesApi(DEFAULT_CONFIG).policiesExpressionRead({ | ||||
|             policyUuid: pk, | ||||
|         }); | ||||
|     } | ||||
|  | ||||
|     @property({attribute: false}) | ||||
|     policy?: ExpressionPolicy; | ||||
|  | ||||
|     getSuccessMessage(): string { | ||||
|         if (this.policy) { | ||||
|         if (this.instance) { | ||||
|             return t`Successfully updated policy.`; | ||||
|         } else { | ||||
|             return t`Successfully created policy.`; | ||||
| @ -33,9 +28,9 @@ export class ExpressionPolicyForm extends Form<ExpressionPolicy> { | ||||
|     } | ||||
|  | ||||
|     send = (data: ExpressionPolicy): Promise<ExpressionPolicy> => { | ||||
|         if (this.policy) { | ||||
|         if (this.instance) { | ||||
|             return new PoliciesApi(DEFAULT_CONFIG).policiesExpressionUpdate({ | ||||
|                 policyUuid: this.policy.pk || "", | ||||
|                 policyUuid: this.instance.pk || "", | ||||
|                 data: data | ||||
|             }); | ||||
|         } else { | ||||
| @ -54,11 +49,11 @@ export class ExpressionPolicyForm extends Form<ExpressionPolicy> { | ||||
|                 label=${t`Name`} | ||||
|                 ?required=${true} | ||||
|                 name="name"> | ||||
|                 <input type="text" value="${ifDefined(this.policy?.name || "")}" class="pf-c-form-control" required> | ||||
|                 <input type="text" value="${ifDefined(this.instance?.name || "")}" class="pf-c-form-control" required> | ||||
|             </ak-form-element-horizontal> | ||||
|             <ak-form-element-horizontal name="executionLogging"> | ||||
|                 <div class="pf-c-check"> | ||||
|                     <input type="checkbox" class="pf-c-check__input" ?checked=${first(this.policy?.executionLogging, false)}> | ||||
|                     <input type="checkbox" class="pf-c-check__input" ?checked=${first(this.instance?.executionLogging, false)}> | ||||
|                     <label class="pf-c-check__label"> | ||||
|                         ${t`Execution logging`} | ||||
|                     </label> | ||||
| @ -76,7 +71,7 @@ export class ExpressionPolicyForm extends Form<ExpressionPolicy> { | ||||
|                         label=${t`Expression`} | ||||
|                         ?required=${true} | ||||
|                         name="expression"> | ||||
|                         <ak-codemirror mode="python" value="${ifDefined(this.policy?.expression)}"> | ||||
|                         <ak-codemirror mode="python" value="${ifDefined(this.instance?.expression)}"> | ||||
|                         </ak-codemirror> | ||||
|                         <p class="pf-c-form__helper-text"> | ||||
|                             ${t`Expression using Python.`} | ||||
|  | ||||
| @ -1,30 +1,25 @@ | ||||
| import { HaveIBeenPwendPolicy, PoliciesApi } from "authentik-api"; | ||||
| import { t } from "@lingui/macro"; | ||||
| import { customElement, property } from "lit-element"; | ||||
| import { customElement } from "lit-element"; | ||||
| import { html, TemplateResult } from "lit-html"; | ||||
| import { DEFAULT_CONFIG } from "../../../api/Config"; | ||||
| import { Form } from "../../../elements/forms/Form"; | ||||
| import { ifDefined } from "lit-html/directives/if-defined"; | ||||
| import "../../../elements/forms/HorizontalFormElement"; | ||||
| import "../../../elements/forms/FormGroup"; | ||||
| import { first } from "../../../utils"; | ||||
| import { ModelForm } from "../../../elements/forms/ModelForm"; | ||||
|  | ||||
| @customElement("ak-policy-hibp-form") | ||||
| export class HaveIBeenPwnedPolicyForm extends Form<HaveIBeenPwendPolicy> { | ||||
| export class HaveIBeenPwnedPolicyForm extends ModelForm<HaveIBeenPwendPolicy, string> { | ||||
|  | ||||
|     set policyUUID(value: string) { | ||||
|         new PoliciesApi(DEFAULT_CONFIG).policiesHaveibeenpwnedRead({ | ||||
|             policyUuid: value, | ||||
|         }).then(policy => { | ||||
|             this.policy = policy; | ||||
|     loadInstance(pk: string): Promise<HaveIBeenPwendPolicy> { | ||||
|         return new PoliciesApi(DEFAULT_CONFIG).policiesHaveibeenpwnedRead({ | ||||
|             policyUuid: pk, | ||||
|         }); | ||||
|     } | ||||
|  | ||||
|     @property({attribute: false}) | ||||
|     policy?: HaveIBeenPwendPolicy; | ||||
|  | ||||
|     getSuccessMessage(): string { | ||||
|         if (this.policy) { | ||||
|         if (this.instance) { | ||||
|             return t`Successfully updated policy.`; | ||||
|         } else { | ||||
|             return t`Successfully created policy.`; | ||||
| @ -32,9 +27,9 @@ export class HaveIBeenPwnedPolicyForm extends Form<HaveIBeenPwendPolicy> { | ||||
|     } | ||||
|  | ||||
|     send = (data: HaveIBeenPwendPolicy): Promise<HaveIBeenPwendPolicy> => { | ||||
|         if (this.policy) { | ||||
|         if (this.instance) { | ||||
|             return new PoliciesApi(DEFAULT_CONFIG).policiesHaveibeenpwnedUpdate({ | ||||
|                 policyUuid: this.policy.pk || "", | ||||
|                 policyUuid: this.instance.pk || "", | ||||
|                 data: data | ||||
|             }); | ||||
|         } else { | ||||
| @ -54,11 +49,11 @@ export class HaveIBeenPwnedPolicyForm extends Form<HaveIBeenPwendPolicy> { | ||||
|                 label=${t`Name`} | ||||
|                 ?required=${true} | ||||
|                 name="name"> | ||||
|                 <input type="text" value="${ifDefined(this.policy?.name || "")}" class="pf-c-form-control" required> | ||||
|                 <input type="text" value="${ifDefined(this.instance?.name || "")}" class="pf-c-form-control" required> | ||||
|             </ak-form-element-horizontal> | ||||
|             <ak-form-element-horizontal name="executionLogging"> | ||||
|                 <div class="pf-c-check"> | ||||
|                     <input type="checkbox" class="pf-c-check__input" ?checked=${first(this.policy?.executionLogging, false)}> | ||||
|                     <input type="checkbox" class="pf-c-check__input" ?checked=${first(this.instance?.executionLogging, false)}> | ||||
|                     <label class="pf-c-check__label"> | ||||
|                         ${t`Execution logging`} | ||||
|                     </label> | ||||
| @ -76,14 +71,14 @@ export class HaveIBeenPwnedPolicyForm extends Form<HaveIBeenPwendPolicy> { | ||||
|                         label=${t`Password field`} | ||||
|                         ?required=${true} | ||||
|                         name="passwordField"> | ||||
|                         <input type="text" value="${ifDefined(this.policy?.passwordField || "password")}" class="pf-c-form-control" required> | ||||
|                         <input type="text" value="${ifDefined(this.instance?.passwordField || "password")}" class="pf-c-form-control" required> | ||||
|                         <p class="pf-c-form__helper-text">${t`Field key to check, field keys defined in Prompt stages are available.`}</p> | ||||
|                     </ak-form-element-horizontal> | ||||
|                     <ak-form-element-horizontal | ||||
|                         label=${t`Allowed count`} | ||||
|                         ?required=${true} | ||||
|                         name="allowedCount"> | ||||
|                         <input type="number" value="${first(this.policy?.allowedCount, 0)}" class="pf-c-form-control" required> | ||||
|                         <input type="number" value="${first(this.instance?.allowedCount, 0)}" class="pf-c-form-control" required> | ||||
|                         <p class="pf-c-form__helper-text">${t`Allow up to N occurrences in the HIBP database.`}</p> | ||||
|                     </ak-form-element-horizontal> | ||||
|                 </div> | ||||
|  | ||||
| @ -1,30 +1,25 @@ | ||||
| import { PasswordPolicy, PoliciesApi } from "authentik-api"; | ||||
| import { t } from "@lingui/macro"; | ||||
| import { customElement, property } from "lit-element"; | ||||
| import { customElement } from "lit-element"; | ||||
| import { html, TemplateResult } from "lit-html"; | ||||
| import { DEFAULT_CONFIG } from "../../../api/Config"; | ||||
| import { Form } from "../../../elements/forms/Form"; | ||||
| import { ifDefined } from "lit-html/directives/if-defined"; | ||||
| import "../../../elements/forms/HorizontalFormElement"; | ||||
| import "../../../elements/forms/FormGroup"; | ||||
| import { first } from "../../../utils"; | ||||
| import { ModelForm } from "../../../elements/forms/ModelForm"; | ||||
|  | ||||
| @customElement("ak-policy-password-form") | ||||
| export class PasswordPolicyForm extends Form<PasswordPolicy> { | ||||
| export class PasswordPolicyForm extends ModelForm<PasswordPolicy, string> { | ||||
|  | ||||
|     set policyUUID(value: string) { | ||||
|         new PoliciesApi(DEFAULT_CONFIG).policiesPasswordRead({ | ||||
|             policyUuid: value, | ||||
|         }).then(policy => { | ||||
|             this.policy = policy; | ||||
|     loadInstance(pk: string): Promise<PasswordPolicy> { | ||||
|         return new PoliciesApi(DEFAULT_CONFIG).policiesPasswordRead({ | ||||
|             policyUuid: pk, | ||||
|         }); | ||||
|     } | ||||
|  | ||||
|     @property({attribute: false}) | ||||
|     policy?: PasswordPolicy; | ||||
|  | ||||
|     getSuccessMessage(): string { | ||||
|         if (this.policy) { | ||||
|         if (this.instance) { | ||||
|             return t`Successfully updated policy.`; | ||||
|         } else { | ||||
|             return t`Successfully created policy.`; | ||||
| @ -32,9 +27,9 @@ export class PasswordPolicyForm extends Form<PasswordPolicy> { | ||||
|     } | ||||
|  | ||||
|     send = (data: PasswordPolicy): Promise<PasswordPolicy> => { | ||||
|         if (this.policy) { | ||||
|         if (this.instance) { | ||||
|             return new PoliciesApi(DEFAULT_CONFIG).policiesPasswordUpdate({ | ||||
|                 policyUuid: this.policy.pk || "", | ||||
|                 policyUuid: this.instance.pk || "", | ||||
|                 data: data | ||||
|             }); | ||||
|         } else { | ||||
| @ -53,11 +48,11 @@ export class PasswordPolicyForm extends Form<PasswordPolicy> { | ||||
|                 label=${t`Name`} | ||||
|                 ?required=${true} | ||||
|                 name="name"> | ||||
|                 <input type="text" value="${ifDefined(this.policy?.name || "")}" class="pf-c-form-control" required> | ||||
|                 <input type="text" value="${ifDefined(this.instance?.name || "")}" class="pf-c-form-control" required> | ||||
|             </ak-form-element-horizontal> | ||||
|             <ak-form-element-horizontal name="executionLogging"> | ||||
|                 <div class="pf-c-check"> | ||||
|                     <input type="checkbox" class="pf-c-check__input" ?checked=${first(this.policy?.executionLogging, false)}> | ||||
|                     <input type="checkbox" class="pf-c-check__input" ?checked=${first(this.instance?.executionLogging, false)}> | ||||
|                     <label class="pf-c-check__label"> | ||||
|                         ${t`Execution logging`} | ||||
|                     </label> | ||||
| @ -75,7 +70,7 @@ export class PasswordPolicyForm extends Form<PasswordPolicy> { | ||||
|                         label=${t`Password field`} | ||||
|                         ?required=${true} | ||||
|                         name="passwordField"> | ||||
|                         <input type="text" value="${ifDefined(this.policy?.passwordField || "password")}" class="pf-c-form-control" required> | ||||
|                         <input type="text" value="${ifDefined(this.instance?.passwordField || "password")}" class="pf-c-form-control" required> | ||||
|                         <p class="pf-c-form__helper-text">${t`Field key to check, field keys defined in Prompt stages are available.`}</p> | ||||
|                     </ak-form-element-horizontal> | ||||
|  | ||||
| @ -83,31 +78,31 @@ export class PasswordPolicyForm extends Form<PasswordPolicy> { | ||||
|                         label=${t`Minimum length`} | ||||
|                         ?required=${true} | ||||
|                         name="lengthMin"> | ||||
|                         <input type="number" value="${first(this.policy?.lengthMin, 10)}" class="pf-c-form-control" required> | ||||
|                         <input type="number" value="${first(this.instance?.lengthMin, 10)}" class="pf-c-form-control" required> | ||||
|                     </ak-form-element-horizontal> | ||||
|                     <ak-form-element-horizontal | ||||
|                         label=${t`Minimum amount of Uppercase Characters`} | ||||
|                         ?required=${true} | ||||
|                         name="amountUppercase"> | ||||
|                         <input type="number" value="${first(this.policy?.amountUppercase, 2)}" class="pf-c-form-control" required> | ||||
|                         <input type="number" value="${first(this.instance?.amountUppercase, 2)}" class="pf-c-form-control" required> | ||||
|                     </ak-form-element-horizontal> | ||||
|                     <ak-form-element-horizontal | ||||
|                         label=${t`Minimum amount of Lowercase Characters`} | ||||
|                         ?required=${true} | ||||
|                         name="amountLowercase"> | ||||
|                         <input type="number" value="${first(this.policy?.amountLowercase, 2)}" class="pf-c-form-control" required> | ||||
|                         <input type="number" value="${first(this.instance?.amountLowercase, 2)}" class="pf-c-form-control" required> | ||||
|                     </ak-form-element-horizontal> | ||||
|                     <ak-form-element-horizontal | ||||
|                         label=${t`Minimum amount of Symbols Characters`} | ||||
|                         ?required=${true} | ||||
|                         name="amountSymbols"> | ||||
|                         <input type="number" value="${first(this.policy?.amountSymbols, 2)}" class="pf-c-form-control" required> | ||||
|                         <input type="number" value="${first(this.instance?.amountSymbols, 2)}" class="pf-c-form-control" required> | ||||
|                     </ak-form-element-horizontal> | ||||
|                     <ak-form-element-horizontal | ||||
|                         label=${t`Error message`} | ||||
|                         ?required=${true} | ||||
|                         name="errorMessage"> | ||||
|                         <input type="text" value="${ifDefined(this.policy?.errorMessage)}" class="pf-c-form-control" required> | ||||
|                         <input type="text" value="${ifDefined(this.instance?.errorMessage)}" class="pf-c-form-control" required> | ||||
|                     </ak-form-element-horizontal> | ||||
|                 </div> | ||||
|             </ak-form-group> | ||||
| @ -120,7 +115,7 @@ export class PasswordPolicyForm extends Form<PasswordPolicy> { | ||||
|                         label=${t`Symbol charset`} | ||||
|                         ?required=${true} | ||||
|                         name="symbolCharset"> | ||||
|                         <input type="text" value="${ifDefined(this.policy?.symbolCharset || "!\\\"#$%&'()*+,-./:;<=>?@[]^_`{|}~ ")}" class="pf-c-form-control" required> | ||||
|                         <input type="text" value="${ifDefined(this.instance?.symbolCharset || "!\\\"#$%&'()*+,-./:;<=>?@[]^_`{|}~ ")}" class="pf-c-form-control" required> | ||||
|                         <p class="pf-c-form__helper-text">${t`Characters which are considered as symbols.`}</p> | ||||
|                     </ak-form-element-horizontal> | ||||
|                 </div> | ||||
|  | ||||
| @ -1,30 +1,25 @@ | ||||
| import { ReputationPolicy, PoliciesApi } from "authentik-api"; | ||||
| import { t } from "@lingui/macro"; | ||||
| import { customElement, property } from "lit-element"; | ||||
| import { customElement } from "lit-element"; | ||||
| import { html, TemplateResult } from "lit-html"; | ||||
| import { DEFAULT_CONFIG } from "../../../api/Config"; | ||||
| import { Form } from "../../../elements/forms/Form"; | ||||
| import { ifDefined } from "lit-html/directives/if-defined"; | ||||
| import "../../../elements/forms/HorizontalFormElement"; | ||||
| import "../../../elements/forms/FormGroup"; | ||||
| import { first } from "../../../utils"; | ||||
| import { ModelForm } from "../../../elements/forms/ModelForm"; | ||||
|  | ||||
| @customElement("ak-policy-reputation-form") | ||||
| export class ReputationPolicyForm extends Form<ReputationPolicy> { | ||||
| export class ReputationPolicyForm extends ModelForm<ReputationPolicy, string> { | ||||
|  | ||||
|     set policyUUID(value: string) { | ||||
|         new PoliciesApi(DEFAULT_CONFIG).policiesReputationRead({ | ||||
|             policyUuid: value, | ||||
|         }).then(policy => { | ||||
|             this.policy = policy; | ||||
|     loadInstance(pk: string): Promise<ReputationPolicy> { | ||||
|         return new PoliciesApi(DEFAULT_CONFIG).policiesReputationRead({ | ||||
|             policyUuid: pk, | ||||
|         }); | ||||
|     } | ||||
|  | ||||
|     @property({attribute: false}) | ||||
|     policy?: ReputationPolicy; | ||||
|  | ||||
|     getSuccessMessage(): string { | ||||
|         if (this.policy) { | ||||
|         if (this.instance) { | ||||
|             return t`Successfully updated policy.`; | ||||
|         } else { | ||||
|             return t`Successfully created policy.`; | ||||
| @ -32,9 +27,9 @@ export class ReputationPolicyForm extends Form<ReputationPolicy> { | ||||
|     } | ||||
|  | ||||
|     send = (data: ReputationPolicy): Promise<ReputationPolicy> => { | ||||
|         if (this.policy) { | ||||
|         if (this.instance) { | ||||
|             return new PoliciesApi(DEFAULT_CONFIG).policiesReputationUpdate({ | ||||
|                 policyUuid: this.policy.pk || "", | ||||
|                 policyUuid: this.instance.pk || "", | ||||
|                 data: data | ||||
|             }); | ||||
|         } else { | ||||
| @ -53,11 +48,11 @@ export class ReputationPolicyForm extends Form<ReputationPolicy> { | ||||
|                 label=${t`Name`} | ||||
|                 ?required=${true} | ||||
|                 name="name"> | ||||
|                 <input type="text" value="${ifDefined(this.policy?.name || "")}" class="pf-c-form-control" required> | ||||
|                 <input type="text" value="${ifDefined(this.instance?.name || "")}" class="pf-c-form-control" required> | ||||
|             </ak-form-element-horizontal> | ||||
|             <ak-form-element-horizontal name="executionLogging"> | ||||
|                 <div class="pf-c-check"> | ||||
|                     <input type="checkbox" class="pf-c-check__input" ?checked=${first(this.policy?.executionLogging, false)}> | ||||
|                     <input type="checkbox" class="pf-c-check__input" ?checked=${first(this.instance?.executionLogging, false)}> | ||||
|                     <label class="pf-c-check__label"> | ||||
|                         ${t`Execution logging`} | ||||
|                     </label> | ||||
| @ -73,7 +68,7 @@ export class ReputationPolicyForm extends Form<ReputationPolicy> { | ||||
|                 <div slot="body" class="pf-c-form"> | ||||
|                     <ak-form-element-horizontal name="checkIp"> | ||||
|                         <div class="pf-c-check"> | ||||
|                             <input type="checkbox" class="pf-c-check__input" ?checked=${first(this.policy?.checkIp, false)}> | ||||
|                             <input type="checkbox" class="pf-c-check__input" ?checked=${first(this.instance?.checkIp, false)}> | ||||
|                             <label class="pf-c-check__label"> | ||||
|                                 ${t`Check IP`} | ||||
|                             </label> | ||||
| @ -81,7 +76,7 @@ export class ReputationPolicyForm extends Form<ReputationPolicy> { | ||||
|                     </ak-form-element-horizontal> | ||||
|                     <ak-form-element-horizontal name="checkUsername"> | ||||
|                         <div class="pf-c-check"> | ||||
|                             <input type="checkbox" class="pf-c-check__input" ?checked=${first(this.policy?.checkUsername, false)}> | ||||
|                             <input type="checkbox" class="pf-c-check__input" ?checked=${first(this.instance?.checkUsername, false)}> | ||||
|                             <label class="pf-c-check__label"> | ||||
|                                 ${t`Check Username`} | ||||
|                             </label> | ||||
| @ -91,7 +86,7 @@ export class ReputationPolicyForm extends Form<ReputationPolicy> { | ||||
|                         label=${t`Threshold`} | ||||
|                         ?required=${true} | ||||
|                         name="threshold"> | ||||
|                         <input type="number" value="${ifDefined(this.policy?.threshold || -5)}" class="pf-c-form-control" required> | ||||
|                         <input type="number" value="${ifDefined(this.instance?.threshold || -5)}" class="pf-c-form-control" required> | ||||
|                     </ak-form-element-horizontal> | ||||
|                 </div> | ||||
|             </ak-form-group> | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Jens Langhammer
					Jens Langhammer