无法使用Firestore规则中的“获取”部分获取功能以正常工作

时间:2018-07-09 20:11:07

标签: firebase google-cloud-firestore firebase-security-rules

在我的Firestore规则中,我具有以下功能:

//True if the current user is 1 of the admins of this event, false otherwise
function isAnAdminOfEvent(){
  return get(/databases/$(database)/documents/users/$(request.auth.uid)).data.mail in resource.data.admins;
  //return "eUB5Lnl5" in resource.data.admins;
}

以某种方式,此规则始终失败。当我注释第一行并注释掉最后一行时,规则工作正常。请注意,我确定当前用户对象的邮件属性确实设置为“ eUB5Lnl5”。

users对象具有以下获取权限:

match /users/{userId} {
       allow read: if request.auth.uid == userId; //users can only read their own data
}

备注:这是我的规则定义的第一部分,在其中使用“ get”方法。我可能在这里做错了...

在请求中添加了评论:

当前失败的测试代码如下:

//Check that event admins are allowed to update other data of the event, such as the description or color
    CompletableFuture<Boolean> futureEventAdminChangeAction = new CompletableFuture<>();
    mFieldsMap.clear();
    mFieldsMap.put(DESCRIPTION, "An updated description!");
    mFieldsMap.put(COLOR, 3);
    mFieldsMap.put(NAME, "The new name");
    FireUtilEvents.getEvent( key ).set( mFieldsMap, SetOptions.merge()).addOnCompleteListener(task -> futureEventAdminChangeAction.complete( task.isSuccessful() ));
    Assert.assertEquals( true, futureEventAdminChangeAction.get() );

在测试中,我正在验证事件管理员是否可以更新他是管理员的事件。事件数据的更新规则如下:

allow update: if isNoEventOwnerChange() && 
            (isOwner() || (isAnAdminOfEvent() && isNotForbiddenAdminChange()));

在测试中:

  • isNoEventOwnerChange()返回true
  • isOwner()返回false,
  • isNotForbiddenAdminChange()返回true,
  • isAnAdminOfEvent()返回 false (这是意外的)。

1 个答案:

答案 0 :(得分:1)

isAnAdminOfEvent块中放置函数match /databases/{database}/documents的定义。

相关问题