如何计算/计算嵌套get()的get()的Firestore安全规则访问限制?

时间:2018-06-28 04:29:10

标签: firebase google-cloud-firestore

单文档请求和查询请求有a limit of 10 get()。以下代码段将成为“标准”访问角色的访问次数为多少?

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)
}

如果我有一个带有OR运算符的get()嵌套get()怎么办。那会打多少通电话?

例如

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

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

总而言之,此get()嵌套的get()使用OR运算符对角色“ STANDARD”的访问次数是多少?

1 个答案:

答案 0 :(得分:1)

与所有主要编程语言一样,安全规则从左至右短路其逻辑OR。从左到右评估每个OR,直到其中一个评估为true,或者所有评估为true。逻辑AND相同,除了第一次错误的评估会停止整个电路。