如何在rails中创建用户 - 组模型?启用多重授权

时间:2021-05-29 23:01:56

A user could create a "group", which other users could join in. Each group has its own admin and moderators so on and could do something like creating posts, inviting users, etc.

用户可以创建一个“组”,其他用户可以加入该组。每个组都有自己的管理员和主持人等,可以做一些事情,比如创建帖子,邀请用户等。

I think "has_many through" should be used here, but not sure about the authorization, since the role is based on different groups. The roles set up in CanCan seem not fit into it, admin is just for one group, not the whole site.

我认为应该在这里使用“has_many through”,但不确定授权,因为角色基于不同的组。 CanCan中设置的角色似乎不适合它,admin只适用于一个组,而不是整个站点。

2 个解决方案

#1


1  

Seems like confusion between a user and its role. A "Group" has many "users". A "user" has one (or more) "role(s)" (admin) toward a group "ALPHA". A "user" might have another role ("listener") on another group "DELTA".

似乎是用户与其角色之间的混淆。 “组”有许多“用户”。 “用户”对一组“ALPHA”具有一个(或多个)“角色”(管理员)。 “用户”可能在另一组“DELTA”上具有另一个角色(“监听器”)。

Admin is a role, Moderator and listener are roles just the same.

Admin是一个角色,主持人和监听者的角色是一样的。

#2


0  

You have to create role like user.is_admin_of?(GroupObject) so first step is create role https://github.com/timonv/rollable

你必须创建像user.is_admin_of?(GroupObject)这样的角色,所以第一步是创建角色https://github.com/timonv/rollable

#1


1  

Seems like confusion between a user and its role. A "Group" has many "users". A "user" has one (or more) "role(s)" (admin) toward a group "ALPHA". A "user" might have another role ("listener") on another group "DELTA".

似乎是用户与其角色之间的混淆。 “组”有许多“用户”。 “用户”对一组“ALPHA”具有一个(或多个)“角色”(管理员)。 “用户”可能在另一组“DELTA”上具有另一个角色(“监听器”)。

Admin is a role, Moderator and listener are roles just the same.

Admin是一个角色,主持人和监听者的角色是一样的。

#2


0  

You have to create role like user.is_admin_of?(GroupObject) so first step is create role https://github.com/timonv/rollable

你必须创建像user.is_admin_of?(GroupObject)这样的角色,所以第一步是创建角色https://github.com/timonv/rollable