javascript - 如何指定firebase数据库规则“超出范围”?
问题描述
我的数据库结构现在看起来像这样:
database: {
users: {
uniqueUserId1: {
name: "an user",
company: "Company1",
rank: "manager"
}
}
rota: {
Company1: {
2018: "rota for 2018"
}
}
}
所以我不想让用户阅读所有公司的名单,只是他们拥有公司的名单。
对于用户规则来说,这并不难:
rules: {
"rules": {
"users": {
"$uid": {
".read": "$uid === auth.uid",
".write": "$uid === auth.uid"
}
},
//But a bit complicated for things "outside the scope".
//What I want is something like:
"rota": {
"$company": {
".read": "$company === users[auth.uid].company",
".write": "$company === users[auth.uid].company && users[auth.uid].rank === 'manager'"
}
}
}
}
我知道这些规则不起作用,但是如何解决这个问题呢?
解决方案
You'll need to build the path to the user data by starting with root
. So you're looking for something like this:
".read": "$company === root.child('users').child(auth.uid).child('company').val()",
Also see:
推荐阅读
- validation - 来自另一个 Google 表格的数据验证
- c++ - Unity 在 Unreal Engine 4 C++ 中的“Vector3.Slerp”等价物?
- rest - 如何使用 REST API 客户端工具(邮递员或 jemeter)发送内容类型为:multipart/related 的请求
- python - Auto-Sklearn:是否可以将 imblearn 的指标集成为得分手?
- php - 我如何解决我的 wordpress php 标头更新文件问题
- sql - 在 SQL 的 update 子句中实现 select 语句
- javascript - 如何检查用户是否在没有 request.session 的情况下登录
- android - 内部 recyclerview 内部支架 切割 切割
- javascript - 如何使用ajax php mysql删除行
- postgresql - 如何使用函数或过程优化 postgresql