Skip to content

Commit

Permalink
add 1st version of transfer batch view
Browse files Browse the repository at this point in the history
  • Loading branch information
xavfernandez committed Dec 13, 2024
1 parent f3ec32a commit f61e6cc
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion itou/templates/apply/includes/siae_actions_modals.html
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ <h5 class="modal-title" id="modal_title_{{ siae.pk }}">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-sm btn-outline-secondary" data-bs-dismiss="modal">Retour</button>
<form method="post" action="url 'apply:batch_transfer'">
<form method="post" action="{% url 'apply:batch_transfer' %}?next_url={{ list_url|urlencode }}">
{% csrf_token %}
<input type="hidden" name="target_company_id" value="{{ siae.pk }}" />
{% for application_id in selected_application_ids %}
Expand Down
1 change: 1 addition & 0 deletions itou/www/apply/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
),
path("siae/list/actions", list_views.list_for_siae_actions, name="list_for_siae_actions"),
path("company/batch/archive", batch_views.archive, name="batch_archive"),
path("company/batch/transfer", batch_views.transfer, name="batch_transfer"),
# Process.
path(
"<uuid:job_application_id>/jobseeker/details",
Expand Down
22 changes: 22 additions & 0 deletions itou/www/apply/views/batch_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

from django.contrib import messages
from django.contrib.auth.decorators import login_required
from django.core.exceptions import ValidationError
from django.http import HttpResponseRedirect
from django.shortcuts import get_object_or_404
from django.urls import reverse
from django.utils import timezone
from django.views.decorators.http import require_POST

from itou.companies.models import Company
from itou.job_applications.models import JobApplication
from itou.utils.auth import check_user
from itou.utils.perms.company import get_current_company_or_404
Expand Down Expand Up @@ -44,3 +47,22 @@ def archive(request):
",".join(str(app_uid) for app_uid in archived_ids),
)
return HttpResponseRedirect(next_url)

Check warning

Code scanning / CodeQL

URL redirection from remote source Medium

Untrusted URL redirection depends on a
user-provided value
.


@login_required
@check_user(lambda user: user.is_employer)
@require_POST
def transfer(request):
company = get_current_company_or_404(request)
# TODO: check that request.user is member of target_company
target_company = get_object_or_404(Company.objects, pk=request.POST.get("target_company_id"))
application_ids = request.POST.getlist("application_ids")
for application in company.job_applications_received.filter(pk__in=application_ids).select_for_update():
try:
application.transfer(user=request.user, target_company=target_company)
except ValidationError:
# TODO: gérer cette erreur et d'autres convenablement
pass

next_url = get_safe_url(request, "next_url", fallback_url=reverse("apply:list_for_siae"))
return HttpResponseRedirect(next_url)

Check warning

Code scanning / CodeQL

URL redirection from remote source Medium

Untrusted URL redirection depends on a
user-provided value
.

0 comments on commit f61e6cc

Please sign in to comment.