Class: V0::LettersGeneratorController
- Inherits:
-
ApplicationController
- Object
- ActionController::API
- ApplicationController
- V0::LettersGeneratorController
- Defined in:
- app/controllers/v0/letters_generator_controller.rb
Constant Summary collapse
- DOWNLOAD_PARAMS =
%i[ id format military_service service_connected_disabilities service_connected_evaluation non_service_connected_pension monthly_award unemployable special_monthly_compensation adapted_housing chapter35_eligibility death_result_of_disability survivors_award letters_generator ].freeze
Constants inherited from ApplicationController
ApplicationController::VERSION_STATUS
Constants included from SignIn::Authentication
SignIn::Authentication::BEARER_PATTERN
Constants included from ExceptionHandling
ExceptionHandling::SKIP_SENTRY_EXCEPTION_TYPES
Instance Attribute Summary
Attributes inherited from ApplicationController
Instance Method Summary collapse
- #beneficiary ⇒ Object
- #dependent? ⇒ Boolean private
- #dependent_letter? ⇒ Boolean private
- #download ⇒ Object
- #download_params ⇒ Object private
- #index ⇒ Object
- #letter_options ⇒ Object private
- #service ⇒ Object private
- #sponsor_icn ⇒ Object private
-
#validate_dependent_sponsor ⇒ Object
private
This is an exceptional case.
- #validate_letter_type ⇒ Object private
Methods inherited from ApplicationController
#clear_saved_form, #cors_preflight, #pagination_params, #render_job_id, #routing_error, #set_csrf_header
Methods included from Traceable
Methods included from SentryControllerLogging
#set_tags_and_extra_context, #tags_context, #user_context
Methods included from SentryLogging
#log_exception_to_sentry, #log_message_to_sentry, #non_nil_hash?, #normalize_level, #rails_logger, #set_sentry_metadata
Methods included from Instrumentation
Methods included from SignIn::Authentication
#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
Methods included from ExceptionHandling
#render_errors, #report_mapped_exception, #report_original_exception, #skip_sentry_exception?, #skip_sentry_exception_types
Methods included from AuthenticationAndSSOConcerns
#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
Methods included from SignIn::AudienceValidator
#authenticate, #validate_audience!
Instance Method Details
#beneficiary ⇒ Object
45 46 47 48 |
# File 'app/controllers/v0/letters_generator_controller.rb', line 45 def beneficiary response = service.get_benefit_information(@current_user.icn) render json: response end |
#dependent? ⇒ Boolean (private)
93 94 95 |
# File 'app/controllers/v0/letters_generator_controller.rb', line 93 def dependent? Lighthouse::LettersGenerator::VeteranSponsorResolver.dependent?(@current_user) end |
#dependent_letter? ⇒ Boolean (private)
56 57 58 59 |
# File 'app/controllers/v0/letters_generator_controller.rb', line 56 def dependent_letter? letter_type = download_params['id'] letter_type.downcase == 'benefit_summary_dependent' end |
#download ⇒ Object
37 38 39 40 41 42 43 |
# File 'app/controllers/v0/letters_generator_controller.rb', line 37 def download icns = { icn: @current_user.icn } icns[:sponsor_icn] = sponsor_icn if dependent_letter? response = service.download_letter(icns, params[:id], ) send_data response, filename: "#{params[:id]}.pdf", type: 'application/pdf', disposition: 'attachment' end |
#download_params ⇒ Object (private)
52 53 54 |
# File 'app/controllers/v0/letters_generator_controller.rb', line 52 def download_params params.permit(DOWNLOAD_PARAMS) end |
#index ⇒ Object
32 33 34 35 |
# File 'app/controllers/v0/letters_generator_controller.rb', line 32 def index response = service.get_eligible_letter_types(@current_user.icn) render json: response end |
#letter_options ⇒ Object (private)
82 83 84 85 86 87 |
# File 'app/controllers/v0/letters_generator_controller.rb', line 82 def download_params.to_h .except('id') .transform_values { |v| ActiveModel::Type::Boolean.new.cast(v) } .transform_keys { |k| k.camelize(:lower) } end |
#service ⇒ Object (private)
78 79 80 |
# File 'app/controllers/v0/letters_generator_controller.rb', line 78 def service @service ||= Lighthouse::LettersGenerator::Service.new end |
#sponsor_icn ⇒ Object (private)
89 90 91 |
# File 'app/controllers/v0/letters_generator_controller.rb', line 89 def sponsor_icn Lighthouse::LettersGenerator::VeteranSponsorResolver.get_sponsor_icn(@current_user) end |
#validate_dependent_sponsor ⇒ Object (private)
This is an exceptional case. A Veteran who is not a dependent should not be able to access this endpoint. A dependent (Veteran or not) must have a Veteran sponsor.
71 72 73 74 75 76 |
# File 'app/controllers/v0/letters_generator_controller.rb', line 71 def validate_dependent_sponsor if dependent_letter? && sponsor_icn.nil? detail = "User #{@current_user.uuid} is #{dependent? ? 'not' : ''} a Veteran and has no associated sponsor." raise Common::Exceptions::BadRequest.new({ detail:, source: self.class.name }) end end |
#validate_letter_type ⇒ Object (private)
61 62 63 64 65 66 |
# File 'app/controllers/v0/letters_generator_controller.rb', line 61 def validate_letter_type unless service.valid_type?(params[:id]) detail = "Letter type of #{params[:id]} is not one of the expected options" raise Common::Exceptions::BadRequest.new({ detail:, source: self.class.name }) end end |