Skip to content

Commit

Permalink
stages/password: use recovery flow from brand
Browse files Browse the repository at this point in the history
Signed-off-by: Jens Langhammer <[email protected]>
  • Loading branch information
BeryJu committed Nov 8, 2024
1 parent 556eca2 commit f4282d1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
8 changes: 4 additions & 4 deletions authentik/stages/password/stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
WithUserInfoChallenge,
)
from authentik.flows.exceptions import StageInvalidException
from authentik.flows.models import Flow, FlowDesignation, Stage
from authentik.flows.models import Flow, Stage
from authentik.flows.planner import PLAN_CONTEXT_PENDING_USER
from authentik.flows.stage import ChallengeStageView
from authentik.lib.utils.reflection import path_to_class
Expand Down Expand Up @@ -141,11 +141,11 @@ def get_challenge(self) -> Challenge:
"allow_show_password": self.executor.current_stage.allow_show_password,
}
)
recovery_flow = Flow.objects.filter(designation=FlowDesignation.RECOVERY)
if recovery_flow.exists():
recovery_flow: Flow | None = self.request.brand.flow_recovery
if recovery_flow:
recover_url = reverse(
"authentik_core:if-flow",
kwargs={"flow_slug": recovery_flow.first().slug},
kwargs={"flow_slug": recovery_flow.slug},
)
challenge.initial_data["recovery_url"] = self.request.build_absolute_uri(recover_url)
return challenge
Expand Down
5 changes: 4 additions & 1 deletion authentik/stages/password/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.core.exceptions import PermissionDenied
from django.urls import reverse

from authentik.core.tests.utils import create_test_admin_user, create_test_flow
from authentik.core.tests.utils import create_test_admin_user, create_test_brand, create_test_flow

Check warning on line 8 in authentik/stages/password/tests.py

View check run for this annotation

Codecov / codecov/patch

authentik/stages/password/tests.py#L8

Added line #L8 was not covered by tests
from authentik.flows.markers import StageMarker
from authentik.flows.models import FlowDesignation, FlowStageBinding
from authentik.flows.planner import PLAN_CONTEXT_PENDING_USER, FlowPlan
Expand Down Expand Up @@ -57,6 +57,9 @@ def test_without_user(self):
def test_recovery_flow_link(self):
"""Test link to the default recovery flow"""
flow = create_test_flow(designation=FlowDesignation.RECOVERY)
brand = create_test_brand()
brand.flow_recovery = flow
brand.save()

Check warning on line 62 in authentik/stages/password/tests.py

View check run for this annotation

Codecov / codecov/patch

authentik/stages/password/tests.py#L60-L62

Added lines #L60 - L62 were not covered by tests

plan = FlowPlan(flow_pk=self.flow.pk.hex, bindings=[self.binding], markers=[StageMarker()])
session = self.client.session
Expand Down

0 comments on commit f4282d1

Please sign in to comment.