Repository navigation
fix(editor): tolerate stale review state from browser Back when same author #23018
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
52f1c20
2fae73b
086df11
5263d66
56237e8
1c024bd
2f8393e
1b08365
3501bf8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -569,36 +569,43 @@ | |
| } | ||
|
|
||
| def test_state_conflict_preserves_draft(self) -> None: | ||
| for actor in (self.user, self.anotheruser): | ||
| with self.subTest(actor=actor.username): | ||
| self.change_unit("Nazdar svete!\n", state=STATE_NEEDS_REWRITING) | ||
| self.change_unit("Nazdar svete!\n", state=STATE_TRANSLATED, user=actor) | ||
| change_count = Change.objects.filter(unit=self.unit).count() | ||
| for _attempt in range(2): | ||
| response = self.client.post(self.url, self.data) | ||
| self.assertContains( | ||
| response, | ||
| "The review state of this string has changed from " | ||
| "Needs editing (Needs rewriting) to Translated", | ||
| ) | ||
| self.assertNotContains( | ||
| response, "This review state is not available" | ||
| ) | ||
| self.assertNotContains(response, "Select a valid choice") | ||
| self.assertContains(response, self.data["target_0"]) | ||
| self.assertContains(response, 'name="initial_state" value="11"') | ||
| self.assertContains(response, 'data-unsaved="true"') | ||
| self.unit.refresh_from_db() | ||
| self.assertEqual(self.unit.target, "Nazdar svete!\n") | ||
| self.assertEqual(self.unit.state, STATE_TRANSLATED) | ||
| self.assertEqual( | ||
| Change.objects.filter(unit=self.unit).count(), change_count | ||
| ) | ||
| """Another user changed the state: the stale form is rejected.""" | ||
| self.change_unit("Nazdar svete!\n", state=STATE_NEEDS_REWRITING) | ||
| self.change_unit( | ||
| "Nazdar svete!\n", state=STATE_TRANSLATED, user=self.anotheruser | ||
| ) | ||
| change_count = Change.objects.filter(unit=self.unit).count() | ||
| for _attempt in range(2): | ||
| response = self.client.post(self.url, self.data) | ||
| self.assertContains( | ||
| response, | ||
| "The review state of this string has changed from " | ||
| "Needs editing (Needs rewriting) to Translated", | ||
| ) | ||
| self.assertNotContains(response, "This review state is not available") | ||
| self.assertNotContains(response, "Select a valid choice") | ||
| self.assertContains(response, self.data["target_0"]) | ||
| self.assertContains(response, 'name="initial_state" value="11"') | ||
| self.assertContains(response, 'data-unsaved="true"') | ||
| self.unit.refresh_from_db() | ||
| self.assertEqual(self.unit.target, "Nazdar svete!\n") | ||
| self.assertEqual(self.unit.state, STATE_TRANSLATED) | ||
| self.assertEqual(Change.objects.filter(unit=self.unit).count(), change_count) | ||
|
|
||
| def test_state_conflict_same_author_allowed(self) -> None: | ||
| """Same user changed the state (browser Back): the stale form is accepted.""" | ||
| self.change_unit("Nazdar svete!\n", state=STATE_NEEDS_REWRITING) | ||
| self.change_unit("Nazdar svete!\n", state=STATE_TRANSLATED, user=self.user) | ||
| response = self.client.post(self.url, self.data) | ||
| self.assertEqual(response.status_code, 302) | ||
|
Comment on lines
+598
to
+600
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The existing Useful? React with 👍 / 👎. |
||
| self.unit.refresh_from_db() | ||
| self.assertEqual(self.unit.target, self.data["target_0"]) | ||
|
cubic-dev-ai[bot] marked this conversation as resolved.
Resolved
|
||
| self.assertEqual(self.unit.state, STATE_TRANSLATED) | ||
|
|
||
| def test_conflict_with_still_available_choice(self) -> None: | ||
| self.change_unit("Nazdar svete!\n", state=STATE_NEEDS_CHECKING) | ||
| response = self.client.post(self.url, {**self.data, "review": "20"}) | ||
| self.assertContains(response, "The review state of this string has changed") | ||
|
Check failure on line 608 in weblate/trans/tests/test_edit.py
|
||
| self.unit.refresh_from_db() | ||
| self.assertEqual(self.unit.state, STATE_NEEDS_CHECKING) | ||
|
|
||
|
|
@@ -664,7 +671,7 @@ | |
| reverse("save_zen", kwargs=self.kw_translation), self.data | ||
| ) | ||
| data = response.json() | ||
| self.assertEqual(data["state"], "danger") | ||
|
Check failure on line 674 in weblate/trans/tests/test_edit.py
|
||
| self.assertEqual(data["translationsum"], "") | ||
| self.assertIsNone(data["initial_state"]) | ||
| self.assertEqual(len(data["messages"]), 1) | ||
|
|
@@ -1416,7 +1423,7 @@ | |
| ) | ||
|
|
||
| # pylint: disable=arguments-differ | ||
| def edit_unit(self, source, target, language="cs", **kwargs): | ||
| """Do edit single unit using web interface.""" | ||
| unit = self.get_unit(source, language) | ||
| params = { | ||
|
|
@@ -3558,13 +3565,13 @@ | |
|
|
||
| self.assertEqual( | ||
| get_sort_name( | ||
| request, ProjectLanguage(self.project, self.translation.language) | ||
| )["query"], | ||
| "component,-priority", | ||
| ) | ||
| self.assertEqual( | ||
| get_sort_name( | ||
| request, CategoryLanguage(category, self.translation.language) | ||
| )["query"], | ||
| "component,-priority", | ||
| ) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When reviewer B accepts and approves a suggestion written by reviewer A,
Suggestion.accept()records B asChange.userbut A asChange.author.get_last_content_change()returns the latter, so if A still has an older editor form open, this branch incorrectly treats B's state change as A's own and replaces the expected state. A's stale save can then silently undo B's approval instead of reporting a conflict. Base the exemption on the actor of the actual state-changing history entry, not its content author.AGENTS.md reference: AGENTS.md:L65-L66
Useful? React with 👍 / 👎.