名称被占用
名称被占用
  • 发布:2024-03-15 10:12
  • 更新:2024-03-15 13:06
  • 阅读:94

unicloud-db 多表联查带parent_id,权限报错问题

分类:uniCloud
collectionList: [db.collection('ledy-dataset').where({  
                        "tenant_id": uni.getStorageSync("uni-id-pages-userInfo").tenant_id  
                    }).field(  
                        '_id,parent_id,name,data_source_id,type,mode,description,sync_status,update_date').getTemp(),  
                    db.collection('ledy-datasource').field('_id, name as text').getTemp()  
                ]

去掉parent_id能查出来带着就报无权限,把配置权限全去掉也不行
"permission": {
"read": "'data_set_view' in auth.permission && get(database.uni-id-users.${auth.uid}).tenant_id == doc.tenant_id",
"create": "'data_set_add' in auth.permission",
"update": "'data_set_update' in auth.permission && get(database.uni-id-users.${auth.uid}).tenant_id == doc.tenant_id",
"delete": "'data_set_del' in auth.permission && get(database.uni-id-users.${auth.uid}).tenant_id == doc.tenant_id"
},

2024-03-15 10:12 负责人:无 分享
已邀请:
DCloud_uniCloud_WYQ

DCloud_uniCloud_WYQ

