2

As I am using Flexible Sync for my application, I have to define my rules on sync level and not on document level. However I was wondering how to achieve read and write permissions across collections as I only have access to the current document from within the rules.

In the documentation I found following snippet:

{
  "defaultRoles": [
    {
      "name": "owner-write",
      "applyWhen": {},
      "read": {
        "owner_id": {
          "$in": "%%user.custom_data.subscribedTo"
        }
      },
      "write": {
        "owner_id": "%%user.id"
      }
    }
  ]
}

This kind of suggests, that I should write business logic into the custom user data (in this case subscribedTo). So I meant to ask if this is the recommended way to solve cross collection validation, as I feel very hesitant to put business logic into the user data just for the sake of document validation.

Thomas
  • 2,375
  • 2
  • 17
  • 32

1 Answers1

0

here is an example permission rule for collections.

{
  "rules": {
    "AnalysisModel": [
      {
        "name": "anyperson",
        "applyWhen": {},
        "read": false,
        "write": true
      }
    ],
    "CoordinatesModel": [
      {
        "name": "anyperson",
        "applyWhen": {},
        "read": false,
        "write": true
      }
    ],
    "UserModel": [
      {
        "name": "anyperson",
        "applyWhen": {},
        "read": true,
        "write": true
      }
    ]
  },
  "defaultRoles": [
    {
      "name": "read-write",
      "applyWhen": {},
      "read": true,
      "write": true
    }
  ]
}
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 03 '22 at 03:38