Module: Card::Auth::Permissions
- Included in:
- Card::Auth
- Defined in:
- lib/card/auth/permissions.rb
Overview
singleton permission methods
Constant Summary collapse
- RECAPTCHA_DEFAULTS =
{ recaptcha_public_key: "6LeoHfESAAAAAN1NdQeYHREq4jTSQhu1foEzv6KC", recaptcha_private_key: "6LeoHfESAAAAAHLZpn7ijrO4_KGLEr2nGL4qjjis" }.freeze
Instance Method Summary collapse
-
#admin?(user_id) ⇒ true/false
test whether user is an administrator.
-
#always_ok? ⇒ true/false
user has "root" permissions.
-
#always_ok_usr_id?(usr_id) ⇒ true/false
specified user has root permission.
-
#createable_types ⇒ Array of strings
list of names of cardtype cards that current user has perms to create.
- #has_role?(user_id, role_id) ⇒ Boolean
Instance Method Details
#admin?(user_id) ⇒ true/false
test whether user is an administrator
54 55 56 |
# File 'lib/card/auth/permissions.rb', line 54 def admin? user_id has_role? user_id, Card::AdministratorID end |
#always_ok? ⇒ true/false
user has "root" permissions
12 13 14 15 16 17 |
# File 'lib/card/auth/permissions.rb', line 12 def always_ok? usr_id = as_id return false unless usr_id always_ok_usr_id? usr_id end |
#always_ok_usr_id?(usr_id) ⇒ true/false
specified user has root permission
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/card/auth/permissions.rb', line 22 def always_ok_usr_id? usr_id return true if usr_id == Card::WagnBotID # cannot disable always = Card.cache.read("ALWAYS") || {} if always[usr_id].nil? always = always.dup if always.frozen? always[usr_id] = admin? usr_id Card.cache.write "ALWAYS", always end always[usr_id] end |
#createable_types ⇒ Array of strings
list of names of cardtype cards that current user has perms to create
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/card/auth/permissions.rb', line 36 def createable_types type_names = Auth.as_bot do Card.search( { type: Card::CardtypeID, return: :name, not: { codename: ["in"] + Card.config.non_createable_types } }, "find createable types" ) end type_names.select do |name| Card.new(type: name).ok? :create end.sort end |
#has_role?(user_id, role_id) ⇒ Boolean
58 59 60 |
# File 'lib/card/auth/permissions.rb', line 58 def has_role? user_id, role_id Card[user_id].all_roles.include? role_id end |