【发布时间】:2023-03-18 14:52:01
【问题描述】:
请随时发表评论并分享任何反馈,以帮助我找到解决方案。谢谢!
这是定义每个用户范围的授权表。
我目前不知道如何在product 级别确定数据范围并处理不同的角色。我认为我的数据库架构设置错误。
C 创建,R 读取,U 更新,D 删除
我使用 postgresql 9
具有以下数据库结构1) user table has_many stores table 中的条目。
-----------------------------
| id | org_tag | email |
|---------------------------|
| 1 | a | a@em.com |
|---------------------------|
| 2 | b | b@em.com |
|---------------------------|
| 3 | c | c@em.com |
-----------------------------
2) stores 表包含 jsonb 列 employees、user_id 和 tags 数组列
store 所有者可以将employees 添加到商店,这将根据role 获得特殊的authorization 授权。
我根据tags数组将store过滤成scope的数据并处理授权。
----------------------------------------------
| id | user_id | employees | tags |
|---------------------------------------------|
| 1 | 1 | see json1 | ['a', 'b'] |
|---------------------------------------------|
| 1 | 1 | see json2 | ['a', 'c'] |
-----------------------------------------------
json1 的值为
[{'email':'a@em.com','role':'owner'},{'email':'b@em.com','role':'trial_editor'}]
tags 对应于user.org_tag
json2 的值为
[{'email':'a@em.com','role':'owner'},{'email':'c@em.com','role':'manager'}]
3) products 表
trial product editor 只能编辑分配给他的产品。
我可以通过tags 确定products 的范围,但我不知道如何处理不同的roles
例如。 Store Manager 可以创建产品,而Trial Product Editor 只能读取和更新。
--------------------------------
| id | user_id | tags |
|------------------------------|
| 1 | 1 | ['a', 'b'] |
|------------------------------|
| 1 | 1 | ['a', 'c'] |
--------------------------------
【问题讨论】:
标签: sql ruby-on-rails database postgresql authorization