Skip to content

Commit

Permalink
Merge branch 'master' into 72706-create-ivcchampva-module
Browse files Browse the repository at this point in the history
  • Loading branch information
balexandr committed Mar 26, 2024
2 parents 2494184 + 137d71f commit 841c74e
Show file tree
Hide file tree
Showing 96 changed files with 5,186 additions and 280 deletions.
64 changes: 64 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
"name": "vets-api native setup",
"image": "mcr.microsoft.com/devcontainers/base:bullseye",

"features": {
"ghcr.io/devcontainers-contrib/features/ruby-asdf:0": {
"version": "3.2.3"
},
"ghcr.io/robbert229/devcontainer-features/postgresql-client:1": {
"version": "15"
},
"ghcr.io/devcontainers-contrib/features/redis-homebrew:1": {
"version": "6.2"
}
},

"forwardPorts": [
3000,
9293,
5432,
6379
],
"portsAttributes": {
"3000": {
"label": "vets-api",
"onAutoForward": "notify",
"requireLocalPort": true
},
"9293": {
"label": "vets-api-healthcheck",
"onAutoForward": "silent",
"requireLocalPort": true
},
"5432": {
"label": "postgis",
"onAutoForward": "silent",
"requireLocalPort": true
},
"6379": {
"label": "redis",
"onAutoForward": "silent",
"requireLocalPort": true
}
},

"postCreateCommand": "sh .devcontainer/post-create.sh",
"postStartCommand": "sh .devcontainer/post-start.sh",

"customizations": {
"codespaces": {
"repositories": {
"department-of-veterans-affairs/vets-api-mockdata": {
"permissions": {
"contents": "read",
"pull_requests": "write"
}
}
}
},
"vscode": {
"extensions": ["ms-azuretools.vscode-docker", "Shopify.ruby-lsp"]
}
}
}
51 changes: 51 additions & 0 deletions .devcontainer/post-create.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/sh

# Add welcome message
sudo cp .devcontainer/welcome.txt /usr/local/etc/vscode-dev-containers/first-run-notice.txt

# Switch to vets-api ruby version
export PATH="${HOME}/.asdf/shims:${HOME}/.asdf/bin:${PATH}"
asdf install ruby $( cat .ruby-version )
asdf global ruby $( cat .ruby-version )

git clone https://github.com/department-of-veterans-affairs/vets-api-mockdata.git ../vets-api-mockdata

sudo apt update
sudo apt install -y libpq-dev pdftk shared-mime-info postgresql-15-postgis-3

gem install bundler
NUM_CORES=$( cat /proc/cpuinfo | grep '^processor'|wc -l )
bundle config --global jobs `expr $NUM_CORES - 1`

# Update test DB config
echo 'test_database_url: postgis://postgres:password@localhost:5432/vets_api_test?pool=4' > config/settings/test.local.yml

# Add service config
if [ ! -f config/settings.local.yml ]; then
cp config/settings.local.yml.example config/settings.local.yml
cat <<EOT >> config/settings.local.yml
database_url: postgis://postgres:password@localhost:5432/vets_api_development?pool=4
test_database_url: postgis://postgres:password@localhost:5432/vets_api_test?pool=4
redis:
host: localhost
port: 6379
app_data:
url: redis://localhost:6379
sidekiq:
url: redis://localhost:6379
betamocks:
cache_dir: ../vets-api-mockdata
# Allow access from localhost and shared github URLs.
virtual_hosts: ["127.0.0.1", "localhost", !ruby/regexp /.*\.app\.github\.dev/]
EOT
fi

mkdir -p log
nohup bash -c '/home/linuxbrew/.linuxbrew/opt/[email protected]/bin/redis-server /home/linuxbrew/.linuxbrew/etc/redis.conf' >> log/redis.log 2>&1 &
sudo /etc/init.d/postgresql restart
pg_isready -t 60
sudo -u root sudo -u postgres psql -c "ALTER USER postgres PASSWORD 'password';"
./bin/setup
9 changes: 9 additions & 0 deletions .devcontainer/post-start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh

