Skip to content

Commit

Permalink
Check that the retried job is the latest
Browse files Browse the repository at this point in the history
  • Loading branch information
zerolab committed Sep 19, 2024
1 parent 0e4226e commit 01234bb
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/wagtail_localize_smartling/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,18 @@ 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.
latest_job = translation.smartling_jobs.values_list("pk", flat=True)[0] # pyright: ignore[reportAttributeAccessIssue]
if latest_job != self.object.pk:
return permission_denied(request)

self.jobs_report_url = reverse("wagtail_localize_smartling_jobs:index")
return super().dispatch(request, *args, **kwargs)

Expand Down

0 comments on commit 01234bb

Please sign in to comment.