module Rbac::Resource

Defined in:

rbac/resource.cr

Instance Method Summary

Instance Method Detail

def authorized?(roleable : Roleable) #

check if a Roleable has any of the roles that the resource has

s = Store.new # includes Resource
s.has_roles :add, :delete

u = User.new # includes Roleable
u.has_roles :add, :edit

s.authorized?(u) # => true because of :add

[View source]
def authorized?(roleable : Roleable, *_roles : Symbol) #

check if a Roleable has a specific role that the resource has

s = Store.new # includes Resource
s.has_roles :add, :delete

u = User.new # includes Roleable
u.has_roles :add, :edit

s.authorized?(u, :add) # => true
s.authorized?(u, :delete) # => false
s.authorized?(u, :edit) # => false because store does not include :edit role

# check multiple rows at once:
s.authorized?(u, :add, :delete) # => false

[View source]
def has_role?(role : Symbol) #

check if a resource has a specific role

s = Store.new # includes Resource
s.has_roles :add, :delete
s.has_role? :add # => true

[View source]
def has_roles(roles : Array(Symbol)) #

add allowed roles

s = Store.new # includes Resource
s.has_roles [:add, :delete]

[View source]
def has_roles(*_roles : Symbol) #

add allowed roles

s = Store.new # includes Resource
s.has_roles :add, :delete

[View source]
def may?(roleable : Roleable, *_roles : Symbol) #

[View source]
def roles #

[View source]