Sha256: 0f1d967d170cf53d9deb2ee0c67fe986a43f23d894ee145050f269121d94f5e5

Contents?: true

Size: 1.01 KB

Versions: 17

Compression:

Stored size: 1.01 KB

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, source: 'resource', source_type: 'Spotlight::Exhibit'

      before_create :add_default_roles
    end

    def superadmin?
      roles.where(role: 'admin', resource: Spotlight::Site.instance).any?
    end

    def exhibit_roles
      roles.where(resource_type: 'Spotlight::Exhibit')
    end

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

    def add_default_roles
      roles.build role: 'admin', resource: Spotlight::Site.instance 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

17 entries across 17 versions & 1 rubygems

Version Path
blacklight-spotlight-0.22.0 app/models/concerns/spotlight/user.rb
blacklight-spotlight-0.21.0 app/models/concerns/spotlight/user.rb
blacklight-spotlight-0.20.3 app/models/concerns/spotlight/user.rb
blacklight-spotlight-0.20.2 app/models/concerns/spotlight/user.rb
blacklight-spotlight-0.20.1 app/models/concerns/spotlight/user.rb
blacklight-spotlight-0.20.0 app/models/concerns/spotlight/user.rb
blacklight-spotlight-0.19.2 app/models/concerns/spotlight/user.rb
blacklight-spotlight-0.19.1 app/models/concerns/spotlight/user.rb
blacklight-spotlight-0.19.0 app/models/concerns/spotlight/user.rb
blacklight-spotlight-0.18.0 app/models/concerns/spotlight/user.rb
blacklight-spotlight-0.17.1 app/models/concerns/spotlight/user.rb
blacklight-spotlight-0.17.0 app/models/concerns/spotlight/user.rb
blacklight-spotlight-0.16.0 app/models/concerns/spotlight/user.rb
blacklight-spotlight-0.15.0 app/models/concerns/spotlight/user.rb
blacklight-spotlight-0.14.2 app/models/concerns/spotlight/user.rb
blacklight-spotlight-0.14.1 app/models/concerns/spotlight/user.rb
blacklight-spotlight-0.14.0 app/models/concerns/spotlight/user.rb