I have a problem with a function UpdateProduct.
{
ref: Role("MyCustomRole"),
ts: 1622063171900000,
name: "MyCustomRole",
privileges: [
{
resource: Index("email"),
actions: {
unrestricted_read: false,
read: true
}
},
{
resource: Ref(Ref("functions"), "CreateProduct"),
actions: {
call: true
}
},
{
resource: Collection("users"),
actions: {
read: true,
write: true,
create: true,
delete: false,
history_read: false,
history_write: false,
unrestricted_read: false
}
},
{
resource: Collection("accounts"),
actions: {
read: true,
write: true,
create: true,
delete: false,
history_read: false,
history_write: false,
unrestricted_read: false
}
},
{
resource: Ref(Ref("functions"), "UpdateProduct"),
actions: {
call: true
}
},
{
resource: Collection("orders"),
actions: {
read: true,
write: true,
create: true,
delete: false,
history_read: false,
history_write: false,
unrestricted_read: false
}
},
{
resource: Collection("comments"),
actions: {
read: true,
write: true,
create: true,
delete: false,
history_read: false,
history_write: false,
unrestricted_read: false
}
},
{
resource: Ref(Ref("functions"), "DeleteProduct"),
actions: {
call: true
}
},
{
resource: Collection("products"),
actions: {
read: Query(
Lambda(
"ref",
Equals(
Select(["data", "user"], Get(CurrentIdentity())),
Select(["data", "user"], Get(Var("ref")))
)
)
),
write: Query(
Lambda(
["oldData", "newData"],
Equals(
Select(["data", "user"], Get(CurrentIdentity())),
Select(["data", "user"], Var("oldData"))
)
)
),
create: true,
delete: Query(
Lambda(
"ref",
Equals(
Select(["data", "user"], Get(CurrentIdentity())),
Select(["data", "user"], Get(Var("ref")))
)
)
),
history_read: false,
history_write: false,
unrestricted_read: false
}
}
],
membership: [
{
resource: Collection("accounts"),
predicate: Query(
Lambda(
"ref",
Equals(
Select(
["data", "status"],
Get(Select(["data", "user"], Get(Var("ref"))))
),
"A"
)
)
)
}
]
}
In such a set up query below just work perfectly
client.query(
q.Update(q.Ref(q.Collection("products"), "299595354097058305"), {
data: {
......
}
})
)
but I can not call the function UpdateProduct
q.Call('UpdateProduct', { ..... })
getting an error: Insufficient privileges to perform the action.
but if I change the write privileges (collection products) then I can call the function
resource: Collection("products"),
actions: {
read: Query(
Lambda(
"ref",
Equals(
Select(["data", "user"], Get(CurrentIdentity())),
Select(["data", "user"], Get(Var("ref")))
)
)
),
write:true
)
.....
}
I do not understand this.
I do need privileges on write action and I need to call function(UpdateProduct) from client. How can I achieve this?