Commit 3f3f5db
authored
fix: ensure restoreAsDraft only updates the published doc when draft is false (#14658)
### What?
Updates the `restoreVersion` logic to ensure restoring as a draft does
not overwrite the currently published data.
### Why?
If you have a published doc, then save a draft, you expect to be able to
access the published data by `draft: false` and the draft by
`draft:true`. When you restore a version as a draft, the same behavior
is expected.
However, in the `restoreVersion` operation, we are updating the main doc
even if you are restoring as a draft. This overwrites the published
data, so now you will see draft data returned regardless of querying
with `draft: true/false`.
### How?
When restoring a version as a draft, we only need to save a new version.
The main doc should only be updated when restoring as published.
This change checks `(!draftArg)` before running the `updateOne` on the
main doc.
#### Reported by client.1 parent a7cf30d commit 3f3f5db
File tree
2 files changed
+10
-7
lines changed- packages/payload/src/collections/operations
- test/versions
2 files changed
+10
-7
lines changedLines changed: 9 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
262 | 262 | | |
263 | 263 | | |
264 | 264 | | |
265 | | - | |
266 | | - | |
267 | | - | |
268 | | - | |
269 | | - | |
270 | | - | |
271 | | - | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
272 | 274 | | |
273 | 275 | | |
274 | 276 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
306 | 306 | | |
307 | 307 | | |
308 | 308 | | |
| 309 | + | |
309 | 310 | | |
310 | 311 | | |
311 | 312 | | |
| |||
0 commit comments