这两个表的完整的schema贴出来一下,parent_id上配置的有外键吗

  • 名称被占用 (作者)

    {

    "bsonType": "object",

    "required": [

    "name"

    ],

    "permission": {

    "read": "'data_set_view' in auth.permission && get(database.uni-id-users.${auth.uid}).tenant_id == doc.tenant_id",

    "create": "'data_set_add' in auth.permission",

    "update": "'data_set_update' in auth.permission && get(database.uni-id-users.${auth.uid}).tenant_id == doc.tenant_id",

    "delete": "'data_set_del' in auth.permission && get(database.uni-id-users.${auth.uid}).tenant_id == doc.tenant_id"

    },

    "properties": {

    "_id": {

    "description": "存储文档 ID"

    },

    "parent_id": {

    "bsonType": "string",

    "description": "父ID,用于多级分类",

    "parentKey": "_id",

    "enum": {

    "collection": "ledy-dataset",

    "field": "_id as value, name as text"

    },

    "enumType": "tree",

    "foreignKey": "ledy-dataset._id"

    },

    "name": {

    "bsonType": "string",

    "description": "数据集",

    "title": "数据集",

    "trim": "both"

    },

    "data_source_id": {

    "bsonType": "string",

    "title": "数据源",

    "enum": {

    "collection": "ledy-datasource",

    "field": "_id as value, name as text"

    },

    "foreignKey": "ledy-datasource._id"

    },

    "type": {

    "bsonType": "string",

    "description": "数据集类型",

    "enum": [{

    "text": "数据库",

    "value": "db"

    },

    {

    "text": "SQL",

    "value": "sql"

    },

    {

    "text": "Excel",

    "value": "excel"

    },

    {

    "text": "API",

    "value": "api"

    }

    ],

    "title": "类型"

    },

    "mode": {

    "bsonType": "int",

    "description": "连接模式",

    "enum": [{

    "text": "直连",

    "value": 0

    },

    {

    "text": "定时同步",

    "value": 1

    }

    ],

    "title": "模式",

    "defaultValue": 1

    },

    "description": {

    "bsonType": "string",

    "description": "数据集描述",

    "title": "数据集描述",

    "trim": "both"

    },

    "info": {

    "bsonType": "string",

    "description": "表原始信息"

    },

    "table_field": {

    "bsonType": "array",

    "description": "表字段",

    "properties": {

    "origin_name": {

    "bsonType": "string",

    "description": "字段名"

    },

    "name": {

    "bsonType": "string",

    "description": "字段展示名"

    },

    "ext_field": {

    "bsonType": "bool",

    "description": "是否拓展字段",

    "defaultValue": false

    },

    "is_show": {

    "bsonType": "bool",

    "description": "是否展示",

    "defaultValue": true

    },

    "field_func": {

    "bsonType": "string",

    "description": "计算公式"

    }

    }

    },

    "sync_type": {

    "bsonType": "string",

    "description": "同步方式",

    "enum": [{

    "text": "全量更新",

    "value": "all"

    },

    {

    "text": "增量更新",

    "value": "add"

    }

    ],

    "title": "同步方式"

    },

    "sync_add": {

    "bsonType": "string",

    "description": "增量添加sql"

    },

    "sync_del": {

    "bsonType": "string",

    "description": "增量删除sql"

    },

    "sync_status": {

    "bsonType": "string",

    "description": "同步状态",

    "enum": [{

    "text": "未同步",

    "value": "0"

    },

    {

    "text": "成功",

    "value": "Completed"

    },

    {

    "text": "失败",

    "value": "Error"

    },

    {

    "text": "同步中",

    "value": "sync"

    }

    ],

    "title": "同步状态"

    },

    "create_date": {

    "bsonType": "timestamp",

    "description": "创建时间",

    "defaultValue": {

    "$env": "now"

    }

    },

    "update_date": {

    "bsonType": "timestamp",

    "title": "更新时间",

    "defaultValue": {

    "$env": "now"

    }

    },

    "tenant_id": {

    "bsonType": "string",

    "description": "租户id"

    }

    },

    "version": "0.0.1"

    }

    2024-03-18 11:21

  • 名称被占用 (作者)

    {

    "bsonType": "object",

    "description": "数据源",

    "required": ["name", "type", "tenant_id"],

    "permission": {

    "read": "'data_source_view' in auth.permission && get(database.uni-id-users.${auth.uid}).tenant_id == doc.tenant_id",

    "create": "'data_source_add' in auth.permission",

    "update": "'data_source_update' in auth.permission && get(database.uni-id-users.${auth.uid}).tenant_id == doc.tenant_id",

    "delete": "'data_source_del' in auth.permission && get(database.uni-id-users.${auth.uid}).tenant_id == doc.tenant_id"

    },

    "properties": {

    "_id": {

    "description": "ID,系统自动生成"

    },

    "type": {

    "bsonType": "string",

    "description": "数据库类型",

    "title": "数据库类型",

    "enum": [{

    "text": "MYSQL",

    "value": "mysql"

    }, {

    "text": "SQLSERVER",

    "value": "mssql"

    }]

    },

    "name": {

    "bsonType": "string",

    "description": "连接名称",

    "title": "连接名称",

    "trim": "both"

    },

    "description": {

    "bsonType": "string",

    "description": "类别描述",

    "title": "类别描述",

    "trim": "both"

    },

    "host": {

    "bsonType": "string",

    "description": "连接地址",

    "title": "连接地址"

    },

    "port": {

    "bsonType": "string",

    "description": "端口",

    "title": "端口"

    },

    "username": {

    "bsonType": "string",

    "description": "数据库名称",

    "title": "数据库名称",

    "trim": "both"

    },

    "password": {

    "bsonType": "string",

    "description": "密码,加密存储",

    "title": "密码"

    },

    "status": {

    "bsonType": "string",

    "description": "状态",

    "title": "状态",

    "enum": [{

    "text": "连接失败",

    "value": "Error"

    }, {

    "text": "连接成功",

    "value": "Success"

    }]

    },

    "create_date": {

    "bsonType": "timestamp",

    "description": "创建时间",

    "defaultValue": {

    "$env": "now"

    }

    },

    "tenant_id": {

    "bsonType": "string",

    "description": "租户id"

    }

    },

    "version": "0.0.1"

    }

    2024-03-18 11:22

  • DCloud_uniCloud_WYQ

    回复 名称被占用: 你有看下前端用户的token里面有没有对应的permission吗?(需要注意的是角色与权限不是实时更新的,而是缓存在用户token内的)你说的权限全去了是指全设为true吗?

    2024-03-18 12:03

  • 名称被占用 (作者)

    回复 DCloud_uniCloud_WYQ: 是的全设为true也不行

    2024-03-18 13:33

  • 名称被占用 (作者)

    回复 DCloud_uniCloud_WYQ: parent_id去掉就可以

    2024-03-18 13:34

  • DCloud_uniCloud_WYQ

    回复 名称被占用: 你连的是本地云函数还是云端云函数?

    2024-03-18 14:58

  • 名称被占用 (作者)

    回复 DCloud_uniCloud_WYQ: 本地

    2024-03-18 16:37

  • DCloud_uniCloud_WYQ

    你说的全设为true是把两个表都设为true吗?parent_id上有个foreignKey指向的是本表的_id

    2024-03-20 15:17

  • 名称被占用 (作者)

    回复 DCloud_uniCloud_WYQ: 全设为true,是本表的id呀树状结构数据 需要拆开?

    2024-04-08 17:22

  • DCloud_uniCloud_WYQ

    回复 名称被占用: 树形的使用parentKey,不要用foreignKey

    2024-04-09 11:14

要回复问题请先登录注册