首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >允许逐个删除儿童的基本规则

允许逐个删除儿童的基本规则
EN

Stack Overflow用户
提问于 2016-11-21 15:02:07
回答 1查看 171关注 0票数 1

请考虑以下面向用户的防火墙数据库规则。我想知道是否有办法写一条规则,可以一个一个地删除孩子(朋友),但不是一次全部删除?

在这里,一个简单的删除操作将不能工作,因为朋友要么是空的,要么是有孩子的。然而,它可以被更新为有任何其他的孩子,这意味着所有的孩子可以被一次覆盖。

代码语言:javascript
运行
复制
"user":
{
    "$uid":
    {
        /* user can read all user data */
        ".read": "$uid == auth.uid",
        /* allow to add to friends but not delete */
        ".write": "$uid == auth.uid && (!data.child('friends').exists() || newData.child('friends').hasChildren())",
        /* other user data also needs to be writable */
        "name": {},
        /* only explicit user data is allowed */
        "$other": { ".validate": false },
        "friends":
        {
            "$friend_uid": { ".validate": "root.child('user').child($friend_uid).exists()" },
        },
    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-11-27 09:26:00

根据firebase策略,.write策略是由子策略继承的,因此解决方案是针对每个子策略的.write规则。

代码语言:javascript
运行
复制
"user":
{
    "$uid":
    {
        /* user can read all user data */
        ".read": "$uid == auth.uid",
        /* no writing at this level */
        /* ".write": false, */
        /* user data is still writable */
        "name": { ".write":"$uid == auth.uid" },
        /* no longer necessary */
        /*"$other": { ".validate": false },*/
        "friends":
        {
            "$friend_uid": { ".write":"$uid == auth.uid" },
        },
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40723172

复制
相关文章

相似问题

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