Class: V1::DecisionReviewEvidencesController
- Inherits:
-
ApplicationController
- Object
- ActionController::API
- ApplicationController
- V1::DecisionReviewEvidencesController
- Defined in:
- app/controllers/v1/decision_review_evidences_controller.rb
Constant Summary collapse
- FORM_ATTACHMENT_MODEL =
DecisionReviewEvidenceAttachment
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
- #common_log_params ⇒ Object private
- #get_form_id_from_request_headers ⇒ Object private
-
#save_attachment_to_cloud! ⇒ Object
private
This method, declared in ‘FormAttachmentCreate`, is responsible for uploading file data to S3.
- #serializer_klass ⇒ Object private
- #unlock_pdf(file, password) ⇒ Object private
Methods included from DecisionReviewV1::Appeals::LoggingUtils
#benchmark?, #benchmark_to_log_data_hash, #extract_uuid_from_central_mail_message, #log_formatted, #parse_form412_response_to_log_msg, #parse_lighthouse_response_to_log_msg, #run_and_benchmark_if_enabled
Methods included from FormAttachmentCreate
#create, #extract_params_from_namespace, #filtered_params, #form_attachment, #form_attachment_model, #save_attachment_to_db!, #validate_file_upload_class!
Methods included from SentryLogging
#log_exception_to_sentry, #log_message_to_sentry, #non_nil_hash?, #normalize_level, #rails_logger, #set_sentry_metadata
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 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
#common_log_params ⇒ Object (private)
46 47 48 49 50 51 52 53 |
# File 'app/controllers/v1/decision_review_evidences_controller.rb', line 46 def common_log_params { key: :evidence_upload_to_s3, form_id: get_form_id_from_request_headers, user_uuid: current_user.uuid, downstream_system: 'AWS S3' } end |
#get_form_id_from_request_headers ⇒ Object (private)
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'app/controllers/v1/decision_review_evidences_controller.rb', line 65 def get_form_id_from_request_headers # 'Source-App-Name', which specifies the form from which evidence was submitted, is taken from `window.appName`, # which is taken from the `entryName` in the manifest.json files for each form. See: # - vets-website/src/platform/utilities/api/index.js (apiRequest) # - vets-website/src/platform/startup/setup.js (setUpCommonFunctionality) # - vets-website/src/platform/startup/index.js (startApp) # - vets-api/lib/source_app_middleware.rb source_app_name = request.env['SOURCE_APP'] # The higher-level review form (996) is not included in this list because it does not permit evidence uploads. form_id = { '10182-board-appeal' => '10182', '995-supplemental-claim' => '995' }[source_app_name] if form_id.present? form_id else # If, for some odd reason, the `entryName`s are changed in these manifest.json files (or if the HLR form begins # accepting additional evidence), we will trigger a DataDog alert hinging on the StatsD metric below. Upon # receiving this alert, we can update the form_id hash above. StatsD.increment('decision_review.evidence_upload_to_s3.unexpected_form_id') # In this situation, there is no good reason to block the Veteran from uploading their evidence to S3, # so we return the unexpected `source_app_name` to be logged by `log_formatted` above. source_app_name end end |
#save_attachment_to_cloud! ⇒ Object (private)
This method, declared in ‘FormAttachmentCreate`, is responsible for uploading file data to S3.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'app/controllers/v1/decision_review_evidences_controller.rb', line 22 def # `form_attachment` is declared in `FormAttachmentCreate`, included above. = &.guid password = filtered_params[:password] log_params = { form_attachment_guid:, encrypted: password.present? } # Unlock pdf with hexapdf instead of using pdftk if password.present? unlocked_pdf = unlock_pdf(filtered_params[:file_data], password) .set_file_data!(unlocked_pdf) else super end log_formatted(**common_log_params.merge(params: log_params, is_success: true)) rescue => e log_formatted(**common_log_params.merge(params: log_params, is_success: false, response_error: e)) raise e end |
#serializer_klass ⇒ Object (private)
17 18 19 |
# File 'app/controllers/v1/decision_review_evidences_controller.rb', line 17 def serializer_klass DecisionReviewEvidenceAttachmentSerializer end |
#unlock_pdf(file, password) ⇒ Object (private)
55 56 57 58 59 60 61 62 63 |
# File 'app/controllers/v1/decision_review_evidences_controller.rb', line 55 def unlock_pdf(file, password) tmpf = Tempfile.new(['decrypted_form_attachment', '.pdf']) ::Common::PdfHelpers.unlock_pdf(file.tempfile.path, password, tmpf) tmpf.rewind file.tempfile.unlink file.tempfile = tmpf file end |