Skip to content

[6.x] Don't save group-inherited roles as explicit roles - #15188

Open
duncanmcclean wants to merge 1 commit into
6.xfrom
group-inherited-roles
Open

[6.x] Don't save group-inherited roles as explicit roles#15188
duncanmcclean wants to merge 1 commit into
6.xfrom
group-inherited-roles

Conversation

@duncanmcclean

Copy link
Copy Markdown
Member

This pull request fixes an issue where roles inherited from a user group were saved against the user as though they'd been assigned directly, when using database-driven users. Removing the user from the group afterwards would leave those roles behind, orphaned in the role_user table.

This was happening because Statamic\Auth\Eloquent\User was using roles() in both data() and saveRoles(). That method merges the user's explicitly assigned roles with the roles they inherit from their groups, so the group's roles were rendered as checked in the Roles field, and were then written into role_user on save. The file driver isn't affected, since it only ever stores explicitly assigned handles.

This PR fixes it by using explicitRoles() in both places. roles() still merges group roles, so permissions are unaffected.

It's worth noting this doesn't clean up rows written by the previous behaviour — users already affected will keep their duplicated role_user rows until they're saved again with the Roles field corrected.

Fixes #15183

`Statamic\Auth\Eloquent\User` used `roles()` in `data()` and `saveRoles()`, which merges explicitly assigned roles with roles inherited from user groups. Group roles were rendered as checked in the Roles field and persisted into `role_user`, so they were left behind when the user was removed from the group.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Orphaned Roles when moving Users between User Groups

1 participant