对于非常简单的Ruby On Rails App,最佳的RBAC是什么?

我正在做我自己的第一个Ruby on Rails应用程序,并试图在应用程序的方案中应用RBAC表。我遇到了几个问题,想听听更有经验的人的意见。该应用程序是一个简单的网站,我的用户可以在其中使用Devise登录。每个用户has_many:子级,has_many:注意,他们可以添加,编辑和删除。用户将具有成员,管理员和主持人角色。不可能添加任何其他角色。我当时想给每个用户一个角色。我也在考虑使用以下方法检查用户模型中的用户权限:

class User < ApplicationRecord

  ROLES = %w[member admin moderator].freeze
  devise :database_authenticatable,:registerable,:recoverable,:rememberable,:validatable
  has_many :children
  has_many :notes
  validates :name,presence: true
  validates :last_name,presence: true
  validates :dob,presence: true
  validates :email,presence: true,uniqueness: { case_sensitive: false }
  validates :role,inclusion: { in: ROLES }
  validates :encrypted_password,confirmation: true

  def can? (right)
    self.role.rights.include?(right)
  end

  def can_many? (rights)
    rights.each do |right|
       if !self.can?(right)
         return false
       end
    return true
  end
end

RBAC模型现在如下所示:

class Rbac < ApplicationRecord
  ROLES = %w[member admin moderator].freeze
  RIGHTS = %w[edit_own_note remove_own_note edit_any_note remove_any_note remove_own_image remove_any_image create_own_child create_any_child edit_own_child edit_any_child remove_own_child remove_any_child remove_user].freeze
  validate :role,inclusion: { in: ROLES }
  validate :rights,inclusion: { in: RIGHTS }
end

所以我的问题是:

  1. 构造一个简单应用程序的整个RBAC部分的最佳方法是什么?用户=>角色=> Rignts是绝对必要的,还是简单应用程序的不必要的复杂性?
  2. 就我而言,我应该创建表格:角色,权限,然后是RBAC吗?创建用户和角色之间的关系表?

OR

我应该像以前一样保留它。为用户模型中的每个用户分配一个角色,跳过角色和权限表,仅拥有RBAC关系表?这样简化基于角色的访问会带来任何风险吗?

wxm821016 回答:对于非常简单的Ruby On Rails App,最佳的RBAC是什么?

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3153454.html

大家都在问