-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MLPAB-1473: Add holding modal while reduced fee evidence documents are scanned #805
Changes from 33 commits
2db2ddd
faf047b
16a5adc
70b2542
99fbf87
ba65a6b
5d6dd88
3ab6d0b
8f0ae1b
6586032
f80f6f1
c562a25
df8b323
3642c00
cc619e3
b87d069
bf90939
922c48f
c1f423d
f32bea7
3346ca8
048321c
adccd28
01057ef
27e2e39
362049c
65abb2a
cb31c93
6403b44
61c4897
06e83f0
8e2d42b
aed4c62
447c1c9
878a128
baebc5d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,6 +55,11 @@ | |
SendCertificateProvider(context.Context, notify.Template, page.AppData, bool, *page.Lpa) error | ||
} | ||
|
||
//go:generate mockery --testonly --inpackage --name DocumentStore --structname mockDocumentStore | ||
type DocumentStore interface { | ||
UpdateScanResults(ctx context.Context, PK, SK string, virusDetected bool) error | ||
} | ||
|
||
type Event struct { | ||
events.S3Event | ||
events.CloudWatchEvent | ||
|
@@ -110,6 +115,8 @@ | |
|
||
notifyClient, err := notify.New(notifyIsProduction, notifyBaseURL, notifyApiKey, http.DefaultClient) | ||
|
||
documentStore := app.NewDocumentStore(dynamoClient, s3Client) | ||
|
||
bundle := localize.NewBundle("./lang/en.json", "./lang/cy.json") | ||
|
||
//TODO do this in handleFeeApproved when/if we save lang preference in LPA | ||
|
@@ -119,7 +126,7 @@ | |
now := time.Now | ||
|
||
if event.isS3Event() { | ||
return handleObjectTagsAdded(ctx, dynamoClient, event.S3Event, now, s3Client) | ||
return handleObjectTagsAdded(ctx, dynamoClient, event.S3Event, s3Client, documentStore) | ||
} | ||
|
||
if event.isCloudWatchEvent() { | ||
|
@@ -230,7 +237,7 @@ | |
return nil | ||
} | ||
|
||
func handleObjectTagsAdded(ctx context.Context, client dynamodbClient, event events.S3Event, now func() time.Time, s3Client s3Client) error { | ||
func handleObjectTagsAdded(ctx context.Context, dynamodbClient dynamodbClient, event events.S3Event, s3Client s3Client, documentStore DocumentStore) error { | ||
objectKey := event.Records[0].S3.Object.Key | ||
if objectKey == "" { | ||
return fmt.Errorf("object key missing in event in '%s'", objectTagsAddedEventName) | ||
|
@@ -256,26 +263,16 @@ | |
return nil | ||
} | ||
|
||
uid := strings.Split(objectKey, "/") | ||
|
||
lpa, err := getLpaByUID(ctx, client, uid[0], objectTagsAddedEventName) | ||
if err != nil { | ||
return err | ||
} | ||
parts := strings.Split(objectKey, "/") | ||
|
||
document := lpa.Evidence.Get(objectKey) | ||
if document.Key == "" { | ||
return fmt.Errorf("LPA did not contain a document with key %s for '%s'", objectKey, objectTagsAddedEventName) | ||
var lpaKey dynamo.Key | ||
if err := dynamodbClient.OneByUID(ctx, parts[0], &lpaKey); err != nil { | ||
return fmt.Errorf("failed to resolve uid for '%s': %w", objectTagsAddedEventName, err) | ||
} | ||
|
||
document.Scanned = now() | ||
document.VirusDetected = hasVirus | ||
|
||
lpa.Evidence.Put(document) | ||
lpa.UpdatedAt = now() | ||
|
||
if err := client.Put(ctx, lpa); err != nil { | ||
return fmt.Errorf("failed to update LPA for '%s': %w", objectTagsAddedEventName, err) | ||
err = documentStore.UpdateScanResults(ctx, lpaKey.PK, "#DOCUMENT#"+objectKey, hasVirus) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be good to push There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Much simpler - I was going around in circles with circular dependencies but makes more sense to hide the detail. |
||
if err != nil { | ||
return fmt.Errorf("failed to update scan results for '%s': %w", objectTagsAddedEventName, err) | ||
} | ||
|
||
return nil | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
keep
pk, sk
lowercase