Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.x] Changes to User role methods #9921

Merged
merged 13 commits into from
Apr 24, 2024
Merged

[5.x] Changes to User role methods #9921

merged 13 commits into from
Apr 24, 2024

Conversation

duncanmcclean
Copy link
Member

@duncanmcclean duncanmcclean commented Apr 17, 2024

This pull request makes some changes to the role methods on Statamic's User classes:

  • The ->roles() method now returns roles assigned via groups, in addition to roles directly assigned to the user.
  • The ->roles() method is no longer a setter, only a getter.
  • Adds a new ->explicitRoles() method, which returns the roles explicitly set on the user.
    • This method is also a setter, so you can do ->explicitRoles(['role_1', 'role_2']).

Breaking Changes

  • The $user->roles() method, $user->hasRole() method and {{ user:is role="role_1" }} tag now check if a user has the provided role via groups.
  • If you were setting a user's roles with the ->roles(['role_1']) method, you should now use the ->explicitRoles() method.

@duncanmcclean duncanmcclean changed the title [5.x] Tweaks to role/group methods [5.x] Include roles via groups in hasRole method Apr 17, 2024
@duncanmcclean duncanmcclean changed the title [5.x] Include roles via groups in hasRole method [5.x] Check roles via groups in hasRole method Apr 17, 2024
@duncanmcclean duncanmcclean changed the title [5.x] Check roles via groups in hasRole method [5.x] Changes to role methods on User classes Apr 18, 2024
@duncanmcclean duncanmcclean changed the title [5.x] Changes to role methods on User classes [5.x] Changes to User role methods Apr 18, 2024
@duncanmcclean duncanmcclean marked this pull request as ready for review April 24, 2024 10:30
@jasonvarga jasonvarga merged commit c410637 into master Apr 24, 2024
31 checks passed
@jasonvarga jasonvarga deleted the role-group-tweaks branch April 24, 2024 18:20
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.

2 participants