Skip to content

Commit

Permalink
Merge branch 'master' into sjc-vets-model-value-coercion
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenjcumming committed Dec 20, 2024
2 parents c611211 + 2913119 commit 4979538
Show file tree
Hide file tree
Showing 383 changed files with 41,142 additions and 25,305 deletions.
27 changes: 17 additions & 10 deletions .github/CODEOWNERS

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .github/workflows/build_atlas_codeowners.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ jobs:
destination_repo: 'department-of-veterans-affairs/platform-atlas'
destination_folder: '/lib/codeowners/vets-api'
destination_branch: 'master'
user_email: '[email protected]'
user_email: '[email protected]'
user_name: 'va-vsp-bot'
commit_message: 'Auto update Atlas with Vets-API CODEOWNERS'
2 changes: 1 addition & 1 deletion .github/workflows/deploy-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,5 @@ jobs:
add: "*"
cwd: vsp-infra-application-manifests/apps
author_name: va-vsp-bot
author_email: [email protected]
author_email: [email protected]
message: "Release ${{ needs.prepare-values.outputs.environments }} for ${{inputs.ecr_repository}} : ${{ inputs.commit_sha }}."
1 change: 1 addition & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ Lint/MissingSuper:
- 'modules/va_notify/lib/va_notify/service.rb'
- 'modules/vaos/app/services/vaos/session_service.rb'
- 'modules/veteran/app/models/veteran/user.rb'
- 'lib/vye/dgib/service.rb'

