Skip to content

Commit

Permalink
fix issue with user_passes_test
Browse files Browse the repository at this point in the history
  • Loading branch information
xavfernandez committed Nov 29, 2024
1 parent 8041f47 commit 6bcbd50
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
7 changes: 7 additions & 0 deletions itou/utils/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,10 @@ class LoginNotRequiredMixin:
def as_view(cls, *args, **kwargs):
view = super().as_view(*args, **kwargs)
return login_not_required(view)


def unset_login_redirect(func):
for attr in ("login_url", "redirect_field_name"):
if hasattr(func, attr):
delattr(func, attr)
return func
5 changes: 4 additions & 1 deletion itou/www/apply/views/process_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from itou.rdv_insertion.api import get_api_credentials, get_invitation_status
from itou.rdv_insertion.models import Invitation, InvitationRequest, Participation
from itou.users.enums import Title
from itou.utils.auth import unset_login_redirect
from itou.utils.urls import get_safe_url
from itou.www.apply.forms import (
AcceptForm,
Expand Down Expand Up @@ -272,7 +273,9 @@ def details_for_company(request, job_application_id, template_name="apply/proces
return render(request, template_name, context)


@login_required
# XXX this is dirty
# Should we stop using user_passes_test ? Define our own ?
@unset_login_redirect
@user_passes_test(
lambda u: u.is_prescriber or u.is_employer,
login_url=reverse_lazy("search:employers_home"),
Expand Down

0 comments on commit 6bcbd50

Please sign in to comment.