diff --git a/authentik/__init__.py b/authentik/__init__.py index ae1e867e7..0343119d3 100644 --- a/authentik/__init__.py +++ b/authentik/__init__.py @@ -8,7 +8,10 @@ ENV_GIT_HASH_KEY = "GIT_BUILD_HASH" def get_build_hash(fallback: Optional[str] = None) -> str: """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: diff --git a/authentik/flows/api/flows.py b/authentik/flows/api/flows.py index e8babed02..5d84f493c 100644 --- a/authentik/flows/api/flows.py +++ b/authentik/flows/api/flows.py @@ -212,12 +212,30 @@ class FlowViewSet(UsedByMixin, ModelViewSet): ] body: list[DiagramElement] = [] 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( get_objects_for_user(request.user, "authentik_flows.view_flowstagebinding") .filter(target=flow) .order_by("order") ): + # First all policies bound to stages since they execute before stages for p_index, policy_binding in enumerate( get_objects_for_user(request.user, "authentik_policies.view_policybinding") .filter(target=stage_binding) @@ -228,14 +246,18 @@ class FlowViewSet(UsedByMixin, ModelViewSet): DiagramElement( f"stage_{s_index}_policy_{p_index}", "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( DiagramElement( f"stage_{s_index}", "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 diff --git a/authentik/flows/tests/test_api.py b/authentik/flows/tests/test_api.py index 4b1d173ba..c52fb975e 100644 --- a/authentik/flows/tests/test_api.py +++ b/authentik/flows/tests/test_api.py @@ -10,11 +10,11 @@ from authentik.policies.models import PolicyBinding from authentik.stages.dummy.models import DummyStage DIAGRAM_EXPECTED = """st=>start: Start -stage_0=>operation: Stage +stage_0=>operation: Stage (Dummy Stage) dummy1 -stage_1_policy_0=>condition: Policy -None -stage_1=>operation: Stage +stage_1_policy_0=>condition: Policy (Dummy Policy) +test +stage_1=>operation: Stage (Dummy Stage) dummy2 e=>end: End|future st(right)->stage_0 @@ -55,7 +55,7 @@ class TestFlowsAPI(APITestCase): slug="test-default-context", 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( target=flow, stage=DummyStage.objects.create(name="dummy1"), order=0