我正在使用 firebase-bolt 来设置我的规则。
我的 bolt :
// ######## CONTENTS
path /contents {
read() = true;
index() = ["dt_created"];
}
path /contents/$id is Timestamped<Contents> {
write() = isSignedIn() && isAllowEdit(this);
}
type Contents {
text : String,
address : String,
organization: String | Null,
location: String | Null,
map_lat : String,
map_lng : String,
num_favorite: Number,
num_comment: Number,
num_denounce: Number,
removed: Boolean,
category_id : String,
user_id : String,
photos: String[]
}
//
// Helper Functions
//
isSignedIn() = auth != null;
isAllowEdit(value) = (prior(value) == null || newData.child('user_id').val() == auth.uid);
我希望帖子的唯一所有者可以编辑,但任何人都可以更新计数器。
我认为:
"contents": {
"$id": {
"num_favorite": {
".write": true
....
不确定是否可能。但是我可以创建规则来仅编辑包含的字段吗?
最佳答案
常规 Firebase 安全规则中的这一点:
"contents": {
"$id": {
"num_favorite": {
".write": true
}
在 Bolt 上翻译为:
path /contents/$id/num_favorite {
write() = true;
}
这会起作用,因为您添加新权限,而不是尝试删除现有权限(即 not possible in Firebase's security rules language )。
但我会考虑将投票分离到自己的更高级别节点中:
path /favorite_counts/$id {
write() = true;
}
这使您的安全规则更加简单且彼此更加隔离。
关于firebase - 如何使用 firebase-bolt 定义包含?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34613402/