Sha256: 465e944993ae972f7574c26af86658a8b64783c1549e38d960b319a43cb449d5
Contents?: true
Size: 896 Bytes
Versions: 6
Compression:
Stored size: 896 Bytes
Contents
module IAmICan module Resource extend ActiveSupport::Concern included do # Book.that_allow(User.all, to: :read) # Book.that_allow(User.last, to: :write) scope :that_allow, -> (subject, to:) do tmp_role_ids = Array(subject).flat_map(&:temporary_roles).map(&:id).uniq allowed_ids = subject.i_am_i_can.role_model.where(id: (subject._roles.ids + tmp_role_ids).uniq) ._permissions.where(action: to, obj_type: self.name).pluck(:obj_id).uniq where(id: allowed_ids) end end class_methods do # def that_allow(subject) # ThatAllow.new(self, subject) # end end end # class ThatAllow # attr_accessor :records, :subject # # def initialize(records, subject) # self.records = records # self.subject = subject # end # # def to(action) # end # end end
Version data entries
6 entries across 6 versions & 1 rubygems