Class: SignIn::RedirectUrlGenerator

Inherits:
Object
  • Object
show all
Defined in:
app/services/sign_in/redirect_url_generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(redirect_uri:, terms_redirect_uri: nil, terms_code: nil, params_hash: {}) ⇒ RedirectUrlGenerator

Returns a new instance of RedirectUrlGenerator.



7
8
9
10
11
12
# File 'app/services/sign_in/redirect_url_generator.rb', line 7

def initialize(redirect_uri:, terms_redirect_uri: nil, terms_code: nil, params_hash: {})
  @redirect_uri = redirect_uri
  @terms_redirect_uri = terms_redirect_uri
  @terms_code = terms_code
  @params_hash = params_hash
end

Instance Attribute Details

#params_hashObject (readonly)

Returns the value of attribute params_hash.



5
6
7
# File 'app/services/sign_in/redirect_url_generator.rb', line 5

def params_hash
  @params_hash
end

#redirect_uriObject (readonly)

Returns the value of attribute redirect_uri.



5
6
7
# File 'app/services/sign_in/redirect_url_generator.rb', line 5

def redirect_uri
  @redirect_uri
end

#terms_codeObject (readonly)

Returns the value of attribute terms_code.



5
6
7
# File 'app/services/sign_in/redirect_url_generator.rb', line 5

def terms_code
  @terms_code
end

#terms_redirect_uriObject (readonly)

Returns the value of attribute terms_redirect_uri.



5
6
7
# File 'app/services/sign_in/redirect_url_generator.rb', line 5

def terms_redirect_uri
  @terms_redirect_uri
end

Instance Method Details

#full_redirect_uriObject (private)



22
23
24
25
26
27
28
29
# File 'app/services/sign_in/redirect_url_generator.rb', line 22

def full_redirect_uri
  if terms_code
    Rails.logger.info('Redirecting to /terms-of-use', type: :sis)
    return terms_of_use_redirect_url
  end

  original_redirect_uri_with_params
end

#original_redirect_uri_with_paramsObject (private)



31
32
33
# File 'app/services/sign_in/redirect_url_generator.rb', line 31

def original_redirect_uri_with_params
  "#{redirect_uri}?#{params_hash.to_query}"
end

#performObject



14
15
16
17
18
# File 'app/services/sign_in/redirect_url_generator.rb', line 14

def perform
  renderer.render(template: 'oauth_get_form',
                  locals: { url: full_redirect_uri },
                  format: :html)
end

#rendererObject (private)



35
36
37
38
39
40
41
# File 'app/services/sign_in/redirect_url_generator.rb', line 35

def renderer
  @renderer ||= begin
    renderer = ActionController::Base.renderer
    renderer.controller.prepend_view_path(Rails.root.join('lib', 'sign_in', 'templates'))
    renderer
  end
end

#terms_of_use_paramsObject (private)



47
48
49
# File 'app/services/sign_in/redirect_url_generator.rb', line 47

def terms_of_use_params
  { redirect_url: original_redirect_uri_with_params, terms_code: }
end

#terms_of_use_redirect_urlObject (private)



43
44
45
# File 'app/services/sign_in/redirect_url_generator.rb', line 43

def terms_of_use_redirect_url
  "#{terms_redirect_uri}?#{terms_of_use_params.to_query}"
end