Skip to content

Commit

Permalink
Merge pull request #1441 from ministryofjustice/MLPAB-2329-same-same
Browse files Browse the repository at this point in the history
MLPAB-2329 Show voucher confirmation page when name matches other actor
  • Loading branch information
hawx authored Aug 22, 2024
2 parents d0fb4dc + b24a5cf commit 49a5146
Show file tree
Hide file tree
Showing 16 changed files with 349 additions and 44 deletions.
2 changes: 1 addition & 1 deletion cmd/mlpa/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func run(ctx context.Context, logger *slog.Logger) error {
if metadataURL != "" {
region, err = awsRegion(metadataURL)
if err != nil {
logger.Warn("error getting region:", err)
logger.Warn("error getting region:", slog.Any("err", err))
}
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/ministryofjustice/opg-modernising-lpa

go 1.22.5
go 1.23.0

require (
github.com/MicahParks/jwkset v0.5.18
Expand Down
32 changes: 28 additions & 4 deletions internal/lpastore/lpa.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"net/http"
"time"

"github.com/ministryofjustice/opg-modernising-lpa/internal/actor"
"github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid"
"github.com/ministryofjustice/opg-modernising-lpa/internal/date"
"github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata"
Expand Down Expand Up @@ -404,9 +405,10 @@ func lpaResponseToLpa(l lpaResponse) *lpadata.Lpa {
},
HowShouldReplacementAttorneysStepIn: l.HowReplacementAttorneysStepIn,
HowShouldReplacementAttorneysStepInDetails: l.HowReplacementAttorneysStepInDetails,
Restrictions: l.Restrictions,
WhenCanTheLpaBeUsed: l.WhenTheLpaCanBeUsed,
LifeSustainingTreatmentOption: l.LifeSustainingTreatmentOption,
Restrictions: l.Restrictions,
WhenCanTheLpaBeUsed: l.WhenTheLpaCanBeUsed,
LifeSustainingTreatmentOption: l.LifeSustainingTreatmentOption,
// TODO: add authorised signatory and independent witness when these become available
SignedAt: l.SignedAt,
CertificateProviderNotRelatedConfirmedAt: confirmedAt,
CannotRegister: l.Status == "cannot-register",
Expand Down Expand Up @@ -484,6 +486,26 @@ func FromDonorProvidedDetails(l *donordata.Provided) *lpadata.Lpa {
}
}

var authorisedSignatory lpadata.Actor
if v := l.AuthorisedSignatory; v.FirstNames != "" {
authorisedSignatory = lpadata.Actor{
// TODO: add UID for this actor
Type: actor.TypeAuthorisedSignatory,
FirstNames: v.FirstNames,
LastName: v.LastName,
}
}

var independentWitness lpadata.Actor
if v := l.IndependentWitness; v.FirstNames != "" {
independentWitness = lpadata.Actor{
// TODO: add UID for this actor
Type: actor.TypeIndependentWitness,
FirstNames: v.FirstNames,
LastName: v.LastName,
}
}

return &lpadata.Lpa{
LpaID: l.LpaID,
LpaUID: l.LpaUID,
Expand Down Expand Up @@ -533,7 +555,9 @@ func FromDonorProvidedDetails(l *donordata.Provided) *lpadata.Lpa {
LastName: l.Correspondent.LastName,
Email: l.Correspondent.Email,
},
Voucher: voucher,
AuthorisedSignatory: authorisedSignatory,
IndependentWitness: independentWitness,
Voucher: voucher,
}
}

Expand Down
81 changes: 81 additions & 0 deletions internal/lpastore/lpadata/lpa.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package lpadata

import (
"iter"
"time"

"github.com/ministryofjustice/opg-modernising-lpa/internal/actor"
"github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid"
"github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo"
)

Expand All @@ -28,6 +31,8 @@ type Lpa struct {
Restrictions string
WhenCanTheLpaBeUsed CanBeUsedWhen
LifeSustainingTreatmentOption LifeSustainingTreatment
AuthorisedSignatory Actor
IndependentWitness Actor

// SignedAt is the date the Donor signed their LPA (and signifies it has been
// witnessed by their CertificateProvider)
Expand Down Expand Up @@ -99,3 +104,79 @@ func (l Lpa) AllAttorneysSigned() bool {

return true
}

type Actor struct {
Type actor.Type
UID actoruid.UID
FirstNames string
LastName string
}

// Actors returns an iterator over all human actors named on the LPA (i.e. this
// excludes trust corporations, the correspondent, and the voucher).
func (l Lpa) Actors() iter.Seq[Actor] {
return func(yield func(Actor) bool) {
if !yield(Actor{
Type: actor.TypeDonor,
UID: l.Donor.UID,
FirstNames: l.Donor.FirstNames,
LastName: l.Donor.LastName,
}) {
return
}

if !yield(Actor{
Type: actor.TypeCertificateProvider,
UID: l.CertificateProvider.UID,
FirstNames: l.CertificateProvider.FirstNames,
LastName: l.CertificateProvider.LastName,
}) {
return
}

for _, attorney := range l.Attorneys.Attorneys {
if !yield(Actor{
Type: actor.TypeAttorney,
UID: attorney.UID,
FirstNames: attorney.FirstNames,
LastName: attorney.LastName,
}) {
return
}
}

for _, attorney := range l.ReplacementAttorneys.Attorneys {
if !yield(Actor{
Type: actor.TypeReplacementAttorney,
UID: attorney.UID,
FirstNames: attorney.FirstNames,
LastName: attorney.LastName,
}) {
return
}
}

for _, person := range l.PeopleToNotify {
if !yield(Actor{
Type: actor.TypePersonToNotify,
UID: person.UID,
FirstNames: person.FirstNames,
LastName: person.LastName,
}) {
return
}
}

if !l.AuthorisedSignatory.UID.IsZero() {
if !yield(l.AuthorisedSignatory) {
return
}
}

if !l.IndependentWitness.UID.IsZero() {
if !yield(l.IndependentWitness) {
return
}
}
}
}
96 changes: 96 additions & 0 deletions internal/lpastore/lpadata/lpa_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package lpadata

import (
"slices"
"testing"
"time"

"github.com/ministryofjustice/opg-modernising-lpa/internal/actor"
"github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -87,3 +90,96 @@ func TestLpaCorrespondentEmailWhenCorrespondentProvided(t *testing.T) {
}
assert.Equal(t, "correspondent", lpa.CorrespondentEmail())
}

func TestLpaActors(t *testing.T) {
authorisedSignatory := Actor{UID: actoruid.New()}
independentWitness := Actor{UID: actoruid.New()}

lpa := &Lpa{
Donor: Donor{
UID: actoruid.New(),
FirstNames: "Sam",
LastName: "Smith",
},
CertificateProvider: CertificateProvider{
UID: actoruid.New(),
FirstNames: "Charlie",
LastName: "Cooper",
},
Attorneys: Attorneys{
Attorneys: []Attorney{{
UID: actoruid.New(),
FirstNames: "Alan",
LastName: "Attorney",
}, {
UID: actoruid.New(),
FirstNames: "Angela",
LastName: "Attorney",
}},
TrustCorporation: TrustCorporation{Name: "Trusty"},
},
ReplacementAttorneys: Attorneys{
Attorneys: []Attorney{{
UID: actoruid.New(),
FirstNames: "Richard",
LastName: "Replacement",
}, {
UID: actoruid.New(),
FirstNames: "Rachel",
LastName: "Replacement",
}},
TrustCorporation: TrustCorporation{Name: "Untrusty"},
},
PeopleToNotify: []PersonToNotify{{
UID: actoruid.New(),
FirstNames: "Peter",
LastName: "Person",
}},
AuthorisedSignatory: authorisedSignatory,
IndependentWitness: independentWitness,
Correspondent: Correspondent{FirstNames: "Nope"},
Voucher: Voucher{FirstNames: "Nada"},
}

actors := slices.Collect(lpa.Actors())

assert.Equal(t, []Actor{{
Type: actor.TypeDonor,
UID: lpa.Donor.UID,
FirstNames: "Sam",
LastName: "Smith",
}, {
Type: actor.TypeCertificateProvider,
UID: lpa.CertificateProvider.UID,
FirstNames: "Charlie",
LastName: "Cooper",
}, {
Type: actor.TypeAttorney,
UID: lpa.Attorneys.Attorneys[0].UID,
FirstNames: "Alan",
LastName: "Attorney",
}, {
Type: actor.TypeAttorney,
UID: lpa.Attorneys.Attorneys[1].UID,
FirstNames: "Angela",
LastName: "Attorney",
}, {
Type: actor.TypeReplacementAttorney,
UID: lpa.ReplacementAttorneys.Attorneys[0].UID,
FirstNames: "Richard",
LastName: "Replacement",
}, {
Type: actor.TypeReplacementAttorney,
UID: lpa.ReplacementAttorneys.Attorneys[1].UID,
FirstNames: "Rachel",
LastName: "Replacement",
}, {
Type: actor.TypePersonToNotify,
UID: lpa.PeopleToNotify[0].UID,
FirstNames: "Peter",
LastName: "Person",
},
authorisedSignatory,
independentWitness,
}, actors)
}
20 changes: 19 additions & 1 deletion internal/lpastore/resolving_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"

"github.com/ministryofjustice/opg-modernising-lpa/internal/actor"
"github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata"
"github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo"
"github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore/lpadata"
Expand Down Expand Up @@ -102,7 +103,6 @@ func (s *ResolvingService) merge(lpa *lpadata.Lpa, donor *donordata.Provided) *l
LastName: donor.Correspondent.LastName,
Email: donor.Correspondent.Email,
}

