Skip to content

Commit

Permalink
apply: Improve redirect after internal transfer
Browse files Browse the repository at this point in the history
By re-using the back_url from the session, we keep the filters from the
list if there were any
  • Loading branch information
tonial committed Oct 4, 2024
1 parent 2a8b3d0 commit a84aa89
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
10 changes: 8 additions & 2 deletions itou/www/apply/views/process_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@
logger = logging.getLogger(__name__)


JOB_APP_DETAILS_FOR_COMPANY_BACK_URL_KEY = "JOB_APP_DETAILS_FOR_COMPANY-BACK_URL-%d"


def check_waiting_period(job_application):
"""
This should be an edge case.
Expand Down Expand Up @@ -190,7 +193,7 @@ def details_for_company(request, job_application_id, template_name="apply/proces
)

# get back_url from GET params or session or fallback value
session_key = f"JOB_APP_DETAILS_FOR_COMPANY-BACK_URL-{job_application.pk}"
session_key = JOB_APP_DETAILS_FOR_COMPANY_BACK_URL_KEY % job_application.pk
fallback_url = request.session.get(session_key, reverse_lazy("apply:list_for_siae"))
back_url = get_safe_url(request, "back_url", fallback_url=fallback_url)
request.session[session_key] = back_url
Expand Down Expand Up @@ -569,7 +572,10 @@ def transfer(request, job_application_id):
queryset = JobApplication.objects.is_active_company_member(request.user)
job_application = get_object_or_404(queryset, pk=job_application_id)
target_company = get_object_or_404(Company.objects, pk=request.POST.get("target_company_id"))
back_url = get_safe_url(request, "back_url", reverse("apply:list_for_siae"))

session_key = JOB_APP_DETAILS_FOR_COMPANY_BACK_URL_KEY % job_application.pk
fallback_url = request.session.get(session_key, reverse_lazy("apply:list_for_siae"))
back_url = get_safe_url(request, "back_url", fallback_url=fallback_url)

try:
job_application.transfer(user=request.user, target_company=target_company)
Expand Down
8 changes: 8 additions & 0 deletions tests/www/apply/test_process_external_transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,13 @@ def test_step_2_internal_transfer(client):
other_company = CompanyMembershipFactory(user=employer).company
client.force_login(employer)

# This will set the session back url
list_url_with_params = reverse("apply:list_for_siae") + "?pass_iae_active=on"
client.get(
reverse("apply:details_for_company", kwargs={"job_application_id": job_application.pk})
+ f"?back_url={quote(list_url_with_params)}"
)

transfer_step_1_url = reverse(
"apply:job_application_external_transfer_step_1", kwargs={"job_application_id": job_application.pk}
)
Expand All @@ -228,6 +235,7 @@ def test_step_2_internal_transfer(client):
assertContains(response, f'<form method="post" action="{internal_transfer_post_url}">')

response = client.post(internal_transfer_post_url, data={"target_company_id": other_company.pk})
assertRedirects(response, list_url_with_params)
job_application.refresh_from_db()
assert job_application.state == JobApplicationState.NEW
assert job_application.to_company == other_company
Expand Down

0 comments on commit a84aa89

Please sign in to comment.