Правила безопасности Firebase для вложенных коллекций - PullRequest
0 голосов
/ 04 октября 2019

У меня есть следующая структура:

+ properties: (collection)
    - address
      status
      type
      ownerId
      renterId
    + offers (collection)
        - id
          amount
          date
        - id
          amount
          date
    + features (collection)
        - id
          name
        - id
          name

Я хотел бы разрешить доступ на чтение к properties для владельца (используя ownerId), съемщика (используя renterId) и администратора.

Кажется, что это не работает:

    match /properties/{property} {
    allow read, write: if get(/databases/$(database)/documents/properties/$(property)).data.renter == request.auth.uid
                    || isOwnerSeller(get(/databases/$(database)/documents/properties/$(property))) 
                    || isAAdmin();
}

Чего мне не хватает? Могу ли я также настроить таргетинг только на предложение?

1 Ответ

0 голосов
/ 09 октября 2019
service firebase.storage {
  // Allow the requestor to read or delete any resource on a path under the
  // user directory.
  match /users/{userId}/{anyUserFile=**} {
    allow read, delete: if request.auth.uid == userId;
  }

  // Allow the requestor to create or update their own images.
  // When 'request.method' == 'delete' this rule and the one matching
  // any path under the user directory would both match and the `delete`
  // would be permitted.

  match /users/{userId}/images/{imageId} {
    // Whether to permit the request depends on the logical OR of all
    // matched rules. This means that even if this rule did not explicitly
    // allow the 'delete' the earlier rule would have.
    allow write: if request.auth.uid == userId && imageId.matches('*.png');
  }
}

В соответствии с документацией вы можете устанавливать правила также и таким способом. Следуйте этому примеру, и вы сможете применить желаемые правила.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...