Skip to content

Commit

Permalink
[Automated] Merged master into target k8s
Browse files Browse the repository at this point in the history
  • Loading branch information
va-vsp-bot authored Apr 17, 2024
2 parents f983b4c + 1e28915 commit e3599d1
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 36 deletions.
9 changes: 0 additions & 9 deletions app/sidekiq/education_form/templates/10203.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
CH33
*START*
<%= form_identifier %>
<% if Settings.vsp_environment.eql?('production') -%>
JUN 2020
<% else -%>
OMB Control #: 2900-0878
<% end -%>


APPLICATION FOR EDITH NOURSE ROGERS STEM SCHOLARSHIP
Expand Down Expand Up @@ -73,10 +69,6 @@ Applicant has POA: <%= yesno(@stem_automated_decision.poa) %>
Applicant School Email Address: <%= @applicant.schoolEmailAddress %>
Applicant School ID: <%= @applicant.schoolStudentId %>

<% if Settings.vsp_environment.eql?('production') -%>
Certification and Signature of Applicant
Signature of Applicant Date
<% else -%>
<% if @applicant.isActiveDuty -%>
As an active-duty service member, you have consulted with an Education Service
Officer (ESO) regarding your education program.
Expand All @@ -86,5 +78,4 @@ Signature of Applicant Date
<% end -%>


<% end -%>
<%= parse_with_template_path('footer') %>
29 changes: 13 additions & 16 deletions modules/appeals_api/app/services/appeals_api/remove_pii.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require 'ddtrace'

module AppealsApi
class RemovePii
include SentryLogging
Expand All @@ -15,13 +17,20 @@ def initialize(form_type:)
end

def run!
validate_form_type!
Datadog::Tracing.trace("#{self.class.name} - #{form_type}") do
validate_form_type!

result = remove_pii!
result = remove_pii!

log_failure_to_sentry if records_were_not_cleared(result)
if result.blank? && records_to_be_expunged.present?
ids = records_to_be_expunged.pluck(:id)
msg = "Failed to remove expired #{form_type} PII from records"
Rails.logger.error(msg, ids)
AppealsApi::Slack::Messager.new({ msg:, ids: }).notify!
end

result
result
end
end

private
Expand Down Expand Up @@ -49,17 +58,5 @@ def records_to_be_expunged
.pii_expunge_policy
end
end

def records_were_not_cleared(result)
result.blank? && records_to_be_expunged.present?
end

def log_failure_to_sentry
log_message_to_sentry(
"Failed to expunge PII from #{form_type} (modules/appeals_api)",
:error,
ids: records_to_be_expunged.pluck(:id)
)
end
end
end
35 changes: 26 additions & 9 deletions modules/appeals_api/spec/services/appeals_api/remove_pii_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# frozen_string_literal: true

require 'rails_helper'
require AppealsApi::Engine.root.join('spec', 'spec_helper.rb')

def update_appeal_status(appeal, status, code: nil, detail: nil)
# At the time of writing, the `update_status` method for each appeal model involves kicking off a sidekiq job to
Expand Down Expand Up @@ -159,6 +158,32 @@ def create_misc_appeals = create_appeals + misc_appeal_types.map { |f| FactoryBo
expect { AppealsApi::RemovePii.new(form_type: 'Invalid').run! }.to raise_error(ArgumentError)
end

context 'when the removal fails' do
let!(:appeals) do
Timecop.freeze(100.days.ago) do
status = 'complete'
[create(:supplemental_claim, status:), create(:supplemental_claim_v0, status:)]
end
end

before do
instance = AppealsApi::RemovePii.new(form_type: AppealsApi::SupplementalClaim)
msg = 'Failed to remove expired AppealsApi::SupplementalClaim PII from records'
expect(Rails.logger).to receive(:error).with(msg, appeals.map(&:id))
expect_any_instance_of(AppealsApi::Slack::Messager).to receive(:notify!)
allow(instance).to receive(:remove_pii!).and_return []
instance.run!
end

it 'logs an error and the IDs of records whose PII failed to be removed' do
appeals.each do |appeal|
appeal.reload
expect(appeal.auth_headers).to be_present
expect(appeal.form_data).to be_present
end
end
end

it 'removes PII from HLR records needing PII removal' do
day_old_has_pii_v2 = create :higher_level_review_v2, status: 'complete'
day_old_has_pii_v2.update updated_at: 1.day.ago
Expand Down Expand Up @@ -271,13 +296,5 @@ def create_misc_appeals = create_appeals + misc_appeal_types.map { |f| FactoryBo
expect(week_old_has_pii_error.reload.form_data_ciphertext).to be_present
end
end

it 'sends a message to sentry if the removal failed.' do
allow_any_instance_of(AppealsApi::RemovePii).to receive(:records_were_not_cleared).and_return(true)
service = AppealsApi::RemovePii.new(form_type: AppealsApi::NoticeOfDisagreement)
expect(service).to receive(:log_failure_to_sentry)

service.run!
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ class InquiriesController < ApplicationController
around_action :handle_exceptions
before_action :get_inquiries_by_icn, only: [:index]
before_action :get_inquiry_by_id, only: [:show]
skip_before_action :authenticate, only: %i[unauth_create upload_attachment]
skip_before_action :verify_authenticity_token, only: %i[unauth_create upload_attachment]
skip_before_action :authenticate, only: %i[unauth_create upload_attachment test_create]
skip_before_action :verify_authenticity_token, only: %i[unauth_create upload_attachment test_create]

def index
render json: @user_inquiries.payload, status: @user_inquiries.status
Expand All @@ -17,6 +17,14 @@ def show
render json: @inquiry.payload, status: @inquiry.status
end

def test_create
service = Crm::Service.new(icn: nil)
payload = { reply: params[:reply] }
response = service.call(endpoint: params[:endpoint], method: :post, payload:)

render json: response.to_json, status: :ok
end

def create
render json: { message: 'success' }, status: :created
end
Expand Down
1 change: 1 addition & 0 deletions modules/ask_va_api/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
post '/inquiries', to: 'inquiries#unauth_create'
post '/upload_attachment', to: 'inquiries#upload_attachment'
post '/inquiries/:id/reply/new', to: 'inquiries#create_reply'
post '/test_create', to: 'inquiries#test_create'

# static_data
get '/categories', to: 'static_data#categories'
Expand Down
13 changes: 13 additions & 0 deletions modules/ask_va_api/spec/requests/v0/inquiries_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,19 @@
end
end

describe 'POST #test_create' do
before do
allow_any_instance_of(Crm::Service).to receive(:call).and_return({ message: 'success' })
post '/ask_va_api/v0/test_create',
params: { 'reply' => 'test', 'endpoint' => 'inquiries/id/reply/new' },
as: :json
end

it 'response with 200' do
expect(response).to have_http_status(:ok)
end
end

describe 'GET #show' do
let(:expected_response) do
{ 'data' =>
Expand Down

0 comments on commit e3599d1

Please sign in to comment.