Bypassing tenancy & authorization to load related data in special read
Th following action reads the received invitation of a user to join the establishment of an organization (both are tenants, org being the top tenant).
It successfully reads the invitation (which belongs to the establishment tenant) thanks to
multitenancy :bypass
However, loading inviter (an establishment_user) requires a tenant to be set, and establishment returns nil — I’m guessing because the policy doesn’t allow reading establishment data unless you’re a member, which we aren’t here (yet).
This means we never even reach organization (top-level tenant).
How can I bypass tenancy & authorization policies just for this exceptional case so I can load related data (inviter, establishment, organization)?3 Replies
Solution
:bypass_all
IIRCwill bypass tenancy for loaded data as well
Awesome, that fixes the tenancy problem
Is there a way to bypass the authorization directly from the
prepare
here?
There is a lot I'm loading here and writing policies for each one of them only for this special use case doesn't feel like the right approach
By the way I tried this
But still getting nil
for the loaded relationships
Ok nevermind, implementing the policies was pretty straightforward after establishing the correct relationships. Here is an example:
Thanks for your support Zach!