授权处理非规格化方案

问题描述 投票:0回答:2

请随意评论和分享的任何反馈,以帮助我找到一个解决方案。谢谢 !

这是授权表定义每个用户的范围。我目前不知道如何在product级范围的数据和处理不同的角色。我相信我的数据库架构是错误的设置。

C创建,R阅读,U更新,D删除

enter image description here

我有PostgreSQL的9以下数据库结构

1)user表里面has_manystores条目。

-----------------------------
| id  | org_tag  |  email   |
|---------------------------|
|  1  |    a     | [email protected] |
|---------------------------|
|  2  |    b     | [email protected] |
|---------------------------|
|  3  |    c     | [email protected] |
-----------------------------

2)stores表包括jsonbemployees,所述user_idtags阵列列

store所有者可以employees增加,这将有取决于authorization特殊role授权店。

I滤波器基于tags阵列scope数据并处理所述授权的存储区。

----------------------------------------------
| id  | user_id  |  employees  |     tags     |
|---------------------------------------------|
|  1  |    1     |  see json1  |  ['a', 'b']  |
|---------------------------------------------|
|  1  |    1     |  see json2  |  ['a', 'c']  |
-----------------------------------------------

json1

[{'email':'[email protected]','role':'owner'},{'email':'[email protected]','role':'trial_editor'}]

tags对应user.org_tag

json2

[{'email':'[email protected]','role':'owner'},{'email':'[email protected]','role':'manager'}]

3)products

trial product editor只能编辑,他被分配到产品。我能范围products通过tags,但我不知道如何处理不同roles

对于防爆。商店经理可以创建产品,而Trial Product Editor只能读取和更新。

--------------------------------
| id  | user_id  |    tags     |
|------------------------------|
|  1  |    1     | ['a', 'b']  |
|------------------------------|
|  1  |    1     | ['a', 'c']  |
--------------------------------
sql ruby-on-rails database postgresql authorization
2个回答
1
投票

你似乎是有桌子太吝啬。你似乎需要:

  • 与每名员工一行employees
  • 与每雇员存储一行storeEmployees(假设员工可以在多于一个的存储)
  • 每店/员工/标签一行storeEmployeeTags

实现一个多到多的使用关系阵列可以是一个合理的选择。你有多个这样的关系,所以我建议你实现数据模型更比列的表。


0
投票

用户

------------------------------------------------------
| id |  org_tag   |     email      |    org_handle   | 
------------------------------------------------------
|  1 |     a      |  [email protected]   |       xyz       | 
------------------------------------------------------ 
|  2 |     b      |  [email protected]   |       xxx       |  
------------------------------------------------------
|  1 |     c      |  [email protected]   |       abc       | 
------------------------------------------------------

角色

------------------------------------------------
| id  |  store_id  |  user_id  |    position   |
------------------------------------------------ 
|  1  |     1      |     1     |     owner     |
------------------------------------------------ 
|  2  |     1      |     2     |    manager    |
------------------------------------------------ 
|  1  |     2      |     2     |  trial_editor |
------------------------------------------------ 

商店

-----------------------------------
| id  |  employees  |  org_handle |
-----------------------------------
|  1  |  see json1  |     abc     |
-----------------------------------
|  2  |  see json2  |     xyz     |
-----------------------------------

员工jsonb是:

[{'email':'[email protected]','role':'owner'},{'email':'[email protected]','role':'trial_editor'}]

产品

--------------------------------
| id  | store_id |   role_id   | 
--------------------------------
|  1  |     1    |      1      |
--------------------------------
|  2  |     2    |      2      |
--------------------------------

Associations

Organization has_many :users
User has_many :stores, through: roles
User has_many :role
User belongs_to :organization
Role belongs_to :user
Role belongs_to :store
Role has_many :products
Store has_many :users, through: roles
Store has_many :roles
Store has_many :products
Product belongs_to :store
Product belongs_to :role
© www.soinside.com 2019 - 2024. All rights reserved.