Class: V0::TermsOfUseAgreementsController
Constant Summary
ApplicationController::VERSION_STATUS
SignIn::Authentication::BEARER_PATTERN
ExceptionHandling::SKIP_SENTRY_EXCEPTION_TYPES
Instance Attribute Summary
#current_user
Instance Method Summary
collapse
#clear_saved_form, #cors_preflight, #pagination_params, #render_job_id, #routing_error, #set_csrf_header
Methods included from Traceable
#set_trace_tags
#set_tags_and_extra_context, #tags_context, #user_context
#log_exception_to_sentry, #log_message_to_sentry, #non_nil_hash?, #normalize_level, #rails_logger, #set_sentry_metadata
#append_info_to_payload
#access_token, #access_token_authenticate, #authenticate, #authenticate_access_token, #bearer_token, #cookie_access_token, #handle_authenticate_error, #load_user, #load_user_object, #scrub_bearer_token, #validate_request_ip
Methods included from Headers
#set_app_info_headers
#render_errors, #report_mapped_exception, #report_original_exception, #skip_sentry_exception?, #skip_sentry_exception_types
#authenticate, #clear_session, #extend_session!, #load_user, #log_sso_info, #render_unauthorized, #reset_session, #set_api_cookie!, #set_current_user, #set_session_expiration_header, #set_session_object, #sign_in_service_exp_time, #sign_in_service_session, #sso_cookie_content, #sso_logging_info, #validate_inbound_login_params, #validate_session
#authenticate, #validate_audience!
Instance Method Details
#accept ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
|
# File 'app/controllers/v0/terms_of_use_agreements_controller.rb', line 18
def accept
terms_of_use_agreement = acceptor.perform!
unless terms_code_temporary_auth?
recache_user
current_user.create_mhv_account_async unless skip_mhv_account_creation?
end
render_success(action: 'accept', body: { terms_of_use_agreement: }, status: :created)
rescue TermsOfUse::Errors::AcceptorError => e
render_error(action: 'accept', message: e.message)
end
|
#accept_and_provision ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'app/controllers/v0/terms_of_use_agreements_controller.rb', line 30
def accept_and_provision
terms_of_use_agreement = acceptor(sync: true).perform!
if terms_of_use_agreement.accepted?
provisioner.perform
create_cerner_cookie
unless terms_code_temporary_auth?
recache_user
current_user.create_mhv_account_async unless skip_mhv_account_creation?
end
render_success(action: 'accept_and_provision', body: { terms_of_use_agreement:, provisioned: true },
status: :created)
else
render_error(action: 'accept_and_provision', message: 'Failed to accept and provision')
end
rescue TermsOfUse::Errors::AcceptorError, TermsOfUse::Errors::ProvisionerError => e
render_error(action: 'accept_and_provision', message: e.message)
end
|
#acceptor(sync: false) ⇒ Object
69
70
71
|
# File 'app/controllers/v0/terms_of_use_agreements_controller.rb', line 69
def acceptor(sync: false)
TermsOfUse::Acceptor.new(user_account: @user_account, version: params[:version], sync:)
end
|
#authenticate_current_user ⇒ Object
108
109
110
111
112
113
|
# File 'app/controllers/v0/terms_of_use_agreements_controller.rb', line 108
def authenticate_current_user
load_user(skip_terms_check: true)
return unless current_user
@user_account = current_user.user_account
end
|
#authenticate_one_time_terms_code ⇒ Object
99
100
101
102
103
104
105
106
|
# File 'app/controllers/v0/terms_of_use_agreements_controller.rb', line 99
def authenticate_one_time_terms_code
terms_code_container = SignIn::TermsCodeContainer.find(params[:terms_code])
return unless terms_code_container
@user_account = UserAccount.find(terms_code_container.user_account_uuid)
ensure
terms_code_container&.destroy
end
|
#create_cerner_cookie ⇒ Object
#decline ⇒ Object
51
52
53
54
55
56
57
|
# File 'app/controllers/v0/terms_of_use_agreements_controller.rb', line 51
def decline
terms_of_use_agreement = decliner.perform!
recache_user unless terms_code_temporary_auth?
render_success(action: 'decline', body: { terms_of_use_agreement: }, status: :created)
rescue TermsOfUse::Errors::DeclinerError => e
render_error(action: 'decline', message: e.message)
end
|
#decliner ⇒ Object
73
74
75
|
# File 'app/controllers/v0/terms_of_use_agreements_controller.rb', line 73
def decliner
TermsOfUse::Decliner.new(user_account: @user_account, version: params[:version])
end
|
#find_latest_agreement_by_version(version) ⇒ Object
95
96
97
|
# File 'app/controllers/v0/terms_of_use_agreements_controller.rb', line 95
def find_latest_agreement_by_version(version)
@user_account.terms_of_use_agreements.where(agreement_version: version).last
end
|
#latest ⇒ Object
13
14
15
16
|
# File 'app/controllers/v0/terms_of_use_agreements_controller.rb', line 13
def latest
terms_of_use_agreement = find_latest_agreement_by_version(params[:version])
render_success(action: 'latest', body: { terms_of_use_agreement: })
end
|
#mpi_profile ⇒ Object
125
126
127
128
|
# File 'app/controllers/v0/terms_of_use_agreements_controller.rb', line 125
def mpi_profile
@mpi_profile ||= MPI::Service.new.find_profile_by_identifier(identifier: @user_account.icn,
identifier_type: MPI::Constants::ICN)&.profile
end
|
#provisioner ⇒ Object
77
78
79
|
# File 'app/controllers/v0/terms_of_use_agreements_controller.rb', line 77
def provisioner
TermsOfUse::Provisioner.new(icn: @user_account.icn)
end
|
#recache_user ⇒ Object
81
82
83
84
|
# File 'app/controllers/v0/terms_of_use_agreements_controller.rb', line 81
def recache_user
current_user.needs_accepted_terms_of_use = current_user.user_account&.needs_accepted_terms_of_use?
current_user.save
end
|
#render_error(action:, message:, status: :unprocessable_entity) ⇒ Object
139
140
141
142
|
# File 'app/controllers/v0/terms_of_use_agreements_controller.rb', line 139
def render_error(action:, message:, status: :unprocessable_entity)
Rails.logger.error("[TermsOfUseAgreementsController] #{action} error: #{message}", { icn: @user_account.icn })
render json: { error: message }, status:
end
|
#render_success(action:, body:, status: :ok, icn: @user_account.icn) ⇒ Object
134
135
136
137
|
# File 'app/controllers/v0/terms_of_use_agreements_controller.rb', line 134
def render_success(action:, body:, status: :ok, icn: @user_account.icn)
Rails.logger.info("[TermsOfUseAgreementsController] #{action} success", { icn: })
render json: body, status:
end
|
#skip_mhv_account_creation? ⇒ Boolean
130
131
132
|
# File 'app/controllers/v0/terms_of_use_agreements_controller.rb', line 130
def skip_mhv_account_creation?
ActiveModel::Type::Boolean.new.cast(params[:skip_mhv_account_creation])
end
|
#terms_authenticate ⇒ Object
119
120
121
122
123
|
# File 'app/controllers/v0/terms_of_use_agreements_controller.rb', line 119
def terms_authenticate
terms_code_temporary_auth? ? authenticate_one_time_terms_code : authenticate_current_user
raise Common::Exceptions::Unauthorized unless @user_account
end
|
#terms_code_temporary_auth? ⇒ Boolean
115
116
117
|
# File 'app/controllers/v0/terms_of_use_agreements_controller.rb', line 115
def terms_code_temporary_auth?
params[:terms_code].present?
end
|
#update_provisioning ⇒ Object
59
60
61
62
63
64
65
|
# File 'app/controllers/v0/terms_of_use_agreements_controller.rb', line 59
def update_provisioning
provisioner.perform
create_cerner_cookie
render_success(action: 'update_provisioning', body: { provisioned: true }, status: :ok)
rescue TermsOfUse::Errors::ProvisionerError => e
render_error(action: 'update_provisioning', message: e.message)
end
|