Skip to content

Commit

Permalink
Merge 0ecd3ce into 17482a2
Browse files Browse the repository at this point in the history
  • Loading branch information
hawx authored May 20, 2024
2 parents 17482a2 + 0ecd3ce commit 0edbcc7
Show file tree
Hide file tree
Showing 8 changed files with 351 additions and 88 deletions.
10 changes: 5 additions & 5 deletions internal/actor/attorney_provided.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,20 @@ type AttorneyProvidedDetails struct {

// Signed checks whether the attorney has confirmed and if that confirmation is
// still valid by checking that it was made for the donor's current signature.
func (d AttorneyProvidedDetails) Signed(after time.Time) bool {
func (d AttorneyProvidedDetails) Signed() bool {
if d.IsTrustCorporation {
switch d.WouldLikeSecondSignatory {
case form.Yes:
return d.AuthorisedSignatories[0].Confirmed.After(after) &&
d.AuthorisedSignatories[1].Confirmed.After(after)
return !d.AuthorisedSignatories[0].Confirmed.IsZero() &&
!d.AuthorisedSignatories[1].Confirmed.IsZero()
case form.No:
return d.AuthorisedSignatories[0].Confirmed.After(after)
return !d.AuthorisedSignatories[0].Confirmed.IsZero()
default:
return false
}
}

return d.Confirmed.After(after)
return !d.Confirmed.IsZero()
}

type AttorneyTasks struct {
Expand Down
5 changes: 1 addition & 4 deletions internal/actor/attorney_provided_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ func TestAttorneyProvidedDetailsSigned(t *testing.T) {
details: AttorneyProvidedDetails{Confirmed: attorneySignedAt},
signed: true,
},
"signed for different iteration": {
details: AttorneyProvidedDetails{Confirmed: lpaSignedAt},
},
"trust corporation unsigned": {
details: AttorneyProvidedDetails{Confirmed: attorneySignedAt, IsTrustCorporation: true},
},
Expand Down Expand Up @@ -70,7 +67,7 @@ func TestAttorneyProvidedDetailsSigned(t *testing.T) {

for name, tc := range testcases {
t.Run(name, func(t *testing.T) {
assert.Equal(t, tc.signed, tc.details.Signed(lpaSignedAt))
assert.Equal(t, tc.signed, tc.details.Signed())
})
}
}
2 changes: 1 addition & 1 deletion internal/page/app_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (d AppData) IsAttorneyType() bool {
}

func (d AppData) IsReplacementAttorney() bool {
return d.ActorType == actor.TypeReplacementAttorney
return d.ActorType == actor.TypeReplacementAttorney || d.ActorType == actor.TypeReplacementTrustCorporation
}

func (d AppData) IsTrustCorporation() bool {
Expand Down
2 changes: 1 addition & 1 deletion internal/page/attorney/progress.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func Progress(tmpl template.Template, lpaStoreResolvingService LpaStoreResolving
data := &progressData{
App: appData,
Lpa: lpa,
Signed: attorneyProvidedDetails.Signed(lpa.SignedAt),
Signed: attorneyProvidedDetails.Signed(),
AttorneysSigned: lpa.AllAttorneysSigned(),
}

Expand Down
137 changes: 90 additions & 47 deletions internal/page/attorney/sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,59 +30,79 @@ func Sign(
lpaStoreClient LpaStoreClient,
now func() time.Time,
) Handler {
return func(appData page.AppData, w http.ResponseWriter, r *http.Request, attorneyProvidedDetails *actor.AttorneyProvidedDetails) error {
signatoryIndex := 0
if r.URL.Query().Has("second") {
signatoryIndex = 1
signAttorney := func(appData page.AppData, w http.ResponseWriter, r *http.Request, attorneyProvidedDetails *actor.AttorneyProvidedDetails, lpa *lpastore.Lpa) error {
data := &signData{
App: appData,
LpaID: lpa.LpaID,
IsReplacement: appData.IsReplacementAttorney(),
LpaCanBeUsedWhenHasCapacity: lpa.WhenCanTheLpaBeUsed.IsHasCapacity(),
Form: &signForm{},
}

lpa, err := lpaStoreResolvingService.Get(r.Context())
if err != nil {
return err
attorneys := lpa.Attorneys
if appData.IsReplacementAttorney() {
attorneys = lpa.ReplacementAttorneys
}

if lpa.SignedAt.IsZero() || lpa.CertificateProvider.SignedAt.IsZero() {
return page.Paths.Attorney.TaskList.Redirect(w, r, appData, attorneyProvidedDetails.LpaID)
attorney, ok := attorneys.Get(appData.AttorneyUID)
if !ok {
return page.Paths.Attorney.Start.Redirect(w, r, appData)
}

data.Attorney = attorney

if r.Method == http.MethodPost {
data.Form = readSignForm(r)
data.Errors = data.Form.Validate(appData.IsTrustCorporation(), appData.IsReplacementAttorney())

if data.Errors.None() {
attorneyProvidedDetails.Tasks.SignTheLpa = actor.TaskCompleted
attorneyProvidedDetails.Confirmed = now()

if attorney.SignedAt.IsZero() {
if err := lpaStoreClient.SendAttorney(r.Context(), lpa, attorneyProvidedDetails); err != nil {
return err
}
} else {
attorneyProvidedDetails.Confirmed = attorney.SignedAt
}

if err := attorneyStore.Put(r.Context(), attorneyProvidedDetails); err != nil {
return err
}

return page.Paths.Attorney.WhatHappensNext.Redirect(w, r, appData, attorneyProvidedDetails.LpaID)
}
}

return tmpl(w, data)
}

signTrustCorporation := func(appData page.AppData, w http.ResponseWriter, r *http.Request, attorneyProvidedDetails *actor.AttorneyProvidedDetails, lpa *lpastore.Lpa) error {
signatoryIndex := 0
if r.URL.Query().Has("second") {
signatoryIndex = 1
}

signatory := attorneyProvidedDetails.AuthorisedSignatories[signatoryIndex]

data := &signData{
App: appData,
LpaID: lpa.LpaID,
IsReplacement: appData.IsReplacementAttorney(),
IsSecondSignatory: signatoryIndex == 1,
LpaCanBeUsedWhenHasCapacity: lpa.WhenCanTheLpaBeUsed.IsHasCapacity(),
Form: &signForm{
Confirm: !attorneyProvidedDetails.Confirmed.IsZero(),
},
}

if appData.IsTrustCorporation() {
signatory := attorneyProvidedDetails.AuthorisedSignatories[signatoryIndex]

data.Form = &signForm{
FirstNames: signatory.FirstNames,
LastName: signatory.LastName,
ProfessionalTitle: signatory.ProfessionalTitle,
Confirm: !signatory.Confirmed.IsZero(),
}
},
}

if appData.IsReplacementAttorney() {
data.TrustCorporation = lpa.ReplacementAttorneys.TrustCorporation
} else {
data.TrustCorporation = lpa.Attorneys.TrustCorporation
}
if appData.IsReplacementAttorney() {
data.TrustCorporation = lpa.ReplacementAttorneys.TrustCorporation
} else {
attorneys := lpa.Attorneys
if appData.IsReplacementAttorney() {
attorneys = lpa.ReplacementAttorneys
}

attorney, ok := attorneys.Get(appData.AttorneyUID)
if !ok {
return page.Paths.Attorney.Start.Redirect(w, r, appData)
}

data.Attorney = attorney
data.TrustCorporation = lpa.Attorneys.TrustCorporation
}

if r.Method == http.MethodPost {
Expand All @@ -96,35 +116,58 @@ func Sign(
attorneyProvidedDetails.Tasks.SignTheLpa = actor.TaskCompleted
}

if appData.IsTrustCorporation() {
attorneyProvidedDetails.AuthorisedSignatories[signatoryIndex] = actor.TrustCorporationSignatory{
FirstNames: data.Form.FirstNames,
LastName: data.Form.LastName,
ProfessionalTitle: data.Form.ProfessionalTitle,
Confirmed: now(),
attorneyProvidedDetails.AuthorisedSignatories[signatoryIndex] = actor.TrustCorporationSignatory{
FirstNames: data.Form.FirstNames,
LastName: data.Form.LastName,
ProfessionalTitle: data.Form.ProfessionalTitle,
Confirmed: now(),
}

if len(data.TrustCorporation.Signatories) == 0 {
if signatoryIndex == 1 {
if err := lpaStoreClient.SendAttorney(r.Context(), lpa, attorneyProvidedDetails); err != nil {
return err
}
}
} else {
attorneyProvidedDetails.Confirmed = now()
attorneyProvidedDetails.AuthorisedSignatories[signatoryIndex].Confirmed = data.TrustCorporation.Signatories[signatoryIndex].SignedAt
}

if err := attorneyStore.Put(r.Context(), attorneyProvidedDetails); err != nil {
return err
}

if appData.IsTrustCorporation() && signatoryIndex == 0 {
if signatoryIndex == 0 {
return page.Paths.Attorney.WouldLikeSecondSignatory.Redirect(w, r, appData, attorneyProvidedDetails.LpaID)
} else {
if err := lpaStoreClient.SendAttorney(r.Context(), lpa, attorneyProvidedDetails); err != nil {
return err
}

return page.Paths.Attorney.WhatHappensNext.Redirect(w, r, appData, attorneyProvidedDetails.LpaID)
}
}
}

return tmpl(w, data)
}

return func(appData page.AppData, w http.ResponseWriter, r *http.Request, attorneyProvidedDetails *actor.AttorneyProvidedDetails) error {
if attorneyProvidedDetails.Signed() {
return page.Paths.Attorney.WhatHappensNext.Redirect(w, r, appData, attorneyProvidedDetails.LpaID)
}

lpa, err := lpaStoreResolvingService.Get(r.Context())
if err != nil {
return err
}

if lpa.SignedAt.IsZero() || lpa.CertificateProvider.SignedAt.IsZero() {
return page.Paths.Attorney.TaskList.Redirect(w, r, appData, attorneyProvidedDetails.LpaID)
}

if appData.IsTrustCorporation() {
return signTrustCorporation(appData, w, r, attorneyProvidedDetails, lpa)
} else {
return signAttorney(appData, w, r, attorneyProvidedDetails, lpa)
}
}
}

type signForm struct {
Expand Down
Loading

0 comments on commit 0edbcc7

Please sign in to comment.