When a user’s membership in an OG group changes, the Edit tab on group content nodes can remain stale (e.g., still hidden after adding a member, or still shown after removal) until cache is
cleared. This appears to be caused by OG access results not carrying cacheability metadata through hook_entity_access() denial paths, and by access results not varying by OG permissions.
Steps to reproduce
1. Create a group content type (e.g., Article) and a group type (e.g., Department).
2. Configure OG permissions so group members have “Edit any article content”.
3. View an Article as a non‑member: no Edit tab.
4. Add membership for the same user to the group (active).
5. Refresh the Article page.
Expected result
The Edit tab appears immediately after membership is added (and disappears immediately after removal).
Actual result
The Edit tab remains in the prior state until caches are cleared.
| Comment | File | Size | Author |
|---|---|---|---|
| Selection_999(5863).jpg | 28.31 KB | amitaibu |
Issue fork og-3571426
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
amitaibuNew test is still failing
Comment #4
amitaibuFixed tests locally.
Comment #6
amitaibuComment #7
joelpittetOk my skills in the access and cache are limited so I leaned heavy on an AI for this review...
Happy to push up the test and fix it came up with but not if that sounds suss to anybody with more knowledge. The fix is:
Comment #8
amitaibuThanks @joelpittet, you and your AI are right :)
We also have to check whether the group being checked is the one from the `ogContext`.
Comment #9
joelpittet@amitaibu I took a another review but I need to give it a bit more context because when I spot something like "removing reset() is a BC break" in the response I know it wants a bit of guidance ;) So I will give it some more.
But to keep you not waiting for my post this is it's hot take
Comment #10
amitaibu> "removing reset() is a BC break"
I think it should have been removed before we tagged 2.0. AFAIK, It was never used, and been hanging there for years.
> In src/OgAccess.php, when isCurrentUserAndGroup() is false but the user is the current user, the code falls back to adding user as a cache context.
I think that's correct. That is, we tell caching to cache by the user. Meaning that if the user is changed, it will call the access function again.
Comment #11
joelpittetYeah exactly, removing the reset() not an issue, good clean-up, that's why I want to scrutinize a bit closer what it's saying.
Comment #12
joelpittetThe video was a really nice illustration thanks @amitaibu I started the merge train. 🚂