policy action :read do
# authorize_if expr(is_public)
# authorize_if expr(^actor(:status) == :active)
authorize_if expr(invites.member_id == ^actor(:id))
end
The primary resource is Event2, which has_many Invites. Each Invite has a member_id. The actor is a Member whose ID matches member_id.
If I use straight Ash.get!(Event2, event_id, actor: actor), that returns Event2 data.
If I uncomment those two other authorize_if lines, then modify the test setup to use either of them, the query returns the expected response data. It’s just that last authorize_if that seems to be tripping things up. What is different about it? Is it because it goes throug a has_many relationship?
I also tried opening up the :read policy on the Invite resource, to allow anyone to read that, and that didn’t help.
I tried that exists() expression earlier today, after reading that documentation. I just tried it again now, with the same result. Here’s the SQL from the logs, if you’re interested:
SELECT e0."id"
FROM "public"."events" AS e0
WHERE (e0."id" = $1)
AND (e0."group_id" = $2)
AND (
EXISTS (
SELECT 1
FROM "events"."invites" AS si0
WHERE (si0."member_id" = $3)
AND (si0."group_id" = $4)
AND (e0."id" = si0."event_id")
)
)
-- [469677, 970674, "V1KJW49URLTGJNFI8", 970674]
The group_id is the tenant. That’s added automatically. The query looks correct. The policy passes (according to the logs). It’s just that the data returned from the GraphQL is empty.
Is it possible to reproduce this w/o using AshGraphql? By calling an equivalent action under the hood? I’d be really surprised if somehow only the GraphQL was affected by policy filters in some way.
It definitely seems like a bug somewhere, but I think its at the point where I’ll need to be able to reproduce it as nothing is really jumping out at me