Module: Authpds::Controllers::AuthpdsController::InstanceMethods

Defined in:
lib/authpds/controllers/authpds_controller.rb

Instance Method Summary collapse

Instance Method Details

#current_primary_institutionObject

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


30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/authpds/controllers/authpds_controller.rb', line 30

def current_primary_institution
    @current_primary_institution ||= 
      (InstitutionList.institutions_defined?) ?
        (params["#{institution_param_key}"].nil? or InstitutionList.instance.get(params["#{institution_param_key}"]).nil?) ?
          (primary_institution_from_ip.nil?) ?
            (current_user.nil? or current_user.primary_institution.nil?) ?
              InstitutionList.instance.defaults.first :
                current_user.primary_institution :
                  primary_institution_from_ip :
                    InstitutionList.instance.get(params["#{institution_param_key}"]) :
                      nil
end

#current_userObject

Get the current User if there is a UserSession



20
21
22
# File 'lib/authpds/controllers/authpds_controller.rb', line 20

def current_user
  @current_user ||= current_user_session.record unless current_user_session.nil?
end

#current_user_sessionObject

Get the current UserSession if it exists



15
16
17
# File 'lib/authpds/controllers/authpds_controller.rb', line 15

def current_user_session
  @current_user_session ||= UserSession.find
end

#institution_layoutObject

Determine institution layout based on:

1. primary institution's resolve_layout
2. default - views/layouts/application


51
52
53
54
# File 'lib/authpds/controllers/authpds_controller.rb', line 51

def institution_layout
  (current_primary_institution.nil? or current_primary_institution.application_layout.nil?) ? 
    :application : current_primary_institution.application_layout
end

#institution_param_keyObject



68
69
70
# File 'lib/authpds/controllers/authpds_controller.rb', line 68

def institution_param_key
  @institution_param_key ||= UserSession.institution_param_key
end

#primary_institution_from_ipObject

Grab the first institution that matches the client IP



44
45
46
# File 'lib/authpds/controllers/authpds_controller.rb', line 44

def primary_institution_from_ip
  InstitutionList.instance.institutions_with_ip(request.remote_ip).first unless request.nil?
end

#url_for(options = {}) ⇒ Object

Override to add institution.



57
58
59
60
61
62
# File 'lib/authpds/controllers/authpds_controller.rb', line 57

def url_for(options={})
  options["#{institution_param_key}"] = 
    params["#{institution_param_key}"] unless params["#{institution_param_key}"].nil? or 
      options["#{institution_param_key}"]
  super(options)          
end

#user_session_redirect_url(url) ⇒ Object



64
65
66
# File 'lib/authpds/controllers/authpds_controller.rb', line 64

def user_session_redirect_url(url)
  (url.nil?) ? (request.referer.nil?) ? root_url : request.referer : url
end