Sha256: 946ce2c5d15fc85f39877fc49781bf24640fb20e66eaaa0b4839e4d67831738c

Contents?: true

Size: 1.46 KB

Versions: 1

Compression:

Stored size: 1.46 KB

Contents

module Authpds
  module Helpers
    module Institution
      module CurrentInstitutionHelper
        # Include institutional param helper
        include ParamHelper

        # Determine current primary institution based on:
        #   0. institutions are not being used (returns nil)
        #   1. institution query string parameter in URL
        #   2. institution associated with the client IP
        #   3. primary institution for the current user
        #   4. first default institution
        def current_primary_institution
          @current_primary_institution ||= case
            when (institution_param.present? && institutions[institution_param])
              institutions[institution_param]
            when primary_institution_from_ip.present?
              primary_institution_from_ip
            when (@current_user && current_user.primary_institution)
              current_user.primary_institution
            else
              Institutions.defaults.first
            end
        end

        # Grab the first institution that matches the client IP
        def primary_institution_from_ip
          unless request.nil?
            @primary_institution_from_ip ||=
              Institutions.with_ip(request.remote_ip).first
          end
        end
        private :primary_institution_from_ip

        # All institutions
        def institutions
          @institutions ||= Institutions.institutions
        end
        private :institutions
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
authpds-1.1.3 lib/authpds/helpers/institution/current_institution_helper.rb