echo "Starting redis..."
nohup /home/linuxbrew/.linuxbrew/opt/[email protected]/bin/redis-server /home/linuxbrew/.linuxbrew/etc/redis.conf >> log/redis.log 2>&1 &

echo "Starting postgres..."
sudo /etc/init.d/postgresql restart
echo "Waiting for postgres to be ready..."
pg_isready -t 60
9 changes: 9 additions & 0 deletions .devcontainer/welcome.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
~~~~~~ Welcome to vets-api on codespaces! ~~~~~~

For more information, see the codespaces README in docs/setup.

~~~~~~ Quickstart ~~~~~

To start vets-api, run this command:

foreman start -m all=1,clamd=0,freshclam=0
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Gemfile @department-of-veterans-affairs/backend-review-group
Gemfile.lock @department-of-veterans-affairs/backend-review-group
Jenkinsfile @department-of-veterans-affairs/backend-review-group
Makefile @department-of-veterans-affairs/backend-review-group
.devcontainer @department-of-veterans-affairs/backend-review-group @department-of-veterans-affairs/cto-engineers
app/controllers/appeals_base_controller.rb @department-of-veterans-affairs/backend-review-group
app/controllers/appeals_base_controller_v1.rb @department-of-veterans-affairs/backend-review-group
app/controllers/application_controller.rb @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group
Expand Down Expand Up @@ -777,6 +778,7 @@ docs/setup/native.md @department-of-veterans-affairs/backend-review-group @depar
docs/setup/rswag_setup.md @department-of-veterans-affairs/backend-review-group @department-of-veterans-affairs/va-api-engineers
docs/setup/running_docker.md @department-of-veterans-affairs/backend-review-group @department-of-veterans-affairs/va-api-engineers
docs/setup/running_natively.md @department-of-veterans-affairs/backend-review-group @department-of-veterans-affairs/va-api-engineers
docs/setup/codespaces.md @department-of-veterans-affairs/backend-review-group @department-of-veterans-affairs/cto-engineers
docs/setup/va_forms.md @department-of-veterans-affairs/platform-va-product-forms @department-of-veterans-affairs/backend-review-group @department-of-veterans-affairs/va-api-engineers
docs/setup/virtual_machine_access.md @department-of-veterans-affairs/backend-review-group @department-of-veterans-affairs/va-api-engineers
.github @department-of-veterans-affairs/backend-review-group
Expand Down
6 changes: 3 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ GEM
factory_bot_rails (6.4.3)
factory_bot (~> 6.4)
railties (>= 5.0.0)
faker (3.2.3)
faker (3.3.0)
i18n (>= 1.8.11, < 2)
fakeredis (0.9.2)
redis (~> 4.8)
Expand Down Expand Up @@ -683,7 +683,7 @@ GEM
os (1.1.4)
ox (2.14.18)
parallel (1.24.0)
parallel_tests (4.5.2)
parallel_tests (4.6.0)
parallel
parser (3.3.0.5)
ast (~> 2.4.1)
Expand Down Expand Up @@ -802,7 +802,7 @@ GEM
rb-inotify (0.10.1)
ffi (~> 1.0)
rchardet (1.8.0)
rdoc (6.6.2)
rdoc (6.6.3.1)
psych (>= 4.0.0)
redis (4.8.1)
redis-namespace (1.11.0)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ For frontend, see [vets-website](https://github.com/department-of-veterans-affai
- [Native setup](docs/setup/native.md) (OSX/Ubuntu)
- [Docker setup](docs/setup/docker.md)
- [Hybrid setup](docs/setup/hybrid.md)
- [Codespaces setup](docs/setup/codespaces.md)
## Running the app
Expand Down
8 changes: 1 addition & 7 deletions app/controllers/concerns/headers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,7 @@
module Headers
extend ActiveSupport::Concern

included { prepend_before_action :block_unknown_hosts, :set_app_info_headers }

# returns a Bad Request if the incoming host header is unsafe.
def block_unknown_hosts
return if controller_name == 'example'
raise Common::Exceptions::NotASafeHostError, request.host unless Settings.virtual_hosts.include?(request.host)
end
included { prepend_before_action :set_app_info_headers }

def set_app_info_headers
headers['X-Git-SHA'] = AppInfo::GIT_REVISION
Expand Down
12 changes: 9 additions & 3 deletions app/controllers/v0/burial_claims_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,24 @@ class BurialClaimsController < ClaimsBaseController

def create
PensionBurial::TagSentry.tag_sentry
claim = claim_class.new(form: filtered_params[:form])

claim = if Flipper.enabled?(:va_burial_v2)
# cannot parse a nil form, to pass unit tests do a check for form presence
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

unless claim.save
StatsD.increment("#{stats_key}.failure")
Sentry.set_tags(team: 'benefits-memorial-1') # tag sentry logs with team name
raise Common::Exceptions::ValidationErrors, claim
end

# this method also calls claim.process_attachments!
claim.submit_to_structured_data_services!

Rails.logger.info "ClaimID=#{claim.confirmation_number} Form=#{claim.class::FORM}"
Rails.logger.info "ClaimID=#{claim.confirmation_number} Form=#{claim.form_id}"
clear_saved_form(claim.form_id)
render(json: claim)
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/v0/claim_documents_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def create

def klass
case form_id
when '21P-527EZ', '21P-530'
when '21P-527EZ', '21P-530', '21P-530V2'
PensionBurial::TagSentry.tag_sentry
PersistentAttachments::PensionBurial
when '21-686C', '686C-674'
Expand Down
4 changes: 3 additions & 1 deletion app/controllers/v0/pension_claims_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require 'pension_21p527ez/tag_sentry'

module V0
class PensionClaimsController < ClaimsBaseController
service_tag 'pension-application'
Expand Down Expand Up @@ -45,7 +47,7 @@ def show
# Creates and validates an instance of the class, removing any copies of
# the form that had been previously saved by the user.
def create
PensionBurial::TagSentry.tag_sentry
Pension21p527ez::TagSentry.tag_sentry

claim = claim_class.new(form: filtered_params[:form])
user_uuid = current_user&.uuid
Expand Down
3 changes: 2 additions & 1 deletion app/models/form_profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class FormProfile
22-5495 22-0993 22-0994 FEEDBACK-TOOL 22-10203 22-1990S 22-1990EZ],
evss: ['21-526EZ'],
hca: %w[1010ez 10-10EZR],
pension_burial: %w[21P-530 21P-527EZ],
pension_burial: %w[21P-530 21P-527EZ 21P-530V2],
dependents: ['686C-674'],
decision_review: %w[20-0995 20-0996 10182],
mdot: ['MDOT'],
Expand Down Expand Up @@ -121,6 +121,7 @@ class FormProfile
'22-5490E' => ::FormProfiles::VA5490e,
'22-5495' => ::FormProfiles::VA5495,
'21P-530' => ::FormProfiles::VA21p530,
'21P-530V2' => ::FormProfiles::VA21p530v2,
'21-686C' => ::FormProfiles::VA21686c,
'686C-674' => ::FormProfiles::VA686c674,
'40-10007' => ::FormProfiles::VA4010007,
Expand Down
33 changes: 33 additions & 0 deletions app/models/form_profiles/va_21p530v2.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# frozen_string_literal: true

