How to load a nested relationship with a tenant?
I'm a beginner with Ash and essentially I'd like to lookup an organization while loading some relationships, something like this:
(I only really need a single organization at the moment but I suppose the question is more general.)
However to load the user roles I have to specify the tenant (which is the organization itself) and I get this error:
How can I load the organization while also loading the relationships that needs the organization itself?
The organization and users live in the "public" schema while the user roles lives in a schema specified by the organization id.
The organization is specified with:
And the user role:
15 Replies
I tried to work around it by adding a many_to_many in organization:
I've verified that the data is created correctly in the db (with user roles in the organization schema and the other in public) but if I try to load it the user is still nil but the organization works:
I haven't added any explicit multitenancy code to the user but I'm unsure how to do that and as I said the creation worked fine.
We've needed a feature for this for a while when loading relationships where you can say that the tenant is the source of the load. Please open a feature proposal for it
But for now what you'd want to do is figure out the tenant for the org before loading the tenanted relationships
You can load after the fact with 'Ash.load'
I'm still having trouble finding the user reference (going from tenant to no tenant). Is that how it's supposed to be setup or does the user require a multitenancy description even though it lives in the public schema?
When you say 'finding the user reference' I'm not sure what you mean sorry
You can set a tenant when reading an untenated resource
i.e
It may be that the user is coming back as
nil
because of your policies
Try this:
Ooh, yeah I was missing
authorize?: false
! Thank you!Keep in mind that for your real usage you typically want to be actually modifying your policies to fit
For admin/testing etc. all good though
I would've expected a policy error when using load like this. I read in the book that
read
works differently but still a bit confused to be honest
I used this codeYep, so read policies by default filter to only show data that you can see as the requester
this is a security measure that prevents leaking internals about your data
Oh right, to prevent enumeration attacks?
For example lets say I knew that the user
zach@daniel.com
was in your system, and I wanted to see what state they live in, if I do /users?filter[email]=zach@daniel.com&filter[state]=FL
etc. I could tell from 403 vs 404 where you live
and yeah I typed all that up but you already knew it 😜Heh
So yeah we just take a cautious approach there
but you can change it w/
access_type
access_type :strict
and access_type :runtime
(almost never use the latter)In this particular case I'd expect that the whole UserRole would be filtered (as it doesn't make sense without a user)
Thats totally up to your policy setup
i.e perhaps your user roles should have policies indicating who can/can't read them etc.
Alright, that's fair.