Module: Card::Auth::Permissions
- Included in:
- Card::Auth
- Defined in:
- lib/card/auth/permissions.rb
Overview
singleton permission methods
Instance Method Summary collapse
-
#admin?(user_mark = nil) ⇒ true/false
test whether user is an administrator.
-
#always_ok? ⇒ true/false
user has “root” permissions.
-
#createable_types ⇒ Array of strings
list of names of cardtype cards that current user has perms to create.
- #has_role?(role_mark, user_mark = nil) ⇒ Boolean
- #update_always_cache(value) ⇒ Object
Instance Method Details
#admin?(user_mark = nil) ⇒ true/false
test whether user is an administrator
36 37 38 39 |
# File 'lib/card/auth/permissions.rb', line 36 def admin? user_mark=nil user_mark ||= as_id has_role? Card::AdministratorID, user_mark end |
#always_ok? ⇒ true/false
user has “root” permissions
7 8 9 10 11 12 13 14 |
# File 'lib/card/auth/permissions.rb', line 7 def always_ok? case as_id when WagnBotID then true # cannot disable when nil then false else always_ok_cached? end end |
#createable_types ⇒ Array of strings
list of names of cardtype cards that current user has perms to create
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/card/auth/permissions.rb', line 18 def createable_types type_names = Auth.as_bot do Card.search( { type: Card::CardtypeID, return: :name, not: { codename: ["in"] + Set.basket[:non_createable_types] } }, "find createable types" ) end type_names.select do |name| Card.new(type: name).ok? :create end.sort end |
#has_role?(role_mark, user_mark = nil) ⇒ Boolean
41 42 43 44 45 46 |
# File 'lib/card/auth/permissions.rb', line 41 def has_role? role_mark, user_mark=nil user_mark ||= as_id return false unless (role_id = role_mark&.card_id) Card[user_mark].all_enabled_roles.include? role_id end |