Sha256: 702805a1b4dd8ec267c9ffa327976e0c3ed94817c5745a938376737178dac491

Contents?: true

Size: 506 Bytes

Versions: 4

Compression:

Stored size: 506 Bytes

Contents

module Spotlight::User
  extend ActiveSupport::Concern
  included do
    has_many :roles, class_name: 'Spotlight::Role'

    before_create :add_default_roles
  end

  def superadmin?
    admin_roles.where(exhibit_id: nil).any?
  end

  def admin_roles
    roles.where(role: 'admin')
  end

  def add_default_roles
    roles.build role: 'admin' unless self.class.any?
  end

  alias_attribute :user_key, :email

  module ClassMethods
    def find_by_user_key(key)
      find_by email: key
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
blacklight-spotlight-0.4.1 app/models/concerns/spotlight/user.rb
blacklight-spotlight-0.3.1 app/models/concerns/spotlight/user.rb
blacklight-spotlight-0.3.0 app/models/concerns/spotlight/user.rb
blacklight-spotlight-0.2.0 app/models/concerns/spotlight/user.rb