我有一个限制对象的子对象访问的问题。

我需要的规则:
roles - read
-- UID
--- SUPUSR
---- settings = read only
--- store = write and read我的规则
"roles":{
".read":"auth != null",
".write":"root.child('roles/SUPUSR/').child(auth.uid).child('settings').child('pri_enabled').val() == 1 || root.child('roles/USERS/').child(auth.uid).child('settings').child('pri_enabled').val() == 1",
"settings":{
".read":"auth != null",
".write":false
}如果我以上面的方式保留它,它继承了写作的“角色”规则。
发布于 2021-03-23 14:29:25
叶栅,一旦授予权限,就不能撤消它。因此,如果您允许对/roles进行写访问,任何人都可以写入/roles的任何子级,无论是自己的还是其他人的数据。
其他说明:
/roles和/roles/settings,这在数据库树中太高了,您应该设置/roles/SUPUSR/someUserId、/roles/SUPUSR/someUserId/settings等规则。auth != null的使用似乎不合适。任何登录用户应该能够读取任何其他用户的角色吗?这只适用于超级用户吗?{
"rules": {
"roles": {
"SUPUSR": {
"$uid": {
// any data under /roles/SUPUSR/$uid is readable to logged in users
".read": "auth != null",
"nome": {
// only this user can update nome, it also must be a string
".write": "auth.uid === $uid",
".validate": "newData.isString()"
},
"role": {
// only this user can update role, and it must be one of a select number of string values
".write": "auth.uid === $uid",
".validate": "newData.isString() && newData.val().matches(/^(R&S|Admin|etc)$/)"
},
"store": {
".write": "root.child('roles/SUPUSR/').child(auth.uid).child('settings').child('pri_enabled').val() == 1 || root.child('roles/USERS/').child(auth.uid).child('settings').child('pri_enabled').val() == 1"
}
// any other keys are ".write": false, by default, which includes "settings"
}
}, // end /rules/roles/SUPUSR
"USERS": {
"$uid": {
...
}
}, // end /rules/roles/USERS
...
}, // end /rules/roles
...
}
}https://stackoverflow.com/questions/66763551
复制相似问题