Sha256: f1f92e8110ddce9708e462abb9badabbf7817f3d4194eb3f2cc886e7e87ef785

Contents?: true

Size: 819 Bytes

Versions: 1

Compression:

Stored size: 819 Bytes

Contents

module Spotlight
  ##
  # Spotlight user mixins for roles
  module User
    extend ActiveSupport::Concern
    included do
      has_many :roles, class_name: 'Spotlight::Role', dependent: :destroy
      has_many :exhibits, class_name: 'Spotlight::Exhibit', through: :roles

      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

    def invite_pending?
      invited_to_sign_up? && !invitation_accepted?
    end

    alias_attribute :user_key, :email

    ##
    # Class-level user mixins
    module ClassMethods
      def find_by_user_key(key)
        find_by email: key
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
blacklight-spotlight-0.13.0 app/models/concerns/spotlight/user.rb