core: refactor MessageStage to not use dynamic class

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2022-10-26 20:01:42 +02:00
parent 9b6e07de17
commit f8fab14e1e
1 changed files with 22 additions and 36 deletions

View File

@ -45,22 +45,18 @@ class Action(Enum):
DENY = "deny"
def message_stage(message: str, level: int) -> StageView:
class MessageStage(StageView):
"""Show a pre-configured message after the flow is done"""
class MessageStage(StageView):
"""Show a pre-configured message after the flow is done"""
message: str
level: int
# pylint: disable=unused-argument
def get(self, request: HttpRequest, *args, **kwargs) -> HttpResponse:
"""Show a pre-configured message after the flow is done"""
message = getattr(self.executor.current_stage, "message", "")
level = getattr(self.executor.current_stage, "level", messages.SUCCESS)
messages.add_message(
self.request,
self.level,
self.message,
level,
message,
)
return self.executor.stage_ok()
@ -68,10 +64,6 @@ def message_stage(message: str, level: int) -> StageView:
"""Wrapper for post requests"""
return self.get(request)
MessageStage.message = message
MessageStage.level = level
return MessageStage
class SourceFlowManager:
"""Help sources decide what they should do after authorization. Based on source settings and
@ -284,14 +276,11 @@ class SourceFlowManager:
connection,
stages=[
in_memory_stage(
message_stage(
messages.SUCCESS,
_(
"Successfully authenticated with %(source)s!"
% {"source": self.source.name}
MessageStage,
message=_(
"Successfully authenticated with %(source)s!" % {"source": self.source.name}
),
)
)
],
**flow_kwargs,
)
@ -339,14 +328,11 @@ class SourceFlowManager:
connection,
stages=[
in_memory_stage(
message_stage(
messages.SUCCESS,
_(
"Successfully authenticated with %(source)s!"
% {"source": self.source.name}
MessageStage,
message=_(
"Successfully authenticated with %(source)s!" % {"source": self.source.name}
),
)
)
],
**{
PLAN_CONTEXT_PROMPT: delete_none_keys(self.enroll_info),