Detect conflicts for Page entities during the handling of auto-saves/pending calls
> [!warning] > > The main MR for this issue has been reverted in https://git.drupalcode.org/project/canvas/-/merge_requests/1205 and needs more work. > [!note] Migrated issue > > <!--Drupal.org comment--> > > <!--Migrated from issue #3589076.--> > > Reported by: [f.mazeikis](https://www.drupal.org/user/3513671) > > Related to !1107 ### Overview As a first small step towards [#3587587](https://www.drupal.org/node/3587587) we should start detecting conflicts during the polling of auto-save endpoint.\ More specifically, conflicts that are caused by updating entity for which there is already an auto-save entry in Canvas. Current `openapi` definition of the `auto-saves/pending` endpoint only describes a HTTP 200 response.\ That is correct, as `ApiAutoSaveController::get()` does not perform validation or conflict detection and currently only returns HTTP 200 responses.\ This issue aims to change that by adding ability to detect certain types of conflicts and respond with HTTP 409.\ This will allow Canvas UI to be notified about a conflict, even if the user is not performing any actions that would previously trigger a conflict detection. ### Proposed resolution 1. Add `openapi` definition for HTTP 409 response from the `auto-saves/pending` endpoint. 2. Start storing "original hash" during auto-save entry save, as this allows us to detect if the underlying entry has been updated since and there is a conflict between what auto-save assumes about the entity and the actual entity state. 3. Make AutoSaveManager to check for conflicts during fetching of the auto-save entry list, add relevant conflict metadata (`conflictId` and `timestamp`) to the entries. 4. Make `ApiAutoSaveController::get()` check entries for Page entities in the list and respond with HTTP 409 if at least one such entry has a conflict 5. As we will be making it possible to recover from some of detected conflicts, on conflicts caused by the change of the underlying auto-save entry entity we will return HTTP 409 and the response body will contain both: * `error` with a new error code for errors describing auto-save entries with conflicts * `data` with all the auto-save entries, including the entries with detected conflicts (thanks to [#3588038: Refactor auto-save endpoint response to encapsulate entries in top-level "data" key, like JSON:API, to enable adding errors later](https://www.drupal.org/project/canvas/issues/3588038)) 6. Add tests for all of this as well as update any existing tests that might start break due to unexpected HTTP 409 ### User interface changes For brief period of time until [#3585970: UI changes for detection of conflicts caused by external updates to underlying entity of auto-save entry](https://www.drupal.org/project/canvas/issues/3585970) is merged there will be a possibility to encounter a situation where Canvas UI forces to refresh the page based on the conflict detection during auto-save endpoint polling.\ No other UI changes are introduced in this issue. > Related issue: [Issue #3587587](https://www.drupal.org/node/3587587)
issue