2017-03-06 66 views
0

简单的引用工具。想要仅向“经销商”显示价格/定价。这个结构是否合适?安全节点的数据结构?

如果我把builds\$key\price节点上的一个更具体的规则(限制价格的访问),那么它似乎非交易商试图读取.oncebuilds\-Ke_yHGa-c-acXF5_J9B会失败。

那么,我必须建立一个单独的prices根节点吗?我想是这样...?

然后

{ 
    "...some path...": { 
    ".read": "root.child("dealers/" + auth.uid).val() === true" 
    } 
} 

在此先感谢。

{ 
    "builds" : { 
    "-Ke_yHGa-c-acXF5_J9B" : { 
     "created" : 1488843260381, 
     "last modified" : false, 
     "model" : "1VR", 
     "price" : "1999.00", 
     "status" : "saved", 
     "title" : "test build", 
     "uid" : "q5b9AJgWATdbNF5y2JZctitx1Qx2" 
    } 
    }, 
    "dealers" : { 
    "DsZ1wSUOmsceMKqCKLZwhpg1vjA3" : true, 
    "R9s2qY6p87cas750wJz5wAB3sfJ3" : false, 
    "q5b9AJgWATdbNF5y2JZctitx1Qx2" : true 
    }, 
    "users" : { 
    "DsZ1wSUOmsceMKqCKLZwhpg1vjC2" : { 
     "displayName" : "Eric Doe", 
     "photoUrl" : "http://abs.twimg.com/sticky/default_profile_images/default_profile_3_normal.png", 
     "provider" : "twitter.com" 
    }, 
    "R9s2qY6p87cas750wJz5wAB3sfk5" : { 
     "displayName" : "Ron Royston", 
     "email" : "[email protected]", 
     "provider" : "password" 
    }, 
    "q5b9AJgWATdbNF5y2JZctitx1Qx2" : { 
     "displayName" : "Ron Royston", 
     "photoUrl" : "http://pbs.twimg.com/profile_images/809222728456675365/C-rlXjaN_normal.jpg", 
     "provider" : "twitter.com" 
    } 
    } 
} 

回答

1

Firebase安全规则允许访问完整的节点。一旦授予对节点的访问权限,您就不能在较低级别访问该访问权限。因此,除了价格之外,您无法拥有允许用户访问所有媒体资源的规则。

如果价格需要与该节点的其他部分不同的安全规则,您确实需要将价格从该节点/分支拉出。

对于类似的情况,请参阅我的答案:How to create public/private user profile with Firebase security rules?

+0

感谢您的确认。我花了大约3个小时才弄明白,我不得不考虑这件事。现在看着你的其他答案... –