Firebase Blaze编译器提供的结果不正确

时间:2014-12-22 05:28:05

标签: firebase

我正在尝试为以下Blaze YAML文件编译rules.json

functions:
  - isLoggedIn(): auth.id !== null

schema:
    type: object
    properties:
        projects:
            type: object
            $projectId:
                type: object
                properties:
                    roles:
                        type: object
                        $permissionId:
                            type: object
                            $roleId: {type: boolean}

access:
  - location: /projects/$projectId/
    write: isLoggedIn() && (!next.exists() || next.hasChildren())

当我用blaze编译它时,我得到以下JSON:

{
  "rules":{
    ".write":"false",
    ".read":"false",
    "projects": {
      ".write":"false",
      ".read":"false",
      "$projectId": {
        ".write":"(((false)))",
        ".read":"false",
        "roles": {
          ".write":"((false))",
          ".read":"false",
          "$permissionId": {
            ".write":"((false))",
            ".read":"false",
            "$roleId": {
              ".write":"(((!newData.parent().parent().parent().parent().parent().exists()||!(((newData.parent().parent().parent().parent().parent().isString()||newData.parent().parent().parent().parent().parent().isNumber()||newData.parent().parent().parent().parent().parent().isBoolean()))))&&(!newData.parent().parent().parent().parent().exists()||!(((newData.parent().parent().parent().parent().isString()||newData.parent().parent().parent().parent().isNumber()||newData.parent().parent().parent().parent().isBoolean()))))&&(!newData.parent().parent().parent().exists()||!(((newData.parent().parent().parent().isString()||newData.parent().parent().parent().isNumber()||newData.parent().parent().parent().isBoolean()))))&&(!newData.parent().parent().exists()||!(((newData.parent().parent().isString()||newData.parent().parent().isNumber()||newData.parent().parent().isBoolean()))))&&(!newData.parent().exists()||!(((newData.parent().isString()||newData.parent().isNumber()||newData.parent().isBoolean()))))&&(!newData.exists()||newData.isBoolean())&&auth.id!==null&&(!newData.parent().parent().parent().exists()||newData.parent().parent().parent().hasChildren())))",
              ".read":"false"
            }
          }
        }
      }
    }
  }
}

我原本希望$projectId.write规则包含isLoggedIn() && (!next.exists() || next.hasChildren())的编译版本,但它包含(((false)))

这是火焰中的错误还是我的YAML规则没有正确构建?如果不正确,我哪里出错?

1 个答案:

答案 0 :(得分:0)

它不是一个错误,而是一些与野生动物的嵌套有关的微妙之处。 "使用wildchild可以防止所有上升者被写入。" [1]

您可以在$ projectId上使用wilderchild代替"〜$ projectId" (请注意,出于某些安全考虑,您无法阻止登录用户删除$ permissionId记录[2])

functions:
  - isLoggedIn(): auth.id !== null

schema:
    type: object
    properties:
        projects:
            type: object
            ~$projectId:
                type: object
                properties:
                    roles:
                        type: object
                        $permissionId:
                            type: object
                            $roleId: {type: boolean}

access:
  - location: /projects/$projectId/
    write: isLoggedIn() && (!next.exists() || next.hasChildren())

[1] https://github.com/firebase/blaze_compiler#wildchild

[2] https://github.com/firebase/blaze_compiler#wilderchild