用户应该有多个组吗?
我正在从事一个个人/有趣的项目。我正在使用 cakePHP,但这更多是一个数据库设计问题。
目前,我的 USERS 表中有一个名为 group 的字段。我有一个 GROUPS 表,其中列出了几个组,例如 admin、confirmed、new 等...
我还有一个 NOTIFICATIONS 表,用于跟踪不同类型的通知。我想在组的 NOTIFICATIONS 表中添加一个字段,其中组来自 GROUPS 表。
问题是,如果我将通知标记为“已确认”组的一部分,如何确保“管理员”组中的用户也可以访问它。本质上,我希望“管理员”能够访问“已确认”所做的一切,甚至更多。
1)允许用户属于多个组会更好吗?那么管理员同时属于管理员组和确认组吗?
2)我的代码中应该有一些额外的逻辑吗?就像我可以向其传递“组”的函数一样,它会告诉我用户是否有权访问该组?
3)...其他方法?我在想这个问题有错吗?
I am working on a personal / for fun project. I am using cakePHP but this is more of a database design question.
Currently I have a field called group in my USERS table. I have a GROUPS table that list several groups like admin, confirmed, new etc...
I also have a NOTIFICATIONS table that I use to track different types of notifications. I want to add a field in the NOTIFICATIONS table for group, where group is from the GROUPS table.
The problem is if I tag a notification as being part of the "confirmed" group, how do I make sure users in the "admin" group also have access to it. Essentially I want "admins" to have access to everything "confirmed" do, and more.
1) Would it be better to allow users to be part of multiple groups. So a admin is in both the admin and confirmed group?
2) Should I have some extra logic in my code. Like a function that I can pass a "group" to and it will tell me if the user has access to that group?
3) ... Other approaches? I am thinking about this wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
让用户属于多个组并不难。您只需要一个包含
user_id
列和group_id
列的users_groups
表。更大的问题是:您的应用程序这样做有意义吗?这样做的理由是什么?不这样做的原因是什么?
另外,我不确定“确认组”是什么意思,但这听起来更像是一个状态指示器,而不是真正的“组”。但在不了解详细要求的情况下,很难确定。
更新:
如果只有管理员可以加入多个组,那么最好只允许用户加入一个组。然后,为了指示用户是否也是管理员,您可能需要一个
is_admin
指示器。当然,管理员仍然必须位于某些组中(除非您允许用户位于零个组中),因此您也可以将他们放入“admin”组中。或者在这种情况下,管理员只是*某些组的管理员,而不是全部组的管理员?在这种情况下,您可以有一个admins_groups
表,其中包含管理员的user_id
和他们管理的组的group_id
。同一user_id
的多个记录允许管理员用户管理非常特定的组。那么...您的用户属于多个组有意义吗?如果现在不想要,将来会是你想要的吗?
It's not that hard to let users be in multiple groups. You just need a
users_groups
table that has auser_id
column and agroup_id
column.The bigger question is: does it make sense for your application to do this? What are the reasons to do it? What are the reasons not to do it?
Also, I'm not sure what "confirmed group" means, but that sounds more like a status indicator than a true "group". But without knowing the detailed requirements, it's hard to say for sure.
Update:
If only admins will have the possibility to be in multiple groups, then it might be better to only allow users to be in one group. Then to indicate if a user is also an admin, you might want to have an
is_admin
indicator. Of course, the admins will still have to be in some group (unless you allow users to be in zero groups) so you could also put them in the "admin" group. Or is this a situation where an admin is only an admin of *some groups, but not all? In that case, you could have a table ofadmins_groups
which has auser_id
of an admin, and agroup_id
of the group they administer. Multiple records for the sameuser_id
allows the admin user to administer very specific groups.So... does it make sense for your users to be in multiple groups? If not now, is it something you may want in the future?