flows: add types to diagrams (#2902)
* add policy and stage types to diagram Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org> * show policies bound to the root flow Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org> * fix get_build_hash being empty Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org> * update tests Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
parent
3d52266773
commit
d570feffac
|
@ -8,7 +8,10 @@ ENV_GIT_HASH_KEY = "GIT_BUILD_HASH"
|
||||||
|
|
||||||
def get_build_hash(fallback: Optional[str] = None) -> str:
|
def get_build_hash(fallback: Optional[str] = None) -> str:
|
||||||
"""Get build hash"""
|
"""Get build hash"""
|
||||||
return environ.get(ENV_GIT_HASH_KEY, fallback if fallback else "")
|
build_hash = environ.get(ENV_GIT_HASH_KEY, fallback if fallback else "")
|
||||||
|
if build_hash == "" and fallback:
|
||||||
|
return fallback
|
||||||
|
return build_hash
|
||||||
|
|
||||||
|
|
||||||
def get_full_version() -> str:
|
def get_full_version() -> str:
|
||||||
|
|
|
@ -212,12 +212,30 @@ class FlowViewSet(UsedByMixin, ModelViewSet):
|
||||||
]
|
]
|
||||||
body: list[DiagramElement] = []
|
body: list[DiagramElement] = []
|
||||||
footer = []
|
footer = []
|
||||||
# First, collect all elements we need
|
# Collect all elements we need
|
||||||
|
# First, policies bound to the flow itself
|
||||||
|
for p_index, policy_binding in enumerate(
|
||||||
|
get_objects_for_user(request.user, "authentik_policies.view_policybinding")
|
||||||
|
.filter(target=flow)
|
||||||
|
.exclude(policy__isnull=True)
|
||||||
|
.order_by("order")
|
||||||
|
):
|
||||||
|
body.append(
|
||||||
|
DiagramElement(
|
||||||
|
f"flow_policy_{p_index}",
|
||||||
|
"condition",
|
||||||
|
_("Policy (%(type)s)" % {"type": policy_binding.policy._meta.verbose_name})
|
||||||
|
+ "\n"
|
||||||
|
+ policy_binding.policy.name,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
# Collect all stages
|
||||||
for s_index, stage_binding in enumerate(
|
for s_index, stage_binding in enumerate(
|
||||||
get_objects_for_user(request.user, "authentik_flows.view_flowstagebinding")
|
get_objects_for_user(request.user, "authentik_flows.view_flowstagebinding")
|
||||||
.filter(target=flow)
|
.filter(target=flow)
|
||||||
.order_by("order")
|
.order_by("order")
|
||||||
):
|
):
|
||||||
|
# First all policies bound to stages since they execute before stages
|
||||||
for p_index, policy_binding in enumerate(
|
for p_index, policy_binding in enumerate(
|
||||||
get_objects_for_user(request.user, "authentik_policies.view_policybinding")
|
get_objects_for_user(request.user, "authentik_policies.view_policybinding")
|
||||||
.filter(target=stage_binding)
|
.filter(target=stage_binding)
|
||||||
|
@ -228,14 +246,18 @@ class FlowViewSet(UsedByMixin, ModelViewSet):
|
||||||
DiagramElement(
|
DiagramElement(
|
||||||
f"stage_{s_index}_policy_{p_index}",
|
f"stage_{s_index}_policy_{p_index}",
|
||||||
"condition",
|
"condition",
|
||||||
f"Policy\n{policy_binding.policy.name}",
|
_("Policy (%(type)s)" % {"type": policy_binding.policy._meta.verbose_name})
|
||||||
|
+ "\n"
|
||||||
|
+ policy_binding.policy.name,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
body.append(
|
body.append(
|
||||||
DiagramElement(
|
DiagramElement(
|
||||||
f"stage_{s_index}",
|
f"stage_{s_index}",
|
||||||
"operation",
|
"operation",
|
||||||
f"Stage\n{stage_binding.stage.name}",
|
_("Stage (%(type)s)" % {"type": stage_binding.stage._meta.verbose_name})
|
||||||
|
+ "\n"
|
||||||
|
+ stage_binding.stage.name,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
# If the 2nd last element is a policy, we need to have an item to point to
|
# If the 2nd last element is a policy, we need to have an item to point to
|
||||||
|
|
|
@ -10,11 +10,11 @@ from authentik.policies.models import PolicyBinding
|
||||||
from authentik.stages.dummy.models import DummyStage
|
from authentik.stages.dummy.models import DummyStage
|
||||||
|
|
||||||
DIAGRAM_EXPECTED = """st=>start: Start
|
DIAGRAM_EXPECTED = """st=>start: Start
|
||||||
stage_0=>operation: Stage
|
stage_0=>operation: Stage (Dummy Stage)
|
||||||
dummy1
|
dummy1
|
||||||
stage_1_policy_0=>condition: Policy
|
stage_1_policy_0=>condition: Policy (Dummy Policy)
|
||||||
None
|
test
|
||||||
stage_1=>operation: Stage
|
stage_1=>operation: Stage (Dummy Stage)
|
||||||
dummy2
|
dummy2
|
||||||
e=>end: End|future
|
e=>end: End|future
|
||||||
st(right)->stage_0
|
st(right)->stage_0
|
||||||
|
@ -55,7 +55,7 @@ class TestFlowsAPI(APITestCase):
|
||||||
slug="test-default-context",
|
slug="test-default-context",
|
||||||
designation=FlowDesignation.AUTHENTICATION,
|
designation=FlowDesignation.AUTHENTICATION,
|
||||||
)
|
)
|
||||||
false_policy = DummyPolicy.objects.create(result=False, wait_min=1, wait_max=2)
|
false_policy = DummyPolicy.objects.create(name="test", result=False, wait_min=1, wait_max=2)
|
||||||
|
|
||||||
FlowStageBinding.objects.create(
|
FlowStageBinding.objects.create(
|
||||||
target=flow, stage=DummyStage.objects.create(name="dummy1"), order=0
|
target=flow, stage=DummyStage.objects.create(name="dummy1"), order=0
|
||||||
|
|
Reference in New Issue