Firestore вложенные разрешения - PullRequest
       20

Firestore вложенные разрешения

0 голосов
/ 02 декабря 2018

Учитывая структуру базы данных:

libraries: {
  my-lib: {
    readers: ['tim@local', 'steve@dev']
    writers: ['steve@dev']
    books_collection: {
      abc: { ... }
      def: { ... }
    },
    other_collection: { ... }
  }
}

Есть ли более простой способ разрешить доступ к любой вложенной коллекции в документах из моей коллекции "библиотек"?

Запрос:

service cloud.firestore {
  match /databases/{database}/documents {
    match /libraries/{library} {
      allow read: if request.auth.token.email in get(/databases/$(database)/documents/libraries/$(library)).data.readers
      allow write: if request.auth.token.email in get(/databases/$(database)/documents/libraries/$(library)).data.writers

      match /{doc=**} {
        allow read: if request.auth.token.email in get(/databases/$(database)/documents/libraries/$(library)).data.readers
        allow write: if request.auth.token.email in get(/databases/$(database)/documents/libraries/$(library)).data.writers
      }
    }
  }
}
...