首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >访问规则:允许基于访问规则的只读/读写访问。

访问规则:允许基于访问规则的只读/读写访问。
EN

Stack Overflow用户
提问于 2017-08-15 19:33:48
回答 1查看 72关注 0票数 0

我想写一个购物清单应用,在那里,用户将能够给予只读或读写权限给其他用户。

我计划数据库如下所示:

代码语言:javascript
复制
{
    "lists": {
        "1": {
            "title": "List #1",
            "items": [...],
            "owner": "user1",
            "read_only_access": [ {"user2": true} ],
            "read_write_access": [ {"user3": true} ],
        },
        "2": {
            "title": "List #1",
            "items": [...],
            "owner": "user1",
            "read_only_access": [ {"user3": true} ],
            "read_write_access": [],
        },
        "3": { ... }
    },
    "users": {
        "user1": {
            "name": "John",
        },
        "user2": { ... },
        "user3": { ... }
    }
}

如何定义“列表”树的访问规则,以便:

  • 业主将有权读-写访问他的所有名单。
  • read_only_access列表中的用户将具有读取权限
  • read_write_access列表中的用户将具有读写权限。
  • 既不是便笺的所有者,也不是便笺的read_only_access和read_write_access列表的用户甚至都无法读取对它的访问权限。

谢谢!

斯拉维克

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-08-16 02:43:41

数据库

代码语言:javascript
复制
{
  "list-users" : {
    "1": {
      "user2" : {
        "access" : { "read" : true, "write": false }
      },
      "user3" : {
        "access" : { "read": false, "write" : true }
      }
    },
    "2": {
      "user3" : {
        "access" : { "read" : true, "write": false }
      }
    }
  },
  "lists" : {
    "1": {
      "items": [ ... ],
      "owner" : "user1",
      "title" : "List #1"
    },
    "2": {
      "items": [ ... ],
      "owner" : "user1",
      "title" : "List #2"
    },
    "3": {
      "items": [ ... ],
      "owner" : "user1",
      "title" : "List #3"
    }
  },
  "users" : {
    "user1" : { "name" : "John" },
    "user2" : { "name" : "Jane" },
    "user3" : { "name" : "Joel" }
  }
}

规则

代码语言:javascript
复制
{
  "rules": {
    "list-users": {
      "$lid": {
        "$uid": {
          ".write": "auth.uid === root.child('lists/$lid/owner').val()",
          ".validate": "newData.child('access').hasChildren(['read', 'write'])"
        }
      }
    },
    "lists": {
      "$lid": {
        ".read": "data.child('owner').val() === auth.uid || root.child('list-users').child($lid).child(auth.uid).child('/access/read').val() === true",
        ".write": "data.child('owner').val() === auth.uid || root.child('list-users').child($lid).child(auth.uid).child('access/write').val() === true"
      }
    },
    "users": {
      "$uid": {
        ".read": "auth !== null",
        ".write": "auth.uid === $uid"
      }
    }
  }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45700206

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档