Hello, I’m trying to set up a role with privileges that are based on a related collection. For example I have a setup similar to the below data
{
"ref": Ref(Collection("users"), "269756182088909300"),
"ts": 1593518393440000,
"data": {
"email": "user@gmail.com"
}
}
{
"ref": Ref(Collection("shops"), "269756182088909400"),
"ts": 1593518393440000,
"data": {
"owner": Ref(Collection("users"), "269756182088909300")
}
}
So I have a users collection for all the users and a shops collection with the shops where each shop is owned by a user. I also have a products collection where a product could look like something below
{
"ref": Ref(Collection("products"), "269756182088909500"),
"ts": 1593518393440000,
"data": {
"shop": Ref(Collection("shops"), "269756182088909400")
}
}
So each product is part of a shop which in turn is owned by a user. What I would like to do is to create a role for users that allows them to create a product inside the shop that they own but I’m struggling to find the correct syntax.
For example I have a role with the following privileges definition taken from the example but I would like to extend it so that it check if the current user is owning the shop instead of the product.
{
resource: Collection("products"),
actions: {
...,
create: Query(
Lambda(
"values",
Equals(Identity(), Select(["data", "owner"], Var("values")))
)
),
...
}
},
I tried doing a select on the user based on the owner but I got some set not found
error so I’m guessing it should be done in some other way.
Any suggestions on how I could go about to accomplish this?