Commit b4d43c0
authored
fix: prevent reordering from unpublishing documents that have a newer draft (#16969)
## Summary
Backport of #16968 to `3.x`.
Reordering a document via the `orderable` drag-and-drop list view could
unpublish it when the document had both a published version and a newer
draft.
The reorder endpoint updated each moved document with `payload.update`
without a `draft` flag. With `draft` defaulting to `false`, the update
loaded the document's latest version (the draft) as its base and wrote
that draft's `_status: 'draft'` into the published main row, effectively
unpublishing the document. A subsequent `status: published` query then
returned 404 and no "currently published" version remained.
This fix detects, for drafts-enabled collections, whether the document's
latest version is a draft and, if so, performs the order update with
`draft: true`. This preserves the published main document (no unpublish)
while still updating the order on the version the list view reads (the
list queries with `draft: true`). Published-only documents keep the
existing behavior.
Reported via support ticket; reproduced on `3.84.1`.
## Changes
- `packages/payload/src/config/orderable/index.ts`: in the reorder
endpoint, look up the latest version for drafts-enabled collections and
pass `draft: true` when the latest version is a draft.
- `test/sort/int.spec.ts`: add an integration test covering reordering a
published document that has a newer draft, asserting it stays published.
## Test plan
- [x] On `main` (#16968): new test fails before the fix (`expected
'draft' to be 'published'`) and passes after; existing reorder tests
pass.
- [ ] CI on `3.x` validates the suite (local run skipped: installed deps
are for the `main`/4.0 toolchain).
- [ ] Manual check: collection with `orderable: true` and `versions: {
drafts: true }`; publish a doc, edit it into a newer draft, drag-reorder
it in the list view, and confirm it stays published.
Co-authored-by: German Jablonski <GermanJablo@users.noreply.github.com>1 parent 29afa77 commit b4d43c0
2 files changed
Lines changed: 92 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
| 16 | + | |
15 | 17 | | |
16 | 18 | | |
17 | 19 | | |
| |||
289 | 291 | | |
290 | 292 | | |
291 | 293 | | |
| 294 | + | |
| 295 | + | |
292 | 296 | | |
293 | 297 | | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
294 | 316 | | |
295 | 317 | | |
296 | 318 | | |
297 | 319 | | |
298 | 320 | | |
299 | 321 | | |
300 | 322 | | |
| 323 | + | |
301 | 324 | | |
302 | 325 | | |
303 | 326 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
594 | 594 | | |
595 | 595 | | |
596 | 596 | | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
597 | 666 | | |
598 | 667 | | |
599 | 668 | | |
| |||
0 commit comments