开发者

Should users have multiple groups?

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?


It's not that hard to let users be in multiple groups. You just need a users_groups table that has a user_id column and a group_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 of admins_groups which has a user_id of an admin, and a group_id of the group they administer. Multiple records for the same user_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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