Skip to content

Commit 407814a

Browse files
committed
Add scheduled events to remind certificate provider
1 parent 860e2f4 commit 407814a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+3013
-407
lines changed

cmd/event-received/sirius_event_handler.go

+18-6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore"
1717
"github.com/ministryofjustice/opg-modernising-lpa/internal/notify"
1818
"github.com/ministryofjustice/opg-modernising-lpa/internal/pay"
19+
"github.com/ministryofjustice/opg-modernising-lpa/internal/scheduled"
1920
"github.com/ministryofjustice/opg-modernising-lpa/internal/sharecode"
2021
"github.com/ministryofjustice/opg-modernising-lpa/internal/task"
2122
)
@@ -231,16 +232,27 @@ func handleDonorSubmissionCompleted(ctx context.Context, client dynamodbClient,
231232
lpaID := uuidString()
232233

233234
donor := &donordata.Provided{
234-
PK: dynamo.LpaKey(lpaID),
235-
SK: dynamo.LpaOwnerKey(dynamo.DonorKey("PAPER")),
236-
LpaID: lpaID,
237-
LpaUID: v.UID,
238-
CreatedAt: now(),
239-
Version: 1,
235+
PK: dynamo.LpaKey(lpaID),
236+
SK: dynamo.LpaOwnerKey(dynamo.DonorKey("PAPER")),
237+
LpaID: lpaID,
238+
LpaUID: v.UID,
239+
CreatedAt: now(),
240+
Version: 1,
241+
CertificateProviderInvitedAt: now(),
240242
}
241243

242244
transaction := dynamo.NewTransaction().
243245
Create(donor).
246+
Create(scheduled.Event{
247+
PK: dynamo.ScheduledDayKey(donor.CertificateProviderInvitedAt.AddDate(0, 3, 1)),
248+
SK: dynamo.ScheduledKey(donor.CertificateProviderInvitedAt.AddDate(0, 3, 1), int(scheduled.ActionRemindCertificateProviderToComplete)),
249+
CreatedAt: now(),
250+
At: donor.CertificateProviderInvitedAt.AddDate(0, 3, 1),
251+
Action: scheduled.ActionRemindCertificateProviderToComplete,
252+
TargetLpaKey: donor.PK,
253+
TargetLpaOwnerKey: donor.SK,
254+
LpaUID: donor.LpaUID,
255+
}).
244256
Create(dynamo.Keys{PK: dynamo.UIDKey(v.UID), SK: dynamo.MetadataKey("")}).
245257
Create(dynamo.Keys{PK: donor.PK, SK: dynamo.ReservedKey(dynamo.DonorKey)})
246258

cmd/event-received/sirius_event_handler_test.go

+18-6
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore/lpadata"
2121
"github.com/ministryofjustice/opg-modernising-lpa/internal/notify"
2222
"github.com/ministryofjustice/opg-modernising-lpa/internal/pay"
23+
"github.com/ministryofjustice/opg-modernising-lpa/internal/scheduled"
2324
"github.com/ministryofjustice/opg-modernising-lpa/internal/sharecode"
2425
"github.com/ministryofjustice/opg-modernising-lpa/internal/task"
2526
"github.com/stretchr/testify/assert"
@@ -756,12 +757,23 @@ func TestHandleDonorSubmissionCompleted(t *testing.T) {
756757
WriteTransaction(ctx, &dynamo.Transaction{
757758
Creates: []any{
758759
&donordata.Provided{
759-
PK: dynamo.LpaKey(testUuidString),
760-
SK: dynamo.LpaOwnerKey(dynamo.DonorKey("PAPER")),
761-
LpaID: testUuidString,
762-
LpaUID: "M-1111-2222-3333",
763-
CreatedAt: testNow,
764-
Version: 1,
760+
PK: dynamo.LpaKey(testUuidString),
761+
SK: dynamo.LpaOwnerKey(dynamo.DonorKey("PAPER")),
762+
LpaID: testUuidString,
763+
LpaUID: "M-1111-2222-3333",
764+
CreatedAt: testNow,
765+
Version: 1,
766+
CertificateProviderInvitedAt: testNow,
767+
},
768+
scheduled.Event{
769+
PK: dynamo.ScheduledDayKey(testNow.AddDate(0, 3, 1)),
770+
SK: dynamo.ScheduledKey(testNow.AddDate(0, 3, 1), int(scheduled.ActionRemindCertificateProviderToComplete)),
771+
CreatedAt: testNow,
772+
At: testNow.AddDate(0, 3, 1),
773+
Action: scheduled.ActionRemindCertificateProviderToComplete,
774+
TargetLpaKey: dynamo.LpaKey(testUuidString),
775+
TargetLpaOwnerKey: dynamo.LpaOwnerKey(dynamo.DonorKey("PAPER")),
776+
LpaUID: "M-1111-2222-3333",
765777
},
766778
dynamo.Keys{PK: dynamo.UIDKey("M-1111-2222-3333"), SK: dynamo.MetadataKey("")},
767779
dynamo.Keys{PK: dynamo.LpaKey(testUuidString), SK: dynamo.ReservedKey(dynamo.DonorKey)},

cmd/schedule-runner/main.go

+29-5
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,18 @@ import (
99
"os"
1010
"time"
1111

12-
"github.com/aws/aws-lambda-go/lambda"
12+
awslambda "github.com/aws/aws-lambda-go/lambda"
1313
"github.com/aws/aws-sdk-go-v2/aws"
14+
v4 "github.com/aws/aws-sdk-go-v2/aws/signer/v4"
1415
"github.com/aws/aws-sdk-go-v2/config"
1516
"github.com/aws/aws-sdk-go-v2/service/cloudwatch"
17+
"github.com/ministryofjustice/opg-modernising-lpa/internal/certificateprovider"
1618
"github.com/ministryofjustice/opg-modernising-lpa/internal/donor"
1719
"github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo"
1820
"github.com/ministryofjustice/opg-modernising-lpa/internal/event"
21+
"github.com/ministryofjustice/opg-modernising-lpa/internal/lambda"
1922
"github.com/ministryofjustice/opg-modernising-lpa/internal/localize"
23+
"github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore"
2024
"github.com/ministryofjustice/opg-modernising-lpa/internal/notify"
2125
"github.com/ministryofjustice/opg-modernising-lpa/internal/scheduled"
2226
"github.com/ministryofjustice/opg-modernising-lpa/internal/search"
@@ -40,6 +44,9 @@ var (
4044
searchIndexingEnabled = os.Getenv("SEARCH_INDEXING_DISABLED") != "1"
4145
tableName = os.Getenv("LPAS_TABLE")
4246
xrayEnabled = os.Getenv("XRAY_ENABLED") == "1"
47+
lpaStoreBaseURL = os.Getenv("LPA_STORE_BASE_URL")
48+
lpaStoreSecretARN = os.Getenv("LPA_STORE_SECRET_ARN")
49+
appPublicURL = os.Getenv("APP_PUBLIC_URL")
4350

4451
Tag string
4552

@@ -81,8 +88,13 @@ func handleRunSchedule(ctx context.Context) error {
8188
return err
8289
}
8390

84-
donorStore := donor.NewStore(dynamoClient, eventClient, logger, searchClient)
91+
lambdaClient := lambda.New(cfg, v4.NewSigner(), httpClient, time.Now)
92+
lpaStoreClient := lpastore.New(lpaStoreBaseURL, secretsClient, lpaStoreSecretARN, lambdaClient)
93+
8594
scheduledStore := scheduled.NewStore(dynamoClient)
95+
donorStore := donor.NewStore(dynamoClient, eventClient, logger, searchClient)
96+
certificateProviderStore := certificateprovider.NewStore(dynamoClient)
97+
lpaStoreResolvingService := lpastore.NewResolvingService(donorStore, lpaStoreClient)
8698

8799
if Tag == "" {
88100
Tag = os.Getenv("TAG")
@@ -91,7 +103,19 @@ func handleRunSchedule(ctx context.Context) error {
91103
client := cloudwatch.NewFromConfig(cfg)
92104
metricsClient := telemetry.NewMetricsClient(client, Tag)
93105

94-
runner := scheduled.NewRunner(logger, scheduledStore, donorStore, notifyClient, metricsClient, metricsEnabled)
106+
runner := scheduled.NewRunner(
107+
logger,
108+
scheduledStore,
109+
donorStore,
110+
certificateProviderStore,
111+
lpaStoreResolvingService,
112+
notifyClient,
113+
eventClient,
114+
bundle,
115+
metricsClient,
116+
metricsEnabled,
117+
appPublicURL,
118+
)
95119

96120
if err = runner.Run(ctx); err != nil {
97121
logger.Error("runner error", slog.Any("err", err))
@@ -154,8 +178,8 @@ func main() {
154178
}
155179
}(ctx)
156180

157-
lambda.Start(otellambda.InstrumentHandler(handleRunSchedule, xrayconfig.WithRecommendedOptions(tp)...))
181+
awslambda.Start(otellambda.InstrumentHandler(handleRunSchedule, xrayconfig.WithRecommendedOptions(tp)...))
158182
} else {
159-
lambda.Start(handleRunSchedule)
183+
awslambda.Start(handleRunSchedule)
160184
}
161185
}

internal/actor/type.go

+1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ const (
1515
TypeTrustCorporation // trustCorporation
1616
TypeReplacementTrustCorporation // replacementTrustCorporation
1717
TypeVoucher // voucher
18+
TypeCorrespondent // correspondent
1819
)

internal/app/app.go

+1
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ func App(
213213
lpaStoreResolvingService,
214214
donorStore,
215215
eventClient,
216+
scheduledStore,
216217
appPublicURL,
217218
)
218219

internal/certificateprovider/certificateproviderpage/mock_ScheduledStore_test.go

+98
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/certificateprovider/certificateproviderpage/mock_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package certificateproviderpage
22

33
import (
44
"errors"
5+
"time"
56

67
"github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext"
78
"github.com/ministryofjustice/opg-modernising-lpa/internal/localize"
@@ -22,4 +23,6 @@ var (
2223
LpaID: "lpa-id",
2324
Lang: localize.En,
2425
}
26+
testNow = time.Now()
27+
testNowFn = func() time.Time { return testNow }
2528
)

internal/certificateprovider/certificateproviderpage/provide_certificate.go

+21-7
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore/lpadata"
1414
"github.com/ministryofjustice/opg-modernising-lpa/internal/notify"
1515
"github.com/ministryofjustice/opg-modernising-lpa/internal/page"
16+
"github.com/ministryofjustice/opg-modernising-lpa/internal/scheduled"
1617
"github.com/ministryofjustice/opg-modernising-lpa/internal/task"
1718
"github.com/ministryofjustice/opg-modernising-lpa/internal/validation"
1819
)
@@ -31,13 +32,10 @@ func ProvideCertificate(
3132
notifyClient NotifyClient,
3233
shareCodeSender ShareCodeSender,
3334
lpaStoreClient LpaStoreClient,
35+
scheduledStore ScheduledStore,
3436
now func() time.Time,
3537
) Handler {
3638
return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, certificateProvider *certificateproviderdata.Provided, lpa *lpadata.Lpa) error {
37-
if !lpa.SignedForDonor() {
38-
return certificateprovider.PathTaskList.Redirect(w, r, appData, lpa.LpaID)
39-
}
40-
4139
if !certificateProvider.SignedAt.IsZero() {
4240
return certificateprovider.PathCertificateProvided.Redirect(w, r, appData, lpa.LpaID)
4341
}
@@ -65,7 +63,7 @@ func ProvideCertificate(
6563

6664
if lpa.CertificateProvider.SignedAt == nil || lpa.CertificateProvider.SignedAt.IsZero() {
6765
if err := lpaStoreClient.SendCertificateProvider(r.Context(), certificateProvider, lpa); err != nil {
68-
return err
66+
return fmt.Errorf("error sending certificate provider to lpa-store: %w", err)
6967
}
7068
} else {
7169
certificateProvider.SignedAt = *lpa.CertificateProvider.SignedAt
@@ -82,11 +80,27 @@ func ProvideCertificate(
8280
}
8381

8482
if err := shareCodeSender.SendAttorneys(r.Context(), appData, lpa); err != nil {
85-
return err
83+
return fmt.Errorf("error sending sharecode to attorneys: %w", err)
84+
}
85+
86+
if !certificateProvider.Tasks.ConfirmYourIdentity.IsCompleted() {
87+
if err := scheduledStore.Create(r.Context(), scheduled.Event{
88+
At: certificateProvider.SignedAt.AddDate(0, 3, 1),
89+
Action: scheduled.ActionRemindCertificateProviderToConfirmIdentity,
90+
TargetLpaKey: certificateProvider.PK,
91+
LpaUID: lpa.LpaUID,
92+
}, scheduled.Event{
93+
At: lpa.SignedAt.AddDate(0, 21, 1),
94+
Action: scheduled.ActionRemindCertificateProviderToConfirmIdentity,
95+
TargetLpaKey: certificateProvider.PK,
96+
LpaUID: lpa.LpaUID,
97+
}); err != nil {
98+
return fmt.Errorf("error scheduling certificate provider prompt: %w", err)
99+
}
86100
}
87101

88102
if err := certificateProviderStore.Put(r.Context(), certificateProvider); err != nil {
89-
return err
103+
return fmt.Errorf("error updating certificate provider: %w", err)
90104
}
91105

92106
return certificateprovider.PathCertificateProvided.Redirect(w, r, appData, certificateProvider.LpaID)

0 commit comments

Comments
 (0)