# Offense count: 5
Lint/NoReturnInBeginEndBlocks:
Expand Down
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ gem 'aws-sdk-s3', '~> 1'
gem 'aws-sdk-sns', '~> 1'
gem 'betamocks', git: 'https://github.com/department-of-veterans-affairs/betamocks', branch: 'master'
gem 'bgs_ext', git: 'https://github.com/department-of-veterans-affairs/bgs-ext.git', require: 'bgs', ref: '350e45ae69'
gem 'blind_index'
gem 'blueprinter'
gem 'bootsnap', require: false
gem 'breakers'
Expand Down Expand Up @@ -206,6 +207,7 @@ group :development, :test do
gem 'byebug', platforms: :ruby # Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'danger'
gem 'database_cleaner'
gem 'debug'
gem 'factory_bot_rails'
gem 'faker'
# CAUTION: faraday_curl may not provide all headers used in the actual faraday request. Be cautious if using this to
Expand Down
52 changes: 30 additions & 22 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ PATH
remote: modules
specs:
accredited_representative_portal (0.1.0)
blind_index
appeals_api (0.0.1)
jsonapi-serializer (>= 2.2.0)
sidekiq
Expand Down Expand Up @@ -240,11 +241,12 @@ GEM
base64
gyoku (>= 0.4.0)
nokogiri
argon2-kdf (0.2.0)
ast (2.4.2)
attr_extras (7.1.0)
awesome_print (1.9.2)
aws-eventstream (1.3.0)
aws-partitions (1.1019.0)
aws-partitions (1.1022.0)
aws-sdk-core (3.214.0)
aws-eventstream (~> 1, >= 1.3.0)
aws-partitions (~> 1, >= 1.992.0)
Expand All @@ -253,7 +255,7 @@ GEM
aws-sdk-kms (1.96.0)
aws-sdk-core (~> 3, >= 3.210.0)
aws-sigv4 (~> 1.5)
aws-sdk-s3 (1.173.0)
aws-sdk-s3 (1.176.1)
aws-sdk-core (~> 3, >= 3.210.0)
aws-sdk-kms (~> 1)
aws-sigv4 (~> 1.5)
Expand All @@ -273,6 +275,9 @@ GEM
bigdecimal (3.1.8)
bigdecimal (3.1.8-java)
bindex (0.8.1)
blind_index (2.6.1)
activesupport (>= 7)
argon2-kdf (>= 0.2)
blueprinter (1.1.2)
bootsnap (1.18.4)
msgpack (~> 1.2)
Expand Down Expand Up @@ -308,7 +313,7 @@ GEM
coercible (1.0.0)
descendants_tracker (~> 0.0.1)
colored2 (3.1.2)
combine_pdf (1.0.26)
combine_pdf (1.0.29)
matrix
ruby-rc4 (>= 0.1.5)
committee (5.4.0)
Expand Down Expand Up @@ -370,6 +375,9 @@ GEM
libddwaf (~> 1.14.0.0.0)
msgpack
debase-ruby_core_source (3.3.1)
debug (1.9.2)
irb (~> 1.10)
reline (>= 0.3.8)
declarative (0.0.20)
deep_merge (1.2.2)
descendants_tracker (0.0.4)
Expand Down Expand Up @@ -596,11 +604,11 @@ GEM
ruby-vips (>= 2.0.17, < 3)
io-console (0.8.0)
io-console (0.8.0-java)
irb (1.14.1)
irb (1.14.2)
rdoc (>= 4.0.0)
reline (>= 0.4.2)
iso_country_codes (0.7.8)
jar-dependencies (0.5.0)
jar-dependencies (0.5.1)
jmespath (1.6.2)
jruby-openssl (0.15.1-java)
json (2.9.0)
Expand Down Expand Up @@ -645,7 +653,7 @@ GEM
ffi-compiler (~> 1.0)
rake (~> 13.0)
lockbox (2.0.0)
logger (1.6.2)
logger (1.6.3)
loofah (2.23.1)
crass (~> 1.0.2)
nokogiri (>= 1.12.0)
Expand Down Expand Up @@ -697,11 +705,9 @@ GEM
nio4r (2.7.4-java)
nkf (0.2.0)
nkf (0.2.0-java)
nokogiri (1.16.8)
nokogiri (1.17.2)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
nokogiri (1.16.8-java)
racc (~> 1.4)
nori (2.7.1)
bigdecimal
notiffany (0.1.3)
Expand Down Expand Up @@ -758,8 +764,8 @@ GEM
ruby-rc4
ttfunk
pg (1.5.9)
pg_query (5.1.0)
google-protobuf (>= 3.22.3)
pg_query (6.0.0)
google-protobuf (>= 3.25.3)
pg_search (2.3.7)
activerecord (>= 6.1)
activesupport (>= 6.1)
Expand All @@ -785,10 +791,10 @@ GEM
byebug (~> 11.0)
pry (>= 0.13, < 0.15)
pstore (0.1.3)
psych (5.2.1)
psych (5.2.2)
date
stringio
psych (5.2.1-java)
psych (5.2.2-java)
date
jar-dependencies (>= 0.1.7)
public_suffix (6.0.1)
Expand Down Expand Up @@ -837,7 +843,7 @@ GEM
activesupport (>= 5.0.0)
minitest
nokogiri (>= 1.6)
rails-html-sanitizer (1.6.1)
rails-html-sanitizer (1.6.2)
loofah (~> 2.21)
nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0)
rails-session_cookie (0.3.0)
Expand All @@ -860,7 +866,7 @@ GEM
rb-inotify (0.10.1)
ffi (~> 1.0)
rchardet (1.8.0)
rdoc (6.8.1)
rdoc (6.9.1)
psych (>= 4.0.0)
redis (5.3.0)
redis-client (>= 0.22.0)
Expand All @@ -869,7 +875,7 @@ GEM
redis-namespace (1.11.0)
redis (>= 4)
regexp_parser (2.9.3)
reline (0.5.12)
reline (0.6.0)
io-console (~> 0.5)
representable (3.2.0)
declarative (< 0.1.0)
Expand Down Expand Up @@ -915,7 +921,7 @@ GEM
rspec-mocks (3.13.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-rails (7.0.1)
rspec-rails (7.1.0)
actionpack (>= 7.0)
activesupport (>= 7.0)
railties (>= 7.0)
Expand All @@ -930,7 +936,7 @@ GEM
rspec-expectations (~> 3.0)
rspec-mocks (~> 3.0)
sidekiq (>= 5, < 8)
rspec-support (3.13.1)
rspec-support (3.13.2)
rspec_junit_formatter (0.6.0)
rspec-core (>= 2, < 4, != 2.12.0)
rswag-specs (2.16.0)
Expand All @@ -942,7 +948,7 @@ GEM
actionpack (>= 5.2, < 8.1)
railties (>= 5.2, < 8.1)
rtesseract (3.1.3)
rubocop (1.69.1)
rubocop (1.69.2)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
Expand All @@ -952,7 +958,7 @@ GEM
rubocop-ast (>= 1.36.2, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 4.0)
rubocop-ast (1.36.2)
rubocop-ast (1.37.0)
parser (>= 3.3.1.0)
rubocop-capybara (2.21.0)
rubocop (~> 1.41)
Expand All @@ -964,7 +970,7 @@ GEM
rack (>= 1.1)
rubocop (>= 1.52.0, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
rubocop-rspec (3.2.0)
rubocop-rspec (3.3.0)
rubocop (~> 1.61)
rubocop-rspec_rails (2.30.0)
rubocop (~> 1.61)
Expand Down Expand Up @@ -998,7 +1004,7 @@ GEM
addressable (>= 2.3.5)
faraday (>= 0.17.3, < 3)
script_utils (0.0.4)
securerandom (0.4.0)
securerandom (0.4.1)
seedbank (0.5.0)
rake (>= 10.0)
semantic_logger (4.16.0)
Expand Down Expand Up @@ -1150,6 +1156,7 @@ DEPENDENCIES
banners!
betamocks!
bgs_ext!
blind_index
blueprinter
bootsnap
brakeman
Expand All @@ -1175,6 +1182,7 @@ DEPENDENCIES
date_validator
ddtrace
debts_api!
debug
decision_reviews!
dhp_connected_devices!
dogstatsd-ruby (= 5.6.3)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/concerns/exception_handling.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def report_mapped_exception(exception, va_exception)
# Add additional user specific context to the logs
if exception.is_a?(Common::Exceptions::BackendServiceException) && current_user.present?
extra[:icn] = current_user.icn
extra[:mhv_correlation_id] = current_user.mhv_correlation_id
extra[:mhv_credential_uuid] = current_user.mhv_credential_uuid
end
va_exception_info = { va_exception_errors: va_exception.errors.map(&:to_hash) }
log_exception_to_sentry(exception, extra.merge(va_exception_info))
Expand Down
11 changes: 1 addition & 10 deletions app/controllers/v0/burial_claims_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def show
def create
PensionBurial::TagSentry.tag_sentry

claim = create_claim
claim = claim_class.new(form: filtered_params[:form])
monitor.track_create_attempt(claim, current_user)

in_progress_form = current_user ? InProgressForm.form_for_user(claim.form_id, current_user) : nil
Expand Down Expand Up @@ -61,15 +61,6 @@ def claim_class
SavedClaim::Burial
end

def create_claim
if Flipper.enabled?(:va_burial_v2)
form = filtered_params[:form]
claim_class.new(form:, formV2: form.present? ? JSON.parse(form)['formV2'] : nil)
else
claim_class.new(form: filtered_params[:form])
end
end

def process_and_upload_to_lighthouse(in_progress_form, claim)
claim.process_attachments!

Expand Down
66 changes: 56 additions & 10 deletions app/controllers/v0/claim_documents_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,46 @@

require 'pension_burial/tag_sentry'
require 'lgy/tag_sentry'
require 'claim_documents/monitor'
require 'lighthouse/benefits_intake/service'
require 'pdf_utilities/datestamp_pdf'

module V0
class ClaimDocumentsController < ApplicationController
service_tag 'claims-shared'
skip_before_action(:authenticate)
before_action :load_user

def create
Rails.logger.info "Creating PersistentAttachment FormID=#{form_id}"
uploads_monitor.track_document_upload_attempt(form_id, current_user)

attachment = klass.new(form_id:)
@attachment = klass&.new(form_id:)
# add the file after so that we have a form_id and guid for the uploader to use
attachment.file = unlock_file(params['file'], params['password'])
@attachment.file = unlock_file(params['file'], params['password'])

raise Common::Exceptions::ValidationErrors, attachment unless attachment.valid?
if %w[21P-527EZ 21P-530 21P-530V2].include?(form_id) &&
Flipper.enabled?(:document_upload_validation_enabled) && !stamped_pdf_valid?

attachment.save
raise Common::Exceptions::ValidationErrors, @attachment
end

raise Common::Exceptions::ValidationErrors, @attachment unless @attachment.valid?

Rails.logger.info "Success creating PersistentAttachment FormID=#{form_id} AttachmentID=#{attachment.id}"
@attachment.save

render json: PersistentAttachmentSerializer.new(attachment)
uploads_monitor.track_document_upload_success(form_id, @attachment.id, current_user)

render json: PersistentAttachmentSerializer.new(@attachment)
rescue => e
Rails.logger.error "Error creating PersistentAttachment FormID=#{form_id} AttachmentID=#{attachment.id} #{e}"
uploads_monitor.track_document_upload_failed(form_id, @attachment&.id, current_user, e)
raise e
end

private

def klass
case form_id
when '21P-527EZ', '21P-530', '21P-530V2'
when '21P-527EZ', '21P-530EZ', '21P-530V2'
PensionBurial::TagSentry.tag_sentry
PersistentAttachments::PensionBurial
when '21-686C', '686C-674'
Expand All @@ -47,7 +57,7 @@ def form_id
end

def unlock_file(file, file_password)
return file unless File.extname(file) == '.pdf' && file_password
return file unless File.extname(file) == '.pdf' && file_password.present?

pdftk = PdfForms.new(Settings.binaries.pdftk)
tmpf = Tempfile.new(['decrypted_form_attachment', '.pdf'])
Expand All @@ -69,5 +79,41 @@ def unlock_file(file, file_password)
file.tempfile = tmpf
file
end

# rubocop:disable Metrics/MethodLength
def stamped_pdf_valid?
extension = File.extname(@attachment&.file&.id)
allowed_types = PersistentAttachment::ALLOWED_DOCUMENT_TYPES

if allowed_types.exclude?(extension)
raise Common::Exceptions::UnprocessableEntity.new(
detail: I18n.t('errors.messages.extension_allowlist_error', extension:, allowed_types:),
source: 'PersistentAttachment.stamped_pdf_valid?'
)
elsif @attachment&.file&.size&.< PersistentAttachment::MINIMUM_FILE_SIZE
raise Common::Exceptions::UnprocessableEntity.new(
detail: 'File size must not be less than 1.0 KB',
source: 'PersistentAttachment.stamped_pdf_valid?'
)
end

document = PDFUtilities::DatestampPdf.new(@attachment.to_pdf).run(text: 'VA.GOV', x: 5, y: 5)
intake_service.valid_document?(document:)
rescue BenefitsIntake::Service::InvalidDocumentError => e
@attachment.errors.add(:attachment, e.message)
false
rescue PdfForms::PdftkError
@attachment.errors.add(:attachment, 'File is corrupt and cannot be uploaded')
false
end
# rubocop:enable Metrics/MethodLength

def intake_service
@intake_service ||= BenefitsIntake::Service.new
end

def uploads_monitor
@uploads_monitor ||= ClaimDocuments::Monitor.new
end
end
end
Loading

0 comments on commit 4979538

Please sign in to comment.