Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ 功能建议 ]资源组关联问题 #190

Closed
yzypals opened this issue May 10, 2019 · 5 comments
Closed

[ 功能建议 ]资源组关联问题 #190

yzypals opened this issue May 10, 2019 · 5 comments
Assignees
Labels
enhancement New feature or request

Comments

@yzypals
Copy link
Collaborator

yzypals commented May 10, 2019

目前遇到的问题/使用障碍

已经关联的用户或实例 被删除后,资源组关联表里不会同步删除

希望如何解决/实现它

修改model字段为外键,用户或实例删除会同步删除资源组信息

其他信息

如果有其他类似的产品功能或者图片信息,可在此提交

@LeoQuote
Copy link
Collaborator

LeoQuote commented May 10, 2019

直接改外键不太可行,目前关联表里关联了两种类型,用户和实例。如果用外键我目前是没找到一个外键关联两个表的做法。

不过这个功能也可以做,一个方案是:

保持原有设计,然后override 用户和实例model的delete方法,在其中加入删除关联信息的代码

另一个方案是:

将关联表拆为两个表,一个是用户关联资源组,一个是实例关联资源组,然后用普通外键进行操作。

@LeoQuote
Copy link
Collaborator

LeoQuote commented May 11, 2019

我自己实践了一下覆盖delete方法, 但是感觉不是特别爽.
建议拆成两个关联表, 这样可以用django原生的多对多关联.
后续可以再加用户组和资源组的关联( 有点晕 ) ,可能可以方便管理
这块感觉还可以再学习一下 RBAC ,还有django原生的关联.
Django原生的关联是

用户 <-> 组
组 <-> 权限
用户 <-> 权限

目前我们的关联是

用户 <-> 资源组 <-> 实例

只要关联上就有权限

RABC

用户 <-> 组
用户 <->角色
组 <-> 角色

在代码中做具体的角色判断

在后续调整中我觉得可以尝试找一找开源模块, 或者自己实现一套rabc权限, 让系统可以更加精细的调整

@LeoQuote LeoQuote added the enhancement New feature or request label May 11, 2019
@yzypals
Copy link
Collaborator Author

yzypals commented May 11, 2019

我目前在做是拆成2个表 这条路再走 ,感觉要改的东西挺多的~!~ 慢慢改ing

@LeoQuote
Copy link
Collaborator

在改的时候建议加上单元测试小步慢慢改,参考我写的单元测试指引 :

#42

@hhyo
Copy link
Owner

hhyo commented May 12, 2019

目前是为了图方便把权限组当做角色来用了,倒是木有找到合适的rbac模块

@hhyo hhyo closed this as completed Jun 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants