stages/dummy: migrate to web

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-04-03 00:49:15 +02:00
parent 1d72019645
commit 75d8641a38
3 changed files with 58 additions and 20 deletions

View File

@ -1,16 +0,0 @@
"""authentik administration forms"""
from django import forms
from authentik.stages.dummy.models import DummyStage
class DummyStageForm(forms.ModelForm):
"""Form to create/edit Dummy Stage"""
class Meta:
model = DummyStage
fields = ["name"]
widgets = {
"name": forms.TextInput(),
}

View File

@ -27,10 +27,8 @@ class DummyStage(Stage):
return DummyStageView return DummyStageView
@property @property
def form(self) -> Type[ModelForm]: def component(self) -> str:
from authentik.stages.dummy.forms import DummyStageForm return "ak-stage-dummy-form"
return DummyStageForm
class Meta: class Meta:

View File

@ -0,0 +1,56 @@
import { DummyStage, StagesApi } 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";
@customElement("ak-stage-dummy-form")
export class DummyStageForm extends Form<DummyStage> {
set stageUUID(value: string) {
new StagesApi(DEFAULT_CONFIG).stagesDummyRead({
stageUuid: value,
}).then(stage => {
this.stage = stage;
});
}
@property({attribute: false})
stage?: DummyStage;
getSuccessMessage(): string {
if (this.stage) {
return gettext("Successfully updated stage.");
} else {
return gettext("Successfully created stage.");
}
}
send = (data: DummyStage): Promise<DummyStage> => {
if (this.stage) {
return new StagesApi(DEFAULT_CONFIG).stagesDummyUpdate({
stageUuid: this.stage.pk || "",
data: data
});
} else {
return new StagesApi(DEFAULT_CONFIG).stagesDummyCreate({
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.stage?.name || "")}" class="pf-c-form-control" required>
</ak-form-element-horizontal>
</form>`;
}
}