How to count/calculate Firestore Security Rule acc

2019-08-21 08:29发布

There is a limit of 10 get() for single-document requests and query requests. How many access call would the below snippet be for access role of 'STANDARD'?

function isOwnerOfTeam(teamId, userId) {
  return get(/databases/$(database)/documents/team_access_privilege/$(teamId)).data[userId] == 'OWNER'
}

function isAdminOfTeam(teamId, userId) {
  return get(/databases/$(database)/documents/team_access_privilege/$(teamId)).data[userId] == 'ADMIN'
}

function isStandardOfTeam(teamId, userId) {
  return get(/databases/$(database)/documents/team_access_privilege/$(teamId)).data[userId] == 'STANDARD'
}

function isTeamMember(teamId, userId) {
  return isOwnerOfTeam(teamId, userId) || isAdminOfTeam(teamId, userId) || isStandardOfTeam(teamId, userId)
}

And what if I have a get() nested get() with OR operators. How many access call would that be?

For instance

function getTeamId(teamName) {
  get(/databases/$(database)/documents/team/$(teamName)).data[id]
}

match /teamSecretStory/{teamName} {
      allow read: if isTeamMember(getTeamId(teamName), request.auth.uid);
}

All in all, how many access is this get() nested get() with OR operators for role 'STANDARD'?

1条回答
仙女界的扛把子
2楼-- · 2019-08-21 08:55

Security rules, like all major programming languages, short circuit their logical ORs, left to right. Each OR is evaluated from left to right until one of them evaluates true, or all of them evaluate true. Same for logical AND, except the first false evaluation will stop the entire circuit.

查看更多
登录 后发表回答