Skip to content

Utiliser le SessionNamespace pour sécuriser l’édition des fiches de poste [GEN-2311] - #6044

Merged
francoisfreitag merged 1 commit into
masterfrom
ff/job-desc-rework
May 5, 2025
Merged

Utiliser le SessionNamespace pour sécuriser l’édition des fiches de poste [GEN-2311]#6044
francoisfreitag merged 1 commit into
masterfrom
ff/job-desc-rework

Conversation

@francoisfreitag

Copy link
Copy Markdown
Member

🤔 Pourquoi ?

Protéger le parcours des problèmes d’une session modifiée dans des onglets multiples.

🍰 Comment ?

En écrivant l’ID de la session dans l’URL.

J’en ai profité pour ajouter job_description_id dans les URLs, afin de mieux indiquer si le parcours est une création de fiche de poste ou une mise à jour.

test_empty_session_during_edit a été supprimé, puisque la SessionNamespace requiert dorénavant une edit_session_id.

🏝️ Comment tester ?

Créer une fiche de poste.
Mettre à jour une fiche de poste.

@francoisfreitag francoisfreitag added the modifié Modifié dans le changelog. label Apr 28, 2025
@francoisfreitag francoisfreitag self-assigned this Apr 28, 2025
@francoisfreitag francoisfreitag changed the title Utilise le SessionNamespace pour sécuriser l’édition des fiches de poste Utiliser le SessionNamespace pour sécuriser l’édition des fiches de poste Apr 28, 2025
@francoisfreitag francoisfreitag changed the title Utiliser le SessionNamespace pour sécuriser l’édition des fiches de poste Utiliser le SessionNamespace pour sécuriser l’édition des fiches de poste [GEN-2311] Apr 28, 2025
@notion-workspace

Copy link
Copy Markdown

Comment on lines +292 to +347
if edit_session_id:
session_namespace = SessionNamespace(request.session, JOB_DESCRIPTION_EDIT_SESSION_KIND, edit_session_id)
if not session_namespace.exists():
raise Http404
session_data = session_namespace.as_dict()
else:
session_namespace = None
session_data = {}

# TODO(François): Drop this fallback next week.
if job_description_id is None and edit_session_id is None:
session_data = request.session.get(ITOU_SESSION_JOB_DESCRIPTION_KEY, {})
job_description_id = session_data.get("pk")

if job_description_id:
job_description = get_object_or_404(
JobDescription.objects.select_related("appellation", "location"),
pk=job_description_id,
company=request.current_organization,
)
if job_description_id
else None
)
else:
job_description = None

form = companies_forms.EditJobDescriptionForm(
request.current_organization, instance=job_description, data=request.POST or None, initial=session_data
)

if request.method == "POST" and form.is_valid():
request.session[ITOU_SESSION_JOB_DESCRIPTION_KEY] = {**session_data, **form.cleaned_data}
return HttpResponseRedirect(reverse("companies_views:edit_job_description_details"))
session_data.update(form.cleaned_data)
if session_namespace is None:
session_namespace = SessionNamespace.create_uuid_namespace(
request.session, JOB_DESCRIPTION_EDIT_SESSION_KIND, session_data
)
else:
session_namespace.update(session_data)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suite à la discussion de jeudi, c’est le micmac de création de la SessionNamespace que j’aimerais simplifier.

Si je trouve le temps dans les semaines à venir, je tenterai mon réusinage. :)

Comment on lines +19 to +25
path("edit_job_description/<uuid:edit_session_id>", views.edit_job_description, name="edit_job_description"),
path("edit_job_description/<int:job_description_id>", views.edit_job_description, name="edit_job_description"),
path(
"edit_job_description/<int:job_description_id>/<uuid:edit_session_id>",
views.edit_job_description,
name="edit_job_description",
),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Est-ce que des URLs en job_description/<int:job_description_id>/edit/..., job_description/create/... ne seraient pas plus jolis ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Si certainement, mais pas au milieu de cette PR qui a déjà assez à s’occuper de la rétrocompatibilité sans avoir à ajouter des changements cosmétiques.

Comment on lines 17 to 18
path("job_description_list", views.job_description_list, name="job_description_list"),
path("edit_job_description", views.edit_job_description, name="edit_job_description"),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

job_description/list & job_description/create ? 🥹
mais bon ça serait dans une autre PR.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Je me mets un TODO pour ces URLs, après avoir supprimé la compat’.

Comment thread itou/www/companies_views/views.py
Comment thread itou/www/companies_views/views.py Outdated
Comment thread itou/www/companies_views/views.py Outdated
Comment thread tests/www/companies_views/test_job_description_views.py Outdated
Like other views in the system (apply, job_seekers, …), prevent
collisions with multiple tabs by specifying the session key in the URL.

Clarify URLs by adding the `job_description_id` in their path.

The tunnel now starts with `edit_job_description` instead of
`update_job_description`. The `update_job_description` is a useless
redirect.
When edit data exists in the session (using the back_url),
`edit_job_description` will use the existing session namespace.
Otherwise, it’ll initialize a session namespace.

test_empty_session_during_edit was removed, as a SessionNamespace is now
required for edit views after the starting view: edit_job_description.
@francoisfreitag
francoisfreitag enabled auto-merge May 5, 2025 14:11
@francoisfreitag
francoisfreitag added this pull request to the merge queue May 5, 2025
Merged via the queue into master with commit d77d7a1 May 5, 2025
@francoisfreitag
francoisfreitag deleted the ff/job-desc-rework branch May 5, 2025 14:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

modifié Modifié dans le changelog.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants