I am getting 403
permission denied “Insufficient privileges to perform the action.” when I try and edit a student. I would really appreciate some help, as I am struggling to see where I went wrong. This should be fairly straight forward.
Here is the role that I setup.
CreateRole({
name: "edit_students",
membership: {
resource: Collection("users"),
predicate:
Query(
Lambda(
"ref",
Equals(
Select(["data","grants","edit_students"], Get(Var("ref")), false),
true
)
)
)
},
privileges: [
{
resource: Collection("students"),
actions: {
write: Query(
Lambda("ref",
Equals(
Select(['data', 'orgsRef'], Get(CurrentIdentity())),
Select(['data', 'orgsRef'], Get(Var("ref")))
)
)
),
}
},
]
})
The general idea is that a user with data.grants.edit_students
can edit any student. I then use the privileges actions to make sure the student they are editing belongs to the same organization.
Here is a sample user. Notice the data.orgsRef
.
{
"ref": Ref(Collection("users"), "286635854845182468"),
"ts": 1610458774620000,
"data": {
"email": "test@example.com",
"orgsRef": Ref(Collection("orgs"), "286635854833649156"),
"grants": {
"add_students": true,
"edit_students": true,
"delete_students": true
}
}
}
Here is an example student.
{
"ref": Ref(Collection("students"), "286635854869299716"),
"ts": 1610538599846000,
"data": {
"profile": {
"firstName": "John",
"lastName": "Doe"
},
"orgsRef": Ref(Collection("orgs"), "286635854833649156")
}
}
I can verify that the role created fine by looking at the dashboard. I see that it has write with the code above listed. So it is confusing for me, am I miss understanding what the lambda is receiving as the ref? I understand it would be the ref for the student that the action is happening on?