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/publishendpoint definition inopenapi.ymlby addingHTTP 409response toPOSTmethod -
Updates
ApiAutoSaveControllerto ensure conflicts are detected during the publishing of auto-save item(s) -
Adds overrides of the
EntityChangedconstraint and it's validator for Page entities inOverriddenEntityChangedConstraintandOverriddenEntityChangedConstraintValidator. The override intervenes only during the handling of auto-save items publishing request and is used to perform additional conflict detection. Validation logic ofEntityChangedis 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
EntityChangedconstraint during publishing via Canvas UI. -
Expand tests in
ApiAutoSaveControllerTestto cover new functionality -
Moves the AUTO_SAVE_CONFLICT_KEY constant out of
ApiAutoSaveControllerintoAutoSaveManager, so it could be re-used more
Testing instructions
Quick fingers are required
-
Start with already published Page entity ready for editing in Canvas UI
-
Take note of the Page ID
-
Modify this Page entity, but do not publish your changes
-
Re-save this Page entity outside of Canvas using the Page ID from step 2 (using
drush esav canvas_page <entity_id> -yshould work just fine)Important
⚠️ The following step must be performed before the next automatic call toauto-saves/pending(every 10s) as that will returnHTTP 409and ruin the test: -
Attempt publishing your changes from step 3 via Canvas UI
-
Observe
HTTP POSTcall to the/canvas/api/v0/auto-saves/pendingendpoint returnHTTP 409response:- Response should have
errorsproperty with item for the Page entity modified in step 3. - Error item should have property
codewith value4, identifying theHTTP 409response as "resolvable in Canvas UI" as described in #3587587 (closed) - Error item must have
metaproperty which inside of it containsconflict_idproperty matching th latest revision id (cast to string) of the Page entity updated in step 4.
- Response should have
One of two MRs that will close #3587526