if donor.Voucher.Allowed {
lpa.Voucher = lpadata.Voucher{
UID: donor.Voucher.UID,
Expand All @@ -112,6 +112,24 @@ func (s *ResolvingService) merge(lpa *lpadata.Lpa, donor *donordata.Provided) *l
}
}

// TODO: remove this once authorised signatory is in lpa-store
if lpa.AuthorisedSignatory.FirstNames == "" && donor.AuthorisedSignatory.FirstNames != "" {
lpa.AuthorisedSignatory = lpadata.Actor{
Type: actor.TypeAuthorisedSignatory,
FirstNames: donor.AuthorisedSignatory.FirstNames,
LastName: donor.AuthorisedSignatory.LastName,
}
}

// TODO: remove this once independent witness is in lpa-store
if lpa.IndependentWitness.FirstNames == "" && donor.IndependentWitness.FirstNames != "" {
lpa.IndependentWitness = lpadata.Actor{
Type: actor.TypeIndependentWitness,
FirstNames: donor.IndependentWitness.FirstNames,
LastName: donor.IndependentWitness.LastName,
}
}

// copy the relationship as it isn't stored in the lpastore.
lpa.CertificateProvider.Relationship = donor.CertificateProvider.Relationship

Expand Down
Loading

0 comments on commit 49a5146

Please sign in to comment.