Skip to content

Commit

Permalink
[#2404] Update middleware for optional CMS app URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
Bart van der Schoor authored and alextreme committed May 10, 2024
1 parent c1e0183 commit 517b033
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions src/open_inwoner/utils/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,27 @@ def get_always_pass_prefixes() -> tuple[str, ...]:
)


def get_app_pass_prefixes() -> tuple[str, ...]:
"""
Urls for apps that may not be active
"""
return (
"profile:registration_necessary",
"profile:email_verification_user",
)


def resolve_urls(urls) -> tuple[str, ...]:
ret = list()
for url in urls:
try:
ret.append(resolve_url(url))
except NoReverseMatch:
# support testing without cms app mounted
pass
return tuple(ret)


class BaseConditionalUserRedirectMiddleware(abc.ABC):
"""
Base class for middleware that redirects users to another view based on conditions
Expand Down Expand Up @@ -64,21 +85,15 @@ def get_pass_prefixes(self, request) -> tuple[str, ...]:
URL prefixes we're skipping without checking requires_redirect()
"""
prefixes = get_always_pass_prefixes()
prefixes += resolve_urls(get_app_pass_prefixes())
prefixes += (resolve_url(self.get_redirect_url(request)),)
prefixes += self.get_extra_pass_prefixes()
return prefixes

def get_extra_pass_prefixes(self) -> tuple[str, ...]:
prefixes = []
if self.extra_pass_prefixes:
for e in self.extra_pass_prefixes:
try:
prefixes.append(resolve_url(e))
prefixes.append(reverse("profile:registration_necessary"))
prefixes.append(reverse("profile:email_verification_user"))
except NoReverseMatch:
# support testing without cms app mounted
pass
return resolve_urls(self.extra_pass_prefixes)
return tuple(prefixes)

def __call__(self, request):
Expand Down

0 comments on commit 517b033

Please sign in to comment.