Sha256: eb3b9b9e19873dd119a299ed41808184ba5d88d84a37f6ebdbc660ef0a1c43ee

Contents?: true

Size: 638 Bytes

Versions: 16

Compression:

Stored size: 638 Bytes

Contents

module Spotlight
  ##
  # Spotlight user mixins for roles
  module 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

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

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
blacklight-spotlight-0.11.0 app/models/concerns/spotlight/user.rb
blacklight-spotlight-0.10.3 app/models/concerns/spotlight/user.rb
blacklight-spotlight-0.10.2 app/models/concerns/spotlight/user.rb
blacklight-spotlight-0.10.1 app/models/concerns/spotlight/user.rb
blacklight-spotlight-0.10.0 app/models/concerns/spotlight/user.rb
blacklight-spotlight-0.9.2 app/models/concerns/spotlight/user.rb
blacklight-spotlight-0.9.1 app/models/concerns/spotlight/user.rb
blacklight-spotlight-0.9.0 app/models/concerns/spotlight/user.rb
blacklight-spotlight-0.8.2 app/models/concerns/spotlight/user.rb
blacklight-spotlight-0.8.1 app/models/concerns/spotlight/user.rb
blacklight-spotlight-0.8.0 app/models/concerns/spotlight/user.rb
blacklight-spotlight-0.7.2 app/models/concerns/spotlight/user.rb
blacklight-spotlight-0.7.1 app/models/concerns/spotlight/user.rb
blacklight-spotlight-0.7.0 app/models/concerns/spotlight/user.rb
blacklight-spotlight-0.6.0 app/models/concerns/spotlight/user.rb
blacklight-spotlight-0.5.0 app/models/concerns/spotlight/user.rb