firebase - 如何使用 firebase-bolt 定义包含?

标签 firebase firebase-security firebase-realtime-database

我正在使用 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/

相关文章:

firebase - 保护新闻通讯的基本 Firebase 表单

javascript - 我想在从 firebase-database 获取时间后运行一个计时器,如何在 React JS 中使用 setInterval() 将时间减少一秒

swift - Firebase 值未在标签上更新

javascript - 以唯一id作为引用删除firebase上的数据

javascript - 当引用不存在时,为什么 firebase "on" "value"不运行监听器函数,但 "once" "value"却运行?

javascript - 限制一组用户对 firebase 数据库的访问

android - FCM如何在另一个 Activity 中显示来自通知点击的数据

javascript - 唯一键中的 Firebase indexOn 规则

firebase - 如何使用 Flutter 从 Firestore 中的集合中获取特定文档

firebase - 如何限制Firebase存储文件仅适用于付费用户?