hans
(Hans)
September 5, 2021, 4:03pm
1
Im trying to have a role that applies when user has a email address.
But im getting
error executing match expression: invalid document: must either be a boolean expression or a literal document
with the following rule:
"apply_when": {
"user_id": "%%user.id",
"%%user.data.email": {
"%exists": true
}
},
It seems to be what is suggested here:
Yes - you can add this logic to your ‘Apply When’ when configuring Roles. One way to do it is:
Add a Anon Role and add the following ‘Apply When’ expression (since anon users don’t have an email associated with them).
{
“%%user.data.email”: { “%exists”: false }
}
Grant Read only permissions to this Role
Add an Email Password Role and add the following apply when expression
{
“%%user.data.email”: { “%exists”: true }
}
Grant Read and Write permissions to this Role
Roles/Apply Wh…
But it does not work for me.
hans
(Hans)
September 5, 2021, 4:07pm
2
Here is the full rules:
{
"roles": [
{
"name": "owner",
"apply_when": {
"user_id": "%%user.id",
"%%user.data.email": {
"%exists": true
}
},
"insert": true,
"delete": true,
"search": true,
"read": true,
"write": true,
"fields": {},
"additional_fields": {}
}
],
"filters": [],
"schema": {}
}
Just for reference: I found that you get this error when mixing document fields and %%user
expansions in the same expression. It’s somewhat weird because the docs use a similar example:
{
"owner": "%%user.id",
"%%request.remoteIPAddress": {
"$in": "%%values.allowedClientIPAddresses"
}
}
But anyway. I found that this Apply When was not working:
{
"organizationId": "%%user.custom_data.organizationId",
"%%user.custom_data.roles": "user-admin"
}
and when I changed the field reference to %%root.[field]
, it did work:
{
"%%root.organizationId": "%%user.custom_data.organizationId",
"%%user.custom_data.roles": "user-admin"
}