Class: V0::ClaimDocumentsController
- Inherits:
-
ApplicationController
- Object
- ActionController::API
- ApplicationController
- V0::ClaimDocumentsController
- Defined in:
- app/controllers/v0/claim_documents_controller.rb
Constant Summary
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
- #create ⇒ Object
- #form_id ⇒ Object private
- #klass ⇒ Object private
- #unlock_file(file, file_password) ⇒ 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
#create ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/controllers/v0/claim_documents_controller.rb', line 11 def create Rails.logger.info "Creating PersistentAttachment FormID=#{form_id}" = klass.new(form_id:) # add the file after so that we have a form_id and guid for the uploader to use .file = unlock_file(params['file'], params['password']) raise Common::Exceptions::ValidationErrors, unless .valid? .save Rails.logger.info "Success creating PersistentAttachment FormID=#{form_id} AttachmentID=#{.id}" render json: PersistentAttachmentSerializer.new() rescue => e Rails.logger.error "Error creating PersistentAttachment FormID=#{form_id} AttachmentID=#{.id} #{e}" raise e end |
#form_id ⇒ Object (private)
45 46 47 |
# File 'app/controllers/v0/claim_documents_controller.rb', line 45 def form_id params[:form_id].upcase end |
#klass ⇒ Object (private)
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/controllers/v0/claim_documents_controller.rb', line 32 def klass case form_id when '21P-527EZ', '21P-530', '21P-530V2' PensionBurial::TagSentry.tag_sentry PersistentAttachments::PensionBurial when '21-686C', '686C-674' PersistentAttachments::DependencyClaim when '26-1880' LGY::TagSentry.tag_sentry PersistentAttachments::LgyClaim end end |
#unlock_file(file, file_password) ⇒ Object (private)
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'app/controllers/v0/claim_documents_controller.rb', line 49 def unlock_file(file, file_password) return file unless File.extname(file) == '.pdf' && file_password pdftk = PdfForms.new(Settings.binaries.pdftk) tmpf = Tempfile.new(['decrypted_form_attachment', '.pdf']) begin pdftk.call_pdftk(file.tempfile.path, 'input_pw', file_password, 'output', tmpf.path) rescue PdfForms::PdftkError => e file_regex = %r{/(?:\w+/)*[\w-]+\.pdf\b} password_regex = /(input_pw).*?(output)/ = e..gsub(file_regex, '[FILTERED FILENAME]').gsub(password_regex, '\1 [FILTERED] \2') (, 'warn') raise Common::Exceptions::UnprocessableEntity.new( detail: I18n.t('errors.messages.uploads.pdf.incorrect_password'), source: 'PersistentAttachment.unlock_file' ) end file.tempfile.unlink file.tempfile = tmpf file end |