Relationship-Based Policies
I’m building an app with a many-to-many between Users and Teams via a TeamMember join resource and need guidance writing two related authorization policies:
1. TeamMember Resource Policy
In
team_member.ex
I’ve defined:
I need to allow reading a TeamMember
record only if the actor is also a member of the same team.
These are the relationships defined in this resource:
2. User Resource Policy
Since the above action loads the :user
relationship, I also need a similar rule in user.ex
. How to allow reading another user only when the actor and the target user share the same team?
This is the relationship defined in my User
resource:
2 Replies
Solution
You can use relates_to_actor_via
After trying many different ways to do it, I finally got it to work like this
Works for both policies
Thanks