找不到函数错误:名称:[get]。错误:提供了无效的参数来调用。函数:[get],参数:[“ || invalid_argument ||”]

时间:2019-06-13 10:27:04

标签: firebase permissions google-cloud-firestore firebase-security-rules user-roles

我正在尝试编写Firestore规则,需要从数据库的“用户”集合中获取用户,然后从“权限”集合中获取她/他的相应Permissions对象。

这是数据库的外观:

在用户集中,我有此条目:

{
    id: 'USER_ID',
    permissionsId: 'PERMISSIONS_1'
}

在权限集合中,我有以下条目:

{
    id: 'PERMISSIONS_1',
    content: {
        view: true,
        create: false,
        update: false,
        delete: false,
    }
}

这些是我的规则:

service cloud.firestore {
  match /databases/{database}/documents {

    function userPermissionsId() {
       return get(/databases/$(database)/documents/users/USER_ID).data.permissionsId;
    }

    function userPermissions(id) {
       return get(/databases/$(database)/documents/permissions/$(id)).data;
    }

    function getPermission(profileId, dataType, action) {
        return userPermissions(profileId)[dataType][action];
    }

    match /{collection}/{document=**} {

        // The below code returns true:
        // allow read: if userPermissionsId() == 'PERMISSIONS_1'
        // The above proves that the function userPermissionsId() is working properly and returning the permissions ID.

        // The below code also returns true:
        // allow read: if getPermission('PERMISSIONS_1', 'content', 'view');
        // The above proves that the function getPermission() is working properly when receiving a correct ID.

        // HOWEVER!! Combining the 2 won't work:
        allow read: if getPermission(userPermissionsId(), 'content', 'view');
        // This will throw the below error in the simulator.

    }
  }
}

尝试模拟时出错:

运行模拟时出错-错误:simulator.rules行[9]的列[15]。找不到函数错误:名称:[get]。错误:提供了无效的参数来调用。函数:[get],参数:[“ || invalid_argument ||”]

0 个答案:

没有答案