Authentication 用于用户建模的Rails多态性
我是Rails 5的新手,我正在尝试使用Desive和CanCanCan对以下场景进行建模:一个商店应用程序。 相关数字包括:管理员、店长、店长、客户、技术员Authentication 用于用户建模的Rails多态性,authentication,devise,authorization,ruby-on-rails-5,cancancan,Authentication,Devise,Authorization,Ruby On Rails 5,Cancancan,我是Rails 5的新手,我正在尝试使用Desive和CanCanCan对以下场景进行建模:一个商店应用程序。 相关数字包括:管理员、店长、店长、客户、技术员 管理员创建StoreManager StoreOfficer可以创建客户信息以注册新客户 StoreOfficer可以查看包含相关信息的所有客户的完整列表 StoreOfficer可以查看所有技术人员的完整列表以及相关信息 StoreManager可以查看所有StoreOfficer的完整列表以及相关信息 StoreManager可使S
- 管理员创建StoreManager
- StoreOfficer可以创建客户信息以注册新客户
- StoreOfficer可以查看包含相关信息的所有客户的完整列表
- StoreOfficer可以查看所有技术人员的完整列表以及相关信息
- StoreManager可以查看所有StoreOfficer的完整列表以及相关信息
- StoreManager可使StoreOfficer使用系统并编辑其信息
- StoreManager可以让StoreOfficers创建的客户使用该系统
- StoreManager可以查看包含相关信息的所有客户的完整列表
FZ在尝试了一些不同的东西之后,我创建了以下令人满意的模式,我在这里为其他人发布了这些模式,以便他们可以使用可靠的东西:
Class User<ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
belongs_to :userable, polymorphic: true
end
你们对这个设置有什么看法?
现在我想把坎坎坎介绍给我的项目。请验证我将要执行的以下步骤:
if user.admin?
can :manage, :all
elsif user.store_manager?
can :read, Customer
can :create, Customer
can :update, Item do |item|
item.try(:user) == user
end
can :destroy, Item do |item|
item.try(:user) == user
end
elsif user.store_officer?
can :read, Customer
end
.
.
.
def customer?
self.userable_type == Customer
end
加载\u和\u授权\u资源
FZ在尝试了一些不同的东西之后,我创建了以下令人满意的模式,我在这里为其他人发布了这些模式,以便他们可以使用可靠的东西:
Class User<ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
belongs_to :userable, polymorphic: true
end
你们对这个设置有什么看法?
现在我想把坎坎坎介绍给我的项目。请验证我将要执行的以下步骤:
if user.admin?
can :manage, :all
elsif user.store_manager?
can :read, Customer
can :create, Customer
can :update, Item do |item|
item.try(:user) == user
end
can :destroy, Item do |item|
item.try(:user) == user
end
elsif user.store_officer?
can :read, Customer
end
.
.
.
def customer?
self.userable_type == Customer
end
加载\u和\u授权\u资源
FZ如果您展示您在
rails
、design
和cancancan
文档之后迄今所取得的成就,您将得到更快的响应。并解释你到底在哪里被卡住了,包括代码示例和相关的错误信息。如果我还需要了解开发这种模式的更好方法,我如何发布一些代码示例?我有以下事实:1-管理员管理一切,并有progressiveid、lastname、secondname和sex作为字段。2-StoreManager与admins具有相同的字段,StoreOfficers与admin具有相同的字段,并引用其作为StoreManager的上司的id。3-客户与管理员具有相同的字段,并引用注册他的店长的id。4-客户不登录系统,但由特定的店长注册。我说,我应该使用STI还是多态关联?DEVICE/cancancan是否会干扰STI或多态性关联?我是否将命令rails generate designe User
应用于class User,或者可能我必须为我需要的每个用户角色创建一个不同的类(class Admin、class StoreOfficer、class StoreManager)?如果您在rails
的文档之后展示您迄今为止所完成的工作,您会得到更快的响应,设计
和cancancan
。并解释你到底在哪里被卡住了,包括代码示例和相关的错误信息。如果我还需要了解开发这种模式的更好方法,我如何发布一些代码示例?我有以下事实:1-管理员管理一切,并有progressiveid、lastname、secondname和sex作为字段。2-StoreManager与admins具有相同的字段,StoreOfficers与admin具有相同的字段,并引用其作为StoreManager的上司的id。3-客户与管理员具有相同的字段,并引用注册他的店长的id。4-客户不登录系统,但由特定的店长注册。我说,我应该使用STI还是多态关联?DEVICE/cancancan是否会干扰STI或多态性关联?我是否将命令rails generate designe User
应用于类用户,或者可能我必须为我需要的每个用户角色(类管理员、类管理员、类管理员)创建一个不同的类?