Flexible sync permission using $and operator

Hi,

I was wondering if $and operator is allowed in permissions JSON. Something like this:

{
      "name": "owner-write",
      "applyWhen": {},
      "read": {
        "_partitionKey": "PUBLIC"
      },
      "write": {
        "$and": [
          {
            "_partitionKey": "%%user.id"
          },
          {
            "organizationID": "%%user.custom_data.organizationID"
          }
        ]
     }
}

And this is the client side query:
QuerySubscription<Product>(name: "productsList") { $0._partitionKey == user._id && $0.organizationID == organizationID }

I am trying to add a record using this approach but the server reverts it.

Or maybe there is a better solution for my use case.

Thank you!

That is indeed a legal permission syntax (though the $and is uncessary), you could just do this instead:

{
      "name": "owner-write",
      "applyWhen": {},
      "read": {
        "_partitionKey": "PUBLIC"
      },
      "write": {
          "_partitionKey": "%%user.id"
          "organizationID": "%%user.custom_data.organizationID"
     }
}

It sounds like your issue is likely that the permissions are working, and you are trying to insert something that permissions says you are not allowed to insert (which will cause the “Reverting” behaviour)

1 Like

Hi @Tyler_Kaye, thank you for the info!

Actually, this was my initial setup but I thought that the issue was caused by the missing $and operator.

You were right, the problem was somewhere else, I managed to fix it.

Awesome thats glad to hear. I hope you are enjoying flexible sync! We are hoping to move the “rules” into the main rules tab soon so that it will be a bit easier to define and visualize rules soon!

Thanks,
Tyler

1 Like

Yeah, I like it so far!

Excellent, looking forward for the new updates!

Thank you,
Horatiu

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.