admin: add flow-stage-bindings, add policy-bindings, add prompts

This commit is contained in:
Jens Langhammer
2020-05-16 19:55:59 +02:00
parent df1cb88abc
commit e68352b09c
17 changed files with 651 additions and 34 deletions

View File

@ -19,6 +19,25 @@ class PromptStageForm(forms.ModelForm):
}
class PromptAdminForm(forms.ModelForm):
"""Form to edit Prompt instances for admins"""
class Meta:
model = Prompt
fields = [
"field_key",
"label",
"type",
"required",
"placeholder",
]
widgets = {
"label": forms.TextInput(),
"placeholder": forms.TextInput(),
}
class PromptForm(forms.Form):
"""Dynamically created form based on PromptStage"""

View File

@ -29,12 +29,17 @@ class UserWriteStageView(AuthenticationStage):
user = self.executor.plan.context[PLAN_CONTEXT_PENDING_USER]
for key, value in data.items():
setter_name = f"set_{key}"
# Check if user has a setter for this key, like set_password
if hasattr(user, setter_name):
setter = getattr(user, setter_name)
if callable(setter):
setter(value)
else:
# User has this key already
elif hasattr(user, key):
setattr(user, key, value)
# Otherwise we just save it as custom attribute
else:
user.attributes[key] = value
user.save()
LOGGER.debug(
"Updated existing user", user=user, flow_slug=self.executor.flow.slug,