flows: handle flow title formatting error better, add user to flow title context
This commit is contained in:
parent
6f0fa731c0
commit
8242b09394
|
@ -120,9 +120,12 @@ class ChallengeStageView(StageView):
|
||||||
return self.executor.flow.title
|
return self.executor.flow.title
|
||||||
try:
|
try:
|
||||||
return self.executor.flow.title % {
|
return self.executor.flow.title % {
|
||||||
"app": self.executor.plan.context.get(PLAN_CONTEXT_APPLICATION, "")
|
"app": self.executor.plan.context.get(PLAN_CONTEXT_APPLICATION, ""),
|
||||||
|
"user": self.get_pending_user(for_display=True),
|
||||||
}
|
}
|
||||||
except ValueError:
|
# pylint: disable=broad-except
|
||||||
|
except Exception as exc:
|
||||||
|
LOGGER.warning("failed to template title", exc=exc)
|
||||||
return self.executor.flow.title
|
return self.executor.flow.title
|
||||||
|
|
||||||
def _get_challenge(self, *args, **kwargs) -> Challenge:
|
def _get_challenge(self, *args, **kwargs) -> Challenge:
|
||||||
|
@ -131,25 +134,29 @@ class ChallengeStageView(StageView):
|
||||||
description=self.__class__.__name__,
|
description=self.__class__.__name__,
|
||||||
):
|
):
|
||||||
challenge = self.get_challenge(*args, **kwargs)
|
challenge = self.get_challenge(*args, **kwargs)
|
||||||
if "flow_info" not in challenge.initial_data:
|
with Hub.current.start_span(
|
||||||
flow_info = ContextualFlowInfo(
|
op="authentik.flow.stage._get_challenge",
|
||||||
data={
|
description=self.__class__.__name__,
|
||||||
"title": self.format_title(),
|
):
|
||||||
"background": self.executor.flow.background_url,
|
if "flow_info" not in challenge.initial_data:
|
||||||
"cancel_url": reverse("authentik_flows:cancel"),
|
flow_info = ContextualFlowInfo(
|
||||||
}
|
data={
|
||||||
)
|
"title": self.format_title(),
|
||||||
flow_info.is_valid()
|
"background": self.executor.flow.background_url,
|
||||||
challenge.initial_data["flow_info"] = flow_info.data
|
"cancel_url": reverse("authentik_flows:cancel"),
|
||||||
if isinstance(challenge, WithUserInfoChallenge):
|
}
|
||||||
# If there's a pending user, update the `username` field
|
)
|
||||||
# this field is only used by password managers.
|
flow_info.is_valid()
|
||||||
# If there's no user set, an error is raised later.
|
challenge.initial_data["flow_info"] = flow_info.data
|
||||||
if user := self.get_pending_user(for_display=True):
|
if isinstance(challenge, WithUserInfoChallenge):
|
||||||
challenge.initial_data["pending_user"] = user.username
|
# If there's a pending user, update the `username` field
|
||||||
challenge.initial_data["pending_user_avatar"] = DEFAULT_AVATAR
|
# this field is only used by password managers.
|
||||||
if not isinstance(user, AnonymousUser):
|
# If there's no user set, an error is raised later.
|
||||||
challenge.initial_data["pending_user_avatar"] = user.avatar
|
if user := self.get_pending_user(for_display=True):
|
||||||
|
challenge.initial_data["pending_user"] = user.username
|
||||||
|
challenge.initial_data["pending_user_avatar"] = DEFAULT_AVATAR
|
||||||
|
if not isinstance(user, AnonymousUser):
|
||||||
|
challenge.initial_data["pending_user_avatar"] = user.avatar
|
||||||
return challenge
|
return challenge
|
||||||
|
|
||||||
def get_challenge(self, *args, **kwargs) -> Challenge:
|
def get_challenge(self, *args, **kwargs) -> Challenge:
|
||||||
|
|
Reference in New Issue