uni-app db schema中permission表达式的或运算符(||)异常

uni-app db schema中permission表达式的或运算符(||)异常

产品分类:uniCloud/App

示例代码:

organization.schema.json

{  
    "bsonType": "object",  
    "required": [],  
    "permission": {  
        "read": "doc.role_owner==auth.uid||doc.role_member==auth.uid"  
    },  
    "properties": {  
        "_id": {  
            "description": "存储文档 ID(用户 ID),系统自动生成"  
        },  
        "name": {  
            "bsonType": "string",  
            "trim": "both",  
            "description": "组织名字"  
        },  
        "role_owner": {  
            "bsonType":"string"  
        },  
        "role_member": {  
            "bsonType":"string"  
        }  
    }  
}
{"_id":{"$oid":"6145538156e6160001a73475"},"name":"org2"}  
{"_id":{"$oid":"6145536e8b76c1000179286f"},"name":"org1"}

操作步骤:

  1. 按上面schema创建organization数据库
  2. 导入测试数据

预期结果:

写成"read": “doc.role_owner==auth.uid||doc.role_member==auth.uid”,应能拦截无权限用户

实际结果:

写成"read": “doc.role_owner==auth.uid||doc.role_member==auth.uid”,无效,无法拦截无权限用户

bug描述:

写成"read": “doc.role_owner==auth.uid”,有效,能拦截无权限用户
写成"read": “doc.role_member==auth.uid”,有效,能拦截无权限用户
写成"read": “doc.role_owner==auth.uid||doc.role_member==auth.uid”,无效,无法拦截无权限用户




更多关于uni-app db schema中permission表达式的或运算符(||)异常的实战教程也可以访问 https://www.itying.com/category-93-b0.html

8 回复

你用的HBuilderX版本多少?连接云端云函数有这个问题吗?试试alpha版本的HBuilderX

更多关于uni-app db schema中permission表达式的或运算符(||)异常的实战教程也可以访问 https://www.itying.com/category-93-b0.html


HBuilderX版本3.2.9.20210927 连接云端云函数也有这个问题

回复 w***@lyjs.ltd: 这个处理的确实不太好,你数据里面就是不带role_owner和role_member是吗?

数据改成这样,也是有问题的,无法正常拦截

回复 w***@lyjs.ltd: 正在调整,上线后会在这个帖子回复你

回复 DCloud_uniCloud_WYQ: 好的,谢谢

回复 w***@lyjs.ltd: 此问题已在线上修复,本地调试插件会在下个HBuilderX的alpha版本更新。你可以通过上传一个schema文件触发云端逻辑更新

在uni-app的db schema中,permission表达式确实存在逻辑运算符的解析问题。根据你的测试,||运算符在当前版本中可能未被正确解析,导致权限控制失效。

针对这个问题,建议采用以下两种解决方案:

方案一:使用$or操作符 将表达式改写为MongoDB风格的查询语法:

"read": "$or:[{'role_owner':auth.uid},{'role_member':auth.uid}]"

方案二:拆分为多个条件 如果上述方案无效,可以尝试:

"read": "doc.role_owner==auth.uid && true || doc.role_member==auth.uid"
回到顶部