require 'iso_country_codes'

class FormProfiles::VA21p530v2 < FormProfile
def metadata
{
version: 0,
prefill: true,
returnUrl: '/claimant-information'
}
end

def prefill
@identity_information = initialize_identity_information
@contact_information = initialize_contact_information
if @contact_information&.address&.country.present?
@contact_information.address.country = convert_to_iso2(@contact_information.address.country)
end
mappings = self.class.mappings_for_form(form_id)

form_data = generate_prefill(mappings) if FormProfile.prefill_enabled_forms.include?(form_id)

{ form_data:, metadata: }
end

private

def convert_to_iso2(country_code)
code = IsoCountryCodes.find(country_code)
code.alpha2
end
end
4 changes: 2 additions & 2 deletions app/models/saved_claim.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class SavedClaim < ApplicationRecord
# create a uuid for this second (used in the confirmation number) and store
# the form type based on the constant found in the subclass.
after_initialize do
self.form_id = self.class::FORM.upcase
self.form_id = self.class::FORM.upcase unless instance_of?(SavedClaim::Burial)
end

def self.add_form_and_validation(form_id)
Expand All @@ -51,7 +51,7 @@ def process_attachments!

def submit_to_structured_data_services!
# Only 21P-530 burial forms are supported at this time
if form_id != '21P-530'
unless %w[21P-530 21P-530V2].include?(form_id)
err_message = "Unsupported form id: #{form_id}"
raise Common::Exceptions::UnprocessableEntity.new(detail: err_message), err_message
end
Expand Down
19 changes: 19 additions & 0 deletions app/models/saved_claim/burial.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@
class SavedClaim::Burial < CentralMailClaim
FORM = '21P-530'

# attribute name is passed from the FE as a flag, maintaining camel case
attr_accessor :formV2 # rubocop:disable Naming/MethodName

after_initialize do
self.form_id = if Flipper.enabled?(:va_burial_v2)
formV2 || form_id == '21P-530V2' ? '21P-530V2' : self.class::FORM.upcase
else
self.class::FORM.upcase
end
end

def process_attachments!
refs = attachment_keys.map { |key| Array(open_struct_form.send(key)) }.flatten
files = PersistentAttachment.where(guid: refs.map(&:confirmationCode))
Expand All @@ -25,6 +36,14 @@ def email
parsed_form['claimantEmail']
end

def form_matches_schema
return unless form_is_string

JSON::Validator.fully_validate(VetsJsonSchema::SCHEMAS[form_id], parsed_form).each do |v|
errors.add(:form, v.to_s)
end
end

def business_line
'NCA'
end
Expand Down
3 changes: 3 additions & 0 deletions app/sidekiq/lighthouse/pension_benefit_intake_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require 'benefits_intake_service/service'
require 'central_mail/datestamp_pdf'
require 'simple_forms_api_submission/metadata_validator'
require 'pension_21p527ez/tag_sentry'

module Lighthouse
class PensionBenefitIntakeJob
Expand Down Expand Up @@ -33,6 +34,8 @@ class PensionBenefitIntakeError < StandardError; end
# @param [Integer] saved_claim_id
# rubocop:disable Metrics/MethodLength
def perform(saved_claim_id)
Pension21p527ez::TagSentry.tag_sentry

@saved_claim_id = saved_claim_id
@claim = SavedClaim::Pension.find(saved_claim_id)
raise PensionBenefitIntakeError, "Unable to find SavedClaim::Pension #{saved_claim_id}" unless @claim
Expand Down
3 changes: 1 addition & 2 deletions app/sidekiq/structured_data/process_data_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ def perform(saved_claim_id)
ensure
@claim.process_attachments! # upload claim and attachments to Central Mail

send_confirmation_email if @claim.form_id == '21P-530'

send_confirmation_email if %w[21P-530 21P-530V2].include?(@claim.form_id)
# veteran lookup for hit/miss metrics in support of Automation work
StatsD.increment("#{stats_key}.success",
tags: %W[relationship:#{relationship_type} veteranInMVI:#{veteran&.participant_id}])
Expand Down
Loading

0 comments on commit 841c74e

Please sign in to comment.