Enable save and delete on a freshly created entity (#274, #268) - #281
Enable save and delete on a freshly created entity (#274, #268)#281p-hoffmann wants to merge 2 commits into
Conversation
Per-entity grants are only delivered by /user/me at startup, so an entity created during the session had no grant until the next page load. useEntityAccess therefore denied write on the thing the user had just made, leaving Save and Delete disabled in the editor until a refresh. Record ownership locally when a create succeeds. The server accepting the POST already establishes the user as the creator, so this matches what /user/me reports after a reload.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #281 +/- ##
===========================================
+ Coverage 94.79% 94.84% +0.04%
===========================================
Files 488 491 +3
Lines 66605 66977 +372
Branches 13627 13755 +128
===========================================
+ Hits 63136 63521 +385
+ Misses 3469 3456 -13
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
this might be worth taking a look at the 2.x codebase for how we synchronize client-side permissions with server side. If i understand the code correctly, you're doing something related to 'register ownership' but the ownership grant is handled on the server side, and you would get your updated permissions from the server (and at this time you can get all the other perms that may have changed). Sounds inefficient (why get everything when you know which permissions changed?), but the reality is that many permissions may change (like you import a Characterization design where new cohorts have been created in the result) so it's just more canonical to refresh the entire set of permissions after a request is performed that may alter user permissions. We also should be periodically refreshing user permissions (but that can be a potentially separate issue, but could be handled here because the crux of this issue is permissions became stale). I'm going to provide a detailed description about how Atlas 2.x handles this in a follow up, if you would like to wait to address this. My CoPilot is going through the code and producing a summary. |
|
@p-hoffmann : here's what I got, its a pretty good summary and includes a suggested bridge strategy: Atlas2 Permission Refresh FlowAtlas2 keeps client-side permissions aligned with the server by treating the server as the source of truth and reloading the current user’s authorization snapshot whenever the app enters a state where permissions may have changed. The core refresh path is in js/services/AuthAPI.js: There are two additional refresh triggers. First, js/services/AuthAPI.js also starts a periodic poll that re-calls Atlas3 Bridge StrategyAtlas3 already has the same ingredients, but split across composables, stores, and service modules instead of one monolithic auth service. The server round-trip lives in src/services/auth/authService.ts, where To recreate Atlas2 behavior, the Atlas3 equivalent of |
Recording the creator as owner client-side fixes the disabled Save and Delete buttons, but it only covers the entity whose id came back. A create can grant more than that: importing a design creates cohorts and concept sets of its own, and none of those ids are visible to the client. It also guesses at an answer the server already has, so a WebAPI that does not grant the creator write would leave the buttons wrongly enabled. Re-read user/me after a create and let it replace the local grant. The optimistic grant stays as the first step so the editor unblocks without waiting on the round trip, and as the fallback when user/me cannot be reached. Rename registerCreatedEntity to syncAccessAfterCreate now that it does both. Also register the three import endpoints, which create an entity server-side and were never covered, so #274 still reproduced through Import.
Problem
An entity you create during a session cannot be edited or deleted until you refresh the page. Save and Delete are disabled on the thing you just made (#274), and the cohort definition Delete button behaves the same way (#268). After a refresh, both work.
Cause
WebAPI reports per-entity permissions only through
/user/me, which the client requests once at startup. An entity created later in the session is not in that snapshot, so the client finds no permission for it and disables writing. Refreshing re-requests/user/me, the permission appears, and the buttons come back to life.What changes
When a create succeeds, the client now records you as the owner of the new entity straight away — the server accepting the request already establishes that — so Save and Delete work immediately, without a refresh.
This covers cohort definitions, concept sets, characterizations, feature analyses, pathways and incidence rates, including copying an incidence rate.
Fixes #274
Fixes #268