Skip to content

Commit

Permalink
Merge e7e8965 into 0e15a72
Browse files Browse the repository at this point in the history
  • Loading branch information
hawx authored Aug 23, 2024
2 parents 0e15a72 + e7e8965 commit 2321b55
Show file tree
Hide file tree
Showing 15 changed files with 255 additions and 203 deletions.
10 changes: 10 additions & 0 deletions internal/actor/actor.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package actor

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

type Actor struct {
Type Type
UID actoruid.UID
FirstNames string
LastName string
}
78 changes: 78 additions & 0 deletions internal/donor/donordata/provided.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package donordata

import (
"errors"
"iter"
"slices"
"strings"
"time"
Expand Down Expand Up @@ -412,3 +413,80 @@ func (l *Provided) CertificateProviderSharesDetails() bool {

return false
}

// 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 *Provided) Actors() iter.Seq[actor.Actor] {
return func(yield func(actor.Actor) bool) {
if !yield(actor.Actor{
Type: actor.TypeDonor,
UID: l.Donor.UID,
FirstNames: l.Donor.FirstNames,
LastName: l.Donor.LastName,
}) {
return
}

if !yield(actor.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.Actor{
Type: actor.TypeAttorney,
UID: attorney.UID,
FirstNames: attorney.FirstNames,
LastName: attorney.LastName,
}) {
return
}
}

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

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

if l.AuthorisedSignatory.FirstNames != "" {
if !yield(actor.Actor{
Type: actor.TypeAuthorisedSignatory,
FirstNames: l.AuthorisedSignatory.FirstNames,
LastName: l.AuthorisedSignatory.LastName,
}) {
return
}
}

if l.IndependentWitness.FirstNames != "" {
if !yield(actor.Actor{
Type: actor.TypeIndependentWitness,
FirstNames: l.IndependentWitness.FirstNames,
LastName: l.IndependentWitness.LastName,
}) {
return
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import (
"fmt"
"testing"
"time"

"slices"

"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"
Expand Down Expand Up @@ -39,7 +40,7 @@ func TestGenerateHash(t *testing.T) {

// DO NOT change these initial hash values. If a field has been added/removed
// you will need to handle the version gracefully by modifying
// (*DonorProvidedDetails).HashInclude and adding another testcase for the new
// (*Provided).HashInclude and adding another testcase for the new
// version.
testcases := map[uint8]uint64{
0: 0x4748f866664816f4,
Expand Down Expand Up @@ -353,3 +354,104 @@ func TestNamesChanged(t *testing.T) {

assert.False(t, donor.NamesChanged("a", "b", "c"))
}

func TestProvidedActors(t *testing.T) {
lpa := &Provided{
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{
FirstNames: "Arthur",
LastName: "Signor",
},
IndependentWitness: IndependentWitness{
FirstNames: "Independent",
LastName: "Wit",
},
Correspondent: Correspondent{FirstNames: "Nope"},
Voucher: Voucher{FirstNames: "Nada"},
}

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

assert.Equal(t, []actor.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",
},{
Type: actor.TypeAuthorisedSignatory,
FirstNames: "Arthur",
LastName: "Signor",
}, {
Type: actor.TypeIndependentWitness,
FirstNames: "Independent",
LastName: "Wit",
}}, actors)
}
27 changes: 6 additions & 21 deletions internal/donor/donorpage/certificate_provider_details.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,29 +134,14 @@ func certificateProviderMatches(donor *donordata.Provided, firstNames, lastName
return actor.TypeNone
}

if strings.EqualFold(donor.Donor.FirstNames, firstNames) && strings.EqualFold(donor.Donor.LastName, lastName) {
return actor.TypeDonor
}

for _, attorney := range donor.Attorneys.Attorneys {
if strings.EqualFold(attorney.FirstNames, firstNames) && strings.EqualFold(attorney.LastName, lastName) {
return actor.TypeAttorney
}
}

for _, attorney := range donor.ReplacementAttorneys.Attorneys {
if strings.EqualFold(attorney.FirstNames, firstNames) && strings.EqualFold(attorney.LastName, lastName) {
return actor.TypeReplacementAttorney
for person := range donor.Actors() {
if !person.Type.IsCertificateProvider() &&
!person.Type.IsPersonToNotify() &&
strings.EqualFold(person.FirstNames, firstNames) &&
strings.EqualFold(person.LastName, lastName) {
return person.Type
}
}

if strings.EqualFold(donor.AuthorisedSignatory.FirstNames, firstNames) && strings.EqualFold(donor.AuthorisedSignatory.LastName, lastName) {
return actor.TypeAuthorisedSignatory
}

if strings.EqualFold(donor.IndependentWitness.FirstNames, firstNames) && strings.EqualFold(donor.IndependentWitness.LastName, lastName) {
return actor.TypeIndependentWitness
}

return actor.TypeNone
}
36 changes: 5 additions & 31 deletions internal/donor/donorpage/choose_attorneys.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,40 +173,14 @@ func attorneyMatches(donor *donordata.Provided, uid actoruid.UID, firstNames, la
return actor.TypeNone
}

if strings.EqualFold(donor.Donor.FirstNames, firstNames) && strings.EqualFold(donor.Donor.LastName, lastName) {
return actor.TypeDonor
}

for _, attorney := range donor.Attorneys.Attorneys {
if attorney.UID != uid && strings.EqualFold(attorney.FirstNames, firstNames) && strings.EqualFold(attorney.LastName, lastName) {
return actor.TypeAttorney
}
}

for _, attorney := range donor.ReplacementAttorneys.Attorneys {
if strings.EqualFold(attorney.FirstNames, firstNames) && strings.EqualFold(attorney.LastName, lastName) {
return actor.TypeReplacementAttorney
}
}

if strings.EqualFold(donor.CertificateProvider.FirstNames, firstNames) && strings.EqualFold(donor.CertificateProvider.LastName, lastName) {
return actor.TypeCertificateProvider
}

for _, person := range donor.PeopleToNotify {
if strings.EqualFold(person.FirstNames, firstNames) && strings.EqualFold(person.LastName, lastName) {
return actor.TypePersonToNotify
for person := range donor.Actors() {
if !(person.Type.IsAttorney() && person.UID == uid) &&
strings.EqualFold(person.FirstNames, firstNames) &&
strings.EqualFold(person.LastName, lastName) {
return person.Type
}
}

if strings.EqualFold(donor.AuthorisedSignatory.FirstNames, firstNames) && strings.EqualFold(donor.AuthorisedSignatory.LastName, lastName) {
return actor.TypeAuthorisedSignatory
}

if strings.EqualFold(donor.IndependentWitness.FirstNames, firstNames) && strings.EqualFold(donor.IndependentWitness.LastName, lastName) {
return actor.TypeIndependentWitness
}

return actor.TypeNone
}

Expand Down
27 changes: 8 additions & 19 deletions internal/donor/donorpage/choose_people_to_notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,25 +124,14 @@ func personToNotifyMatches(donor *donordata.Provided, uid actoruid.UID, firstNam
return actor.TypeNone
}

if strings.EqualFold(donor.Donor.FirstNames, firstNames) && strings.EqualFold(donor.Donor.LastName, lastName) {
return actor.TypeDonor
}

for _, attorney := range donor.Attorneys.Attorneys {
if strings.EqualFold(attorney.FirstNames, firstNames) && strings.EqualFold(attorney.LastName, lastName) {
return actor.TypeAttorney
}
}

for _, attorney := range donor.ReplacementAttorneys.Attorneys {
if strings.EqualFold(attorney.FirstNames, firstNames) && strings.EqualFold(attorney.LastName, lastName) {
return actor.TypeReplacementAttorney
}
}

for _, person := range donor.PeopleToNotify {
if person.UID != uid && strings.EqualFold(person.FirstNames, firstNames) && strings.EqualFold(person.LastName, lastName) {
return actor.TypePersonToNotify
for person := range donor.Actors() {
if !(person.Type.IsPersonToNotify() && person.UID == uid) &&
!person.Type.IsCertificateProvider() &&
!person.Type.IsAuthorisedSignatory() &&
!person.Type.IsIndependentWitness() &&
strings.EqualFold(person.FirstNames, firstNames) &&
strings.EqualFold(person.LastName, lastName) {
return person.Type
}
}

Expand Down
36 changes: 5 additions & 31 deletions internal/donor/donorpage/choose_replacement_attorneys.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,39 +101,13 @@ func replacementAttorneyMatches(donor *donordata.Provided, uid actoruid.UID, fir
return actor.TypeNone
}

if strings.EqualFold(donor.Donor.FirstNames, firstNames) && strings.EqualFold(donor.Donor.LastName, lastName) {
return actor.TypeDonor
}

for _, attorney := range donor.Attorneys.Attorneys {
if strings.EqualFold(attorney.FirstNames, firstNames) && strings.EqualFold(attorney.LastName, lastName) {
return actor.TypeAttorney
}
}

for _, attorney := range donor.ReplacementAttorneys.Attorneys {
if attorney.UID != uid && strings.EqualFold(attorney.FirstNames, firstNames) && strings.EqualFold(attorney.LastName, lastName) {
return actor.TypeReplacementAttorney
}
}

if strings.EqualFold(donor.CertificateProvider.FirstNames, firstNames) && strings.EqualFold(donor.CertificateProvider.LastName, lastName) {
return actor.TypeCertificateProvider
}

for _, person := range donor.PeopleToNotify {
if strings.EqualFold(person.FirstNames, firstNames) && strings.EqualFold(person.LastName, lastName) {
return actor.TypePersonToNotify
for person := range donor.Actors() {
if !(person.Type.IsReplacementAttorney() && person.UID == uid) &&
strings.EqualFold(person.FirstNames, firstNames) &&
strings.EqualFold(person.LastName, lastName) {
return person.Type
}
}

if strings.EqualFold(donor.AuthorisedSignatory.FirstNames, firstNames) && strings.EqualFold(donor.AuthorisedSignatory.LastName, lastName) {
return actor.TypeAuthorisedSignatory
}

if strings.EqualFold(donor.IndependentWitness.FirstNames, firstNames) && strings.EqualFold(donor.IndependentWitness.LastName, lastName) {
return actor.TypeIndependentWitness
}

return actor.TypeNone
}
Loading

0 comments on commit 2321b55

Please sign in to comment.