policies/reputation: migrate to web
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
parent
fcdc064cac
commit
6acfbb7d66
|
@ -1,22 +0,0 @@
|
||||||
"""authentik reputation request forms"""
|
|
||||||
from django import forms
|
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
|
|
||||||
from authentik.policies.forms import PolicyForm
|
|
||||||
from authentik.policies.reputation.models import ReputationPolicy
|
|
||||||
|
|
||||||
|
|
||||||
class ReputationPolicyForm(PolicyForm):
|
|
||||||
"""Form to edit ReputationPolicy"""
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
|
|
||||||
model = ReputationPolicy
|
|
||||||
fields = PolicyForm.Meta.fields + ["check_ip", "check_username", "threshold"]
|
|
||||||
widgets = {
|
|
||||||
"name": forms.TextInput(),
|
|
||||||
"value": forms.TextInput(),
|
|
||||||
}
|
|
||||||
labels = {
|
|
||||||
"check_ip": _("Check IP"),
|
|
||||||
}
|
|
|
@ -30,10 +30,8 @@ class ReputationPolicy(Policy):
|
||||||
return ReputationPolicySerializer
|
return ReputationPolicySerializer
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def form(self) -> Type[ModelForm]:
|
def component(self) -> str:
|
||||||
from authentik.policies.reputation.forms import ReputationPolicyForm
|
return "ak-policy-reputation-form"
|
||||||
|
|
||||||
return ReputationPolicyForm
|
|
||||||
|
|
||||||
def passes(self, request: PolicyRequest) -> PolicyResult:
|
def passes(self, request: PolicyRequest) -> PolicyResult:
|
||||||
remote_ip = get_client_ip(request.http_request) or "255.255.255.255"
|
remote_ip = get_client_ip(request.http_request) or "255.255.255.255"
|
||||||
|
|
|
@ -0,0 +1,95 @@
|
||||||
|
import { ReputationPolicy, PoliciesApi } from "authentik-api";
|
||||||
|
import { gettext } from "django";
|
||||||
|
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 { ifDefined } from "lit-html/directives/if-defined";
|
||||||
|
import "../../../elements/forms/HorizontalFormElement";
|
||||||
|
import "../../../elements/forms/FormGroup";
|
||||||
|
|
||||||
|
@customElement("ak-policy-reputation-form")
|
||||||
|
export class ReputationPolicyForm extends Form<ReputationPolicy> {
|
||||||
|
|
||||||
|
set policyUUID(value: string) {
|
||||||
|
new PoliciesApi(DEFAULT_CONFIG).policiesReputationRead({
|
||||||
|
policyUuid: value,
|
||||||
|
}).then(policy => {
|
||||||
|
this.policy = policy;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@property({attribute: false})
|
||||||
|
policy?: ReputationPolicy;
|
||||||
|
|
||||||
|
getSuccessMessage(): string {
|
||||||
|
if (this.policy) {
|
||||||
|
return gettext("Successfully updated policy.");
|
||||||
|
} else {
|
||||||
|
return gettext("Successfully created policy.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
send = (data: ReputationPolicy): Promise<ReputationPolicy> => {
|
||||||
|
if (this.policy) {
|
||||||
|
return new PoliciesApi(DEFAULT_CONFIG).policiesReputationUpdate({
|
||||||
|
policyUuid: this.policy.pk || "",
|
||||||
|
data: data
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
return new PoliciesApi(DEFAULT_CONFIG).policiesReputationCreate({
|
||||||
|
data: data
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
renderForm(): TemplateResult {
|
||||||
|
return html`<form class="pf-c-form pf-m-horizontal">
|
||||||
|
<ak-form-element-horizontal
|
||||||
|
label=${gettext("Name")}
|
||||||
|
?required=${true}
|
||||||
|
name="name">
|
||||||
|
<input type="text" value="${ifDefined(this.policy?.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=${this.policy?.executionLogging || false}>
|
||||||
|
<label class="pf-c-check__label">
|
||||||
|
${gettext("Execution logging")}
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<p class="pf-c-form__helper-text">${gettext("When this option is enabled, all executions of this policy will be logged. By default, only execution errors are logged.")}</p>
|
||||||
|
</ak-form-element-horizontal>
|
||||||
|
<ak-form-group .expanded=${true}>
|
||||||
|
<span slot="header">
|
||||||
|
${gettext("Policy-specific settings")}
|
||||||
|
</span>
|
||||||
|
<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=${this.policy?.checkIp || false}>
|
||||||
|
<label class="pf-c-check__label">
|
||||||
|
${gettext("Check IP")}
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</ak-form-element-horizontal>
|
||||||
|
<ak-form-element-horizontal name="checkUsername">
|
||||||
|
<div class="pf-c-check">
|
||||||
|
<input type="checkbox" class="pf-c-check__input" ?checked=${this.policy?.checkUsername || false}>
|
||||||
|
<label class="pf-c-check__label">
|
||||||
|
${gettext("Check Username")}
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</ak-form-element-horizontal>
|
||||||
|
<ak-form-element-horizontal
|
||||||
|
label=${gettext("Threshold")}
|
||||||
|
?required=${true}
|
||||||
|
name="threshold">
|
||||||
|
<input type="number" value="${ifDefined(this.policy?.threshold || -5)}" class="pf-c-form-control" required>
|
||||||
|
</ak-form-element-horizontal>
|
||||||
|
</div>
|
||||||
|
</ak-form-group>
|
||||||
|
</form>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Reference in New Issue