From a7f9dd0b926231ac3f67583d65dd25d8a663d714 Mon Sep 17 00:00:00 2001 From: zerolab Date: Thu, 19 Sep 2024 17:30:15 +0100 Subject: [PATCH] Check that the retried job is the latest --- src/wagtail_localize_smartling/views.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/wagtail_localize_smartling/views.py b/src/wagtail_localize_smartling/views.py index 706e1fd..758dda4 100644 --- a/src/wagtail_localize_smartling/views.py +++ b/src/wagtail_localize_smartling/views.py @@ -115,6 +115,17 @@ def dispatch(self, request, *args, **kwargs): if self.object.status not in UNTRANSLATED_STATUSES: return permission_denied(request) + # Check that the given Job is the latest. We can use any of its translations + translation = self.object.translations.first() + if translation is None: + # should cover the case where the translation was converted back to an alias + return permission_denied(request) + + # Jobs are ordered by `first_synced_at`, with null values coming at the top + # then pk descending. + if translation.smartling_jobs.values_list("pk", flat=True)[0] != self.object.pk: + return permission_denied(request) + self.jobs_report_url = reverse("wagtail_localize_smartling_jobs:index") return super().dispatch(request, *args, **kwargs)