-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Validate document attachments at time of upload (#19532)
* Validate document attachments at time of upload * Added flipper for extra validation steps --------- Co-authored-by: Wayne Weibel <[email protected]>
- Loading branch information
1 parent
ad7406c
commit ebf58a6
Showing
10 changed files
with
295 additions
and
77 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'logging/monitor' | ||
|
||
module ClaimDocuments | ||
## | ||
# Monitor functions for Rails logging and StatsD | ||
# @todo abstract, split logging for controller and sidekiq | ||
# | ||
class Monitor < ::Logging::Monitor | ||
# statsd key for document uploads | ||
DOCUMENT_STATS_KEY = 'api.claim_documents' | ||
|
||
def initialize | ||
super('claim_documents') | ||
end | ||
|
||
def track_document_upload_attempt(form_id, current_user) | ||
additional_context = { | ||
user_account_uuid: current_user&.user_account_uuid, | ||
tags: ["form_id:#{form_id}"] | ||
} | ||
track_request('info', "Creating PersistentAttachment FormID=#{form_id}", "#{DOCUMENT_STATS_KEY}.attempt", | ||
**additional_context) | ||
end | ||
|
||
def track_document_upload_success(form_id, attachment_id, current_user) | ||
additional_context = { | ||
attachment_id:, | ||
user_account_uuid: current_user&.user_account_uuid, | ||
tags: ["form_id:#{form_id}"] | ||
} | ||
track_request('info', "Success creating PersistentAttachment FormID=#{form_id} AttachmentID=#{attachment_id}", | ||
"#{DOCUMENT_STATS_KEY}.success", **additional_context) | ||
end | ||
|
||
def track_document_upload_failed(form_id, attachment_id, current_user, e) | ||
additional_context = { | ||
attachment_id:, | ||
user_account_uuid: current_user&.user_account_uuid, | ||
tags: ["form_id:#{form_id}"], | ||
message: e&.message | ||
} | ||
track_request('error', "Error creating PersistentAttachment FormID=#{form_id} AttachmentID=#{attachment_id} #{e}", | ||
"#{DOCUMENT_STATS_KEY}.failure", **additional_context) | ||
end | ||
end | ||
end |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
require 'claim_documents/monitor' | ||
|
||
RSpec.describe ClaimDocuments::Monitor do | ||
let(:service) { OpenStruct.new(uuid: 'uuid') } | ||
let(:monitor) { described_class.new } | ||
let(:document_stats_key) { described_class::DOCUMENT_STATS_KEY } | ||
let(:form_id) { 'ABC123' } | ||
let(:attachment_id) { '12345' } | ||
let(:current_user) { create(:user) } | ||
let(:error) { StandardError.new('An error occurred') } | ||
|
||
describe '#track_document_upload_attempt' do | ||
it 'logs an upload attempt' do | ||
expect(StatsD).to receive(:increment).with("#{document_stats_key}.attempt", tags: ["form_id:#{form_id}"]) | ||
expect(Rails.logger).to receive(:info).with( | ||
"Creating PersistentAttachment FormID=#{form_id}", | ||
hash_including(user_account_uuid: current_user.user_account_uuid, statsd: "#{document_stats_key}.attempt") | ||
) | ||
|
||
monitor.track_document_upload_attempt(form_id, current_user) | ||
end | ||
end | ||
|
||
describe '#track_document_upload_success' do | ||
it 'logs a successful upload' do | ||
expect(StatsD).to receive(:increment).with("#{document_stats_key}.success", tags: ["form_id:#{form_id}"]) | ||
expect(Rails.logger).to receive(:info).with( | ||
"Success creating PersistentAttachment FormID=#{form_id} AttachmentID=#{attachment_id}", | ||
hash_including(user_account_uuid: current_user.user_account_uuid, statsd: "#{document_stats_key}.success") | ||
) | ||
|
||
monitor.track_document_upload_success(form_id, attachment_id, current_user) | ||
end | ||
end | ||
|
||
describe '#track_document_upload_failed' do | ||
it 'logs a failed upload' do | ||
expect(StatsD).to receive(:increment).with("#{document_stats_key}.failure", tags: ["form_id:#{form_id}"]) | ||
expect(Rails.logger).to receive(:error).with( | ||
"Error creating PersistentAttachment FormID=#{form_id} AttachmentID=#{attachment_id} #{error}", | ||
hash_including(user_account_uuid: current_user.user_account_uuid, statsd: "#{document_stats_key}.failure") | ||
) | ||
|
||
monitor.track_document_upload_failed(form_id, attachment_id, current_user, error) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.