Replies: 5 comments 4 replies
-
The relationship between users and roles is a many-to-many, with the team ID on the pivot context and a part of the primary key, so any pair of user and role instances can have multiple relationships - one for each team that user is a member of. |
Beta Was this translation helpful? Give feedback.
-
There is another level to the team-based functionality too - being able to work with specified teams. A super-admin may have access to a full list of users, and they may need to add or remove roles from those users for specific teams they are on. Switching the context to the team is one way to do this, but not needing to switch context would be useful. Perhaps working in a closure that switches team context for what runs in it, then switches back on finishing could be one approach. I can go direct to the models for my application, but I'm trying to avoid that where possible and stick to the public interface to reduce surprises in future releases. |
Beta Was this translation helpful? Give feedback.
-
I'm sure that's caused by your customizations in #2446 (comment), try it on a fresh installation Related: #2088 (reply in thread) Tests: laravel-permission/tests/TeamHasRolesTest.php Lines 87 to 118 in 9d7ea6d |
Beta Was this translation helpful? Give feedback.
-
Looks like it. The detach needs the exlicit
It does not support OR conditions, which is a shame. The result on the SQL for a many-to-many join is the same whether using a So we are stuck, out of the box, needing to add special users to roles in every single team that needs it, apart from the single super admin that has god-like privileges. It also means having to add those special users to each team for those roles to work, which I didn't want to do. Another approach may be to keep this permissions package only for privileges of team members, and use a completely separate guard for non-team members (with elevated privileges). Or maybe I sleep on it and think of another approach. My problem remains: I have a set of roles that can be assigned to users within a team. All teams share those same roles. I have a set of roles that can be assigned to users globally, that work across all teams and do not require a user to be a member of those teams. |
Beta Was this translation helpful? Give feedback.
-
Responding to your first post above: You are correct: While not exactly perfect, I believe you could accomplish something akin to syncRoles by looping through all the teams the particular user is assigned to and attaching back the necessary records/pivots. (Obviously querying and remembering them before detaching everything, and using that to attach what you want to keep.)
I haven't explored it in detail, but an alternate approach might be: instead of wiping all and adding new, you could first query which records to specifically detach and pass those to the EDIT: I read further, and I see that you are indeed exploring more about working directly with the |
Beta Was this translation helpful? Give feedback.
-
This doesn'r seem right, and is certainly inconsistent. Is it a bug? Feels like it.
I have teams set up, omn release
5.10.1
, so the latest at this time. I have a bunch of global roles, that is roles not assigned to a particular team, so are common to all teams and used by all teams.I and logged in and have a team selected, and want to remove a user from the current team. Before removing the user, I want to remove all their roles from the current team. The user is a member of other teams, and has roles on those other teams too.
So the obvious way to remove the roles is:
That will remove all roles and add back in no roles.
However, it removes the user's roles from ALL the teams. It does not use the team context to detatch those roles. It does this using:
That does not take into account the pivot table context, which will have the team ID in, so roles for all teams are removed.
Now, the next step is to add the new synced roles back in:
Looking at
assignRole()
, that method does take the current team into account when assigning the new roles. That's the inconsistency.I think
removeRole()
is the same - does not look at the team context.Beta Was this translation helpful? Give feedback.
All reactions