module Destiny::User

Public Instance Methods

admin?()

compatibility with The_Role gem

Alias for: is_admin?
has_grant?(section_name, privilege)
Alias for: permitted?
has_role?(role_name) click to toggle source
# File app/models/concerns/destiny/user.rb, line 39
def has_role?(role_name)
  roles.pluck(:name).count(role_name.to_s) > 0
end
is_admin?() click to toggle source
# File app/models/concerns/destiny/user.rb, line 31
def is_admin?
  return true if role_hash.try(:[], 'system').try(:[], 'administrator')
end
Also aliased as: admin?
owner?(obj) click to toggle source
# File app/models/concerns/destiny/user.rb, line 21
def owner?(obj)
  return id == obj.user_id if obj.respond_to? :user_id
end
permitted?(section_name, privilege) click to toggle source
# File app/models/concerns/destiny/user.rb, line 13
def permitted?(section_name, privilege)
  return true if is_admin?
  return false unless role_hash[section_name]
  return false unless role_hash[section_name].key? privilege

  role_hash[section_name][privilege]
end
Also aliased as: has_grant?
role_hash() click to toggle source
# File app/models/concerns/destiny/user.rb, line 25
def role_hash
  @role_hash = {}
  roles.map(&:to_hash).each_entry { |h| @role_hash.deep_merge!(h) }
  @role_hash.with_indifferent_access
end