stages/user_write: migrate to web

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-04-02 23:54:00 +02:00
parent 128af67011
commit 8ac82b97d3
3 changed files with 58 additions and 20 deletions

View File

@ -1,16 +0,0 @@
"""authentik flows write forms"""
from django import forms
from authentik.stages.user_write.models import UserWriteStage
class UserWriteStageForm(forms.ModelForm):
"""Form to write/edit UserWriteStage instances"""
class Meta:
model = UserWriteStage
fields = ["name"]
widgets = {
"name": forms.TextInput(),
}

View File

@ -26,10 +26,8 @@ class UserWriteStage(Stage):
return UserWriteStageView return UserWriteStageView
@property @property
def form(self) -> Type[ModelForm]: def component(self) -> str:
from authentik.stages.user_write.forms import UserWriteStageForm return "ak-stage-user-write-form"
return UserWriteStageForm
class Meta: class Meta:

View File

@ -0,0 +1,56 @@
import { UserWriteStage, 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-user-write-form")
export class UserWriteStageForm extends Form<UserWriteStage> {
set stageUUID(value: string) {
new StagesApi(DEFAULT_CONFIG).stagesUserWriteRead({
stageUuid: value,
}).then(stage => {
this.stage = stage;
});
}
@property({attribute: false})
stage?: UserWriteStage;
getSuccessMessage(): string {
if (this.stage) {
return gettext("Successfully updated stage.");
} else {
return gettext("Successfully created stage.");
}
}
send = (data: UserWriteStage): Promise<UserWriteStage> => {
if (this.stage) {
return new StagesApi(DEFAULT_CONFIG).stagesUserWriteUpdate({
stageUuid: this.stage.pk || "",
data: data
});
} else {
return new StagesApi(DEFAULT_CONFIG).stagesUserWriteCreate({
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>`;
}
}