feat(Conflict detection): #3587526 "Detect conflicts during publishing of changes to Page entity"

TL;DR: Adds HTTP 409 response to the "publish auto-save items" endpoint; Prevents publishing on the BE if a conflict is detected;

For people with attention span or AI summary tools:

This MR adds "Prevent publishing of auto-save items with detected conflicts on BE" capability described in the "[META] Review of changes and Conflict resolution" (#3587587 (closed)).

It is BE implementation of #3587526 and counter-part of feat(Conflict detection): #3587526 "Client side... (!1018 - merged) .

To keep the scope manageable, changes are limited to Page (canvas_page) entities. Effort is made to leave path open for other entity types.

List of changes:

  • Updates the /canvas/api/v0/auto-saves/publish endpoint definition in openapi.yml by adding HTTP 409 response to POST method

  • Updates ApiAutoSaveController to ensure conflicts are detected during the publishing of auto-save item(s)

  • Adds overrides of the EntityChanged constraint and it's validator for Page entities in OverriddenEntityChangedConstraint and OverriddenEntityChangedConstraintValidator . The override intervenes only during the handling of auto-save items publishing request and is used to perform additional conflict detection. Validation logic of EntityChanged is overlapping with and is superseded by the conflict detection and resolution logic during the auto-save item publishing via Canvas UI.

    Without this override Page entities with resolved conflicts fail validation of EntityChanged constraint during publishing via Canvas UI.

  • Expand tests in ApiAutoSaveControllerTest to cover new functionality

  • Moves the AUTO_SAVE_CONFLICT_KEY constant out of ApiAutoSaveController into AutoSaveManager , so it could be re-used more

Testing instructions

Quick fingers are required 😅

  1. Start with already published Page entity ready for editing in Canvas UI

  2. Take note of the Page ID

  3. Modify this Page entity, but do not publish your changes

  4. Re-save this Page entity outside of Canvas using the Page ID from step 2 (using drush esav canvas_page <entity_id> -y should work just fine)

    Important

    ⚠️ The following step must be performed before the next automatic call to auto-saves/pending (every 10s) as that will return HTTP 409 and ruin the test:

  5. Attempt publishing your changes from step 3 via Canvas UI

  6. Observe HTTP POST call to the /canvas/api/v0/auto-saves/pending endpoint return HTTP 409 response:

    • Response should have errors property with item for the Page entity modified in step 3.
    • Error item should have property code with value 4 , identifying the HTTP 409 response as "resolvable in Canvas UI" as described in #3587587 (closed)
    • Error item must have meta property which inside of it contains conflict_id property matching th latest revision id (cast to string) of the Page entity updated in step 4.

One of two MRs that will close #3587526

Edited by Feliksas Mazeikis

Merge request reports

Loading