module Card::Auth::Permissions

singleton permission methods

Public Instance Methods

admin?(user_mark=nil) click to toggle source

test whether user is an administrator @param user_mark [Cardish] @return [true/false]

# File lib/card/auth/permissions.rb, line 36
def admin? user_mark=nil
  (user_mark || as_id).card&.admin?
end
always_ok?() click to toggle source

user has “root” permissions @return [true/false]

# 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() click to toggle source

list of names of cardtype cards that current user has perms to create @return [Array of strings]

# 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
update_always_cache(value) click to toggle source
# File lib/card/auth/permissions.rb, line 40
def update_always_cache value
  always = always_cache
  always = always.dup if always.frozen?
  always[as_id] = value
  Card.cache.write "ALWAYS", always
  value
end

Private Instance Methods

always_cache() click to toggle source
# File lib/card/auth/permissions.rb, line 61
def always_cache
  Card.cache.read("ALWAYS") || {}
end
always_ok_cached?() click to toggle source

specified user has root permission @return [true/false]

# File lib/card/auth/permissions.rb, line 52
def always_ok_cached?
  always = always_cache
  if always[as_id].nil?
    update_always_cache admin?
  else
    always[as_id]
  end
end