AO3-4122 Prevent duplicate translation languages for admin posts - #6003
Open
pmonfort wants to merge 2 commits into
Open
AO3-4122 Prevent duplicate translation languages for admin posts#6003pmonfort wants to merge 2 commits into
pmonfort wants to merge 2 commits into
Conversation
pmonfort
commented
Aug 27, 2026
Comment on lines
+37
to
+42
| # rubocop:disable Rails/UniqueValidationWithoutIndex | ||
| validates :translated_post_id, | ||
| uniqueness: { scope: :language_id, | ||
| message: :translation_already_exists }, | ||
| allow_nil: true | ||
| # rubocop:enable Rails/UniqueValidationWithoutIndex |
Contributor
Author
There was a problem hiding this comment.
Disabled this cop instead of adding a unique index on (translated_post_id, language_id). Production likely has duplicates already (that's what this issue is about), so the index would need a data cleanup first, and that felt out of scope here. The validation itself runs the same query either way and uses the existing index on translated_post_id.
pmonfort
commented
Aug 27, 2026
| end | ||
| end | ||
|
|
||
| context "when the original post has a draft translation in the language" do |
Contributor
Author
There was a problem hiding this comment.
The issue only mentions published translations, but this implementation also blocks the case where the existing translation is still a draft. Drafts are shared between all admins, otherwise a second translation in the same language could be posted while the draft is pending.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull Request Checklist
AO3-1234 Fix thing)Issue
https://otwarchive.atlassian.net/browse/AO3-4122
Purpose
Adds a validation so an admin post can't be saved as a translation of another post when that post already has a translation in the same language. The error is reported on the translated post field, alongside the existing "cannot be same language as original post" and "cannot be posted before the original post" errors.
Testing Instructions
Credit
Pablo Monfort (he/him)