Firebase SecurityRules和FirebaseArray

时间:2016-06-02 16:47:46

标签: firebase angularfire firebase-security

我对Firebase很陌生,而且我正在实施我的第一个WebApp。 WebApp应该是我们活动的管理系统(我们是一家活动公司)。

所以我的数据库结构类似于:

{
  "employees" : {
    "y4j2NYsc9waWzLOi4fH7HJFkZsj1" : {
      "email" : "emailadress",
      "events" : {
        "-KImpJr6asZfG28vCF5I" : {
          "isPlanned" : true
        },
        "-KImqNoVIJjeiU-f1FtM" : {
          "isPlanned" : true
        }
      },
      "givenname" : "Tobias",
      "role" : 10,
      "surname" : "K.",
      "uid" : "y4j2NYsc9waWzLOi4fH7HJFkZsj1"
    }
  },
  "events" : {
    "-KImpJr6asZfG28vCF5I" : {
      "date" : 1464386400000,
      "employees" : [ "58438e51-40a8-4c60-bd28-d9f5ee2f2871", "y4j2NYsc9waWzLOi4fH7HJFkZsj1" ],
      "name" : "Schützenfest"
    },
    "-KImpXeis1gDGGCWIx83" : {
      "date" : 1467237600000,
      "employees" : [ "0e9f20c0-547d-46e9-ad01-c7152812a3b2", "658feaf6-26a2-4ea5-b932-a661191f0f38" ],
      "name" : "Sommerfest"
    }
  },
  "roles" : {
    "Admin" : 99,
    "Chef" : 50,
    "Freelancer" : 15,
    "Mitarbeiter" : 20,
    "Praktikant" : 10
  }
}

我的安全规则如下:

{
  "rules":    {
    "events": {
      "$event": {
        ".read": "root.child('employees/' + auth.uid + '/role').val() >= 20 || root.child('employees/' + auth.uid + '/events/' + $event + '/isPlanned').val() === true",
        ".write": "root.child('employees/' + auth.uid + '/role').val() >= 20 || root.child('employees/' + auth.uid + '/events/' + $event + '/isPlanned').val() === true"
          }
      },
    "employees": {
      "$employee": {
          ".read": "auth !== null",
        "role": {".write": "root.child('employees/' + auth.uid + '/role').val() >= 50"},
        "$other": {".write" : "$employee === auth.uid"}
      }
    },
      "roles": {
        ".read": "auth !== null",
          ".write": false
      }
  }
}

我将实现20岁以下角色的员工只能看到他们必须工作的事件。

在我的代码中,我有一个列出所有事件的页面。如果员工的角色低于20,那么只应该有他必须工作的事件。 我的假设是,当我做的时候

var ref = new Firebase("https://myid.firebaseio.com/events");
var allEvents = $firebaseArray(ref);

我将获得所有活动,我的员工可以访问。但我得到这样的错误:

  

错误:permission_denied:客户无权访问所需数据。

有没有办法实现我的愿望?

非常感谢!

祝福

托比

0 个答案:

没有答案
相关问题