Best option to read a relationship which has policy in Action
Hi, I so much searching today and with AI to be allowed load a relations in action, but i think there is better way!
for example in user resource
get_by_subject
I added this:
permissions
is a many_to_many
So i added this Policy in resource b
and c
So it let me to to get the data of permissions
before it it just return empty list []
I tried to add authorize?: false
To |> Ash.Query.load([:permissions, :permission_values], authorize?: false)
But it did not work and return empty list
I think this (authorize_if expr(not is_nil(^context(:accessing_from)))
) way can be a problem for me base on a mistake leak the data
Thank you in advance!Solution:Jump to solution
Finally i found :)) i created this debugger 😂 😂😂
```elixir
defmodule MishkaCms.Accounts.Checks.DebugAccessingFrom do
use Ash.Policy.SimpleCheck
...
7 Replies
You would typically do
authorize_if accessing_from({Resource, :relationship})
if you want to allow loading from a relationshipThank you, but you mean this? after chasing this i get
permissions: []
again! :thinkies:
MishkaCms.Accounts.User
MishkaCms.Accounts.Permission
MishkaCms.Accounts.UserPermission
That bottom policy always forbids everything
This is probably what you want
Remember to thoroughly read the policies guide to understand how they work, even if you have to read it multiple times 😄
I have read more than 100 times :)))
sorry to waste your time again i get
permissions: []
This fire my head :))🤔
Did you put in the right relationship name?
Ahhhmmm. it is many to many!! sorry i am so confused
where should i put them
MishkaCms.Accounts.User
we have action that want to read permissions
I need to put it inside my MishkaCms.Accounts.Permission
resource
like this?
and what i should put inside the MishkaCms.Accounts.UserPermission
resource
because i put the
in both MishkaCms.Accounts.Permission
and MishkaCms.Accounts.UserPermission
resource
Gist: https://gist.github.com/shahryarjb/6728cf3b4b1c42c467dd38197dd632a4Solution
Finally i found :)) i created this debugger 😂 😂😂
in my user
inside MishkaCms.Accounts.Permission
and
MishkaCms.Accounts.UserPermission