module Destiny::User

Public Instance Methods

admin?() click to toggle source
# File lib/destiny/user.rb, line 27
def admin?
  return true if role_hash.try(:[], 'system').try(:[], 'administrator')
end
has_role?(role_name) click to toggle source
# File lib/destiny/user.rb, line 31
def has_role?(role_name)
  roles.pluck(:name).count(role_name.to_s) > 0
end
owner?(obj) click to toggle source
# File lib/destiny/user.rb, line 17
def owner?(obj)
  return id == obj.user_id if obj.respond_to? :user_id
end
permitted?(*privileges) click to toggle source
# File lib/destiny/user.rb, line 4
def permitted?(*privileges)
  return true if is_admin?

  begin
    permitted = role_hash.dig(*privileges)
    permitted = false unless !!permitted == permitted
  rescue Exception => e
    permitted = false
  end

  permitted
end
role_hash() click to toggle source
# File lib/destiny/user.rb, line 21
def role_hash
  @role_hash = {}
  roles.map(&:to_hash).each_entry { |h| @role_hash.deep_merge!(h) }
  @role_hash.with_indifferent_access
end