Skip to content

Commit

Permalink
Merge 6dfcdf9 into f55a1e5
Browse files Browse the repository at this point in the history
  • Loading branch information
hawx authored Oct 29, 2024
2 parents f55a1e5 + 6dfcdf9 commit 988fd84
Show file tree
Hide file tree
Showing 12 changed files with 135 additions and 112 deletions.
1 change: 1 addition & 0 deletions cmd/mlpa/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ func run(ctx context.Context, logger *slog.Logger) error {
}

otelaws.AppendMiddlewares(&cfg.APIOptions)
telemetry.AppendMiddlewares(&cfg.APIOptions)

lpasDynamoClient, err := dynamo.NewClient(cfg, dynamoTableLpas)
if err != nil {
Expand Down
22 changes: 14 additions & 8 deletions cypress/e2e/attorney/read-the-lpa.cy.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
describe('Read the LPA', () => {
it('displays the LPA details with actor specific content', () => {
cy.visit('/fixtures/attorney?redirect=/read-the-lpa');
it('displays the LPA details with actor specific content', () => {
cy.visit('/fixtures/attorney?redirect=/read-the-lpa');

cy.contains('dt', "When attorneys can use the LPA")
cy.contains('dt', "Attorney names")
cy.contains('dt', "Replacement attorney names")
cy.contains('Donor: Sam Smith');
cy.contains('Certificate provider: Charlie Cooper');
cy.contains('Attorney: Jessie Jones');
cy.contains('Trust corporation attorney: First Choice Trust Corporation Ltd.');
cy.contains('Replacement attorney: Blake Buckley');
cy.contains('Replacement trust corporation attorney: Second Choice Trust Corporation Ltd.');
cy.contains('Signed by Sam Smith on: 2 January 2023');
cy.contains('Witnessed by Charlie Cooper on: 2 January 2023');
cy.contains('Signed by Charlie Cooper on: 2 January 2023');

cy.contains('Continue').click();
cy.contains('Continue').click();

cy.url().should('contain', '/task-list');
});
cy.url().should('contain', '/task-list');
});
});
22 changes: 13 additions & 9 deletions cypress/e2e/certificate-provider/read-the-lpa.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ describe('Read the LPA', () => {
it('displays the LPA details and goes to provide certificate', () => {
cy.checkA11yApp();

cy.contains('dt', "When attorneys can use the LPA")
cy.contains('dt', "Their attorneys")
cy.contains('dt', "Their replacement attorneys")
cy.contains('Donor: Sam Smith');
cy.contains('Certificate provider: Charlie Cooper');
cy.contains('Attorney: Jessie Jones');
cy.contains('Attorney: Robin Redcar');
cy.contains('Signed by Sam Smith on: 2 January 2023');
cy.contains('Witnessed by Charlie Cooper on: 2 January 2023');

cy.contains('Continue').click();
cy.contains('button', 'Continue').click();
cy.url().should('contain', '/what-happens-next');
});
});
Expand All @@ -24,12 +27,13 @@ describe('Read the LPA', () => {
it('displays the LPA details and goes to task list', () => {
cy.checkA11yApp();

cy.contains('dt', "When attorneys can use the LPA")
cy.contains('dt', "Their attorneys")
cy.contains('dt', "Their replacement attorneys")
cy.contains('Donor: Sam Smith');
cy.contains('Certificate provider: Charlie Cooper');
cy.contains('Attorney: Jessie Jones');
cy.contains('Attorney: Robin Redcar');

cy.get('button').should('not.contain', 'Continue');
cy.contains('Return to task list').click();
cy.contains('button', 'Continue').should('not.exist');
cy.contains('a', 'Return to task list').click();
cy.url().should('contain', '/task-list');
});
});
Expand Down
8 changes: 0 additions & 8 deletions internal/event/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import (
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/eventbridge"
"github.com/aws/aws-sdk-go-v2/service/eventbridge/types"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/trace"
)

const source = "opg.poas.makeregister"
Expand Down Expand Up @@ -90,12 +88,6 @@ func send[T any](ctx context.Context, c *Client, detail any) error {
return errors.New("event send of unknown type")
}

tracer := otel.GetTracerProvider().Tracer("mlpab")
ctx, span := tracer.Start(ctx, detailType,
trace.WithSpanKind(trace.SpanKindInternal),
)
defer span.End()

v, err := json.Marshal(detail)
if err != nil {
return err
Expand Down
5 changes: 3 additions & 2 deletions internal/page/fixtures/attorney.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ func Attorney(
attorneyCtx = appcontext.ContextWithSession(r.Context(), &appcontext.Session{SessionID: attorneySessionID, LpaID: donorDetails.LpaID})
)

donorDetails.SignedAt = time.Now()
donorDetails.WitnessedByCertificateProviderAt = time.Now()
donorDetails.SignedAt = time.Date(2023, time.January, 2, 3, 4, 5, 6, time.UTC)
donorDetails.WitnessedByCertificateProviderAt = time.Date(2023, time.January, 2, 3, 4, 5, 6, time.UTC)
donorDetails.Donor = makeDonor(testEmail)

if lpaType == "personal-welfare" && !isTrustCorporation {
Expand Down Expand Up @@ -221,6 +221,7 @@ func Attorney(
}

certificateProvider.ContactLanguagePreference = localize.En
certificateProvider.SignedAt = time.Date(2023, time.January, 2, 3, 4, 5, 6, time.UTC)

attorney, err := createAttorney(
attorneyCtx,
Expand Down
4 changes: 2 additions & 2 deletions internal/page/fixtures/certificate_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ func CertificateProvider(

if progress >= slices.Index(progressValues, "signedByDonor") {
donorDetails.Tasks.ConfirmYourIdentityAndSign = task.IdentityStateCompleted
donorDetails.WitnessedByCertificateProviderAt = time.Now()
donorDetails.SignedAt = time.Now()
donorDetails.SignedAt = time.Date(2023, time.January, 2, 3, 4, 5, 6, time.UTC)
donorDetails.WitnessedByCertificateProviderAt = time.Date(2023, time.January, 2, 3, 4, 5, 6, time.UTC)
}

if progress >= slices.Index(progressValues, "confirmYourDetails") {
Expand Down
32 changes: 32 additions & 0 deletions internal/telemetry/middleware.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package telemetry

import (
"context"

"github.com/aws/aws-sdk-go-v2/service/eventbridge"
"github.com/aws/smithy-go/middleware"
"go.opentelemetry.io/otel/attribute"
semconv "go.opentelemetry.io/otel/semconv/v1.17.0"
"go.opentelemetry.io/otel/trace"
)

func AppendMiddlewares(list *[]func(*middleware.Stack) error) {
*list = append(*list, func(stack *middleware.Stack) error {
return stack.Initialize.Add(middleware.InitializeMiddlewareFunc("appInitializeMiddlewareAfter",
func(ctx context.Context, in middleware.InitializeInput, next middleware.InitializeHandler) (middleware.InitializeOutput, middleware.Metadata, error) {
span := trace.SpanFromContext(ctx)

switch v := in.Parameters.(type) {
case *eventbridge.PutEventsInput:
if len(v.Entries) == 1 {
span.SetAttributes(attribute.String("aws.operation", "PutEvents "+*v.Entries[0].DetailType))
span.SetAttributes(semconv.CloudeventsEventSource(*v.Entries[0].Source))
span.SetAttributes(semconv.CloudeventsEventType(*v.Entries[0].DetailType))
}
}

return next.HandleInitialize(ctx, in)
},
), middleware.After)
})
}
48 changes: 48 additions & 0 deletions internal/telemetry/slog.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package telemetry

import (
"context"
"log/slog"

"github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext"
"go.opentelemetry.io/otel/trace"
)

type SlogHandler struct {
handler slog.Handler
}

func NewSlogHandler(h slog.Handler) slog.Handler {
return &SlogHandler{handler: h}
}

func (h *SlogHandler) Enabled(ctx context.Context, level slog.Level) bool {
return h.handler.Enabled(ctx, level)
}

func (h *SlogHandler) Handle(ctx context.Context, record slog.Record) error {
spanCtx := trace.SpanContextFromContext(ctx)
if spanCtx.HasTraceID() {
traceID := spanCtx.TraceID()
record.AddAttrs(slog.String("trace_id", traceID.String()))
}

session, err := appcontext.SessionFromContext(ctx)
if err == nil {
record.AddAttrs(slog.String("session_id", session.SessionID))

if session.OrganisationID != "" {
record.AddAttrs(slog.String("organisation_id", session.OrganisationID))
}
}

return h.handler.Handle(ctx, record)
}

func (h *SlogHandler) WithAttrs(attrs []slog.Attr) slog.Handler {
return NewSlogHandler(h.handler.WithAttrs(attrs))
}

func (h *SlogHandler) WithGroup(name string) slog.Handler {
return NewSlogHandler(h.handler.WithGroup(name))
}
File renamed without changes.
41 changes: 0 additions & 41 deletions internal/telemetry/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ package telemetry
import (
"context"
"fmt"
"log/slog"
"net/http"
"strings"

"github.com/felixge/httpsnoop"
"github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext"
"go.opentelemetry.io/contrib/propagators/aws/xray"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
Expand Down Expand Up @@ -77,42 +75,3 @@ func WrapHandler(handler http.Handler) http.HandlerFunc {
span.SetAttributes(semconv.HTTPResponseContentLengthKey.Int64(m.Written))
}
}

type SlogHandler struct {
handler slog.Handler
}

func NewSlogHandler(h slog.Handler) slog.Handler {
return &SlogHandler{handler: h}
}

func (h *SlogHandler) Enabled(ctx context.Context, level slog.Level) bool {
return h.handler.Enabled(ctx, level)
}

func (h *SlogHandler) Handle(ctx context.Context, record slog.Record) error {
spanCtx := trace.SpanContextFromContext(ctx)
if spanCtx.HasTraceID() {
traceID := spanCtx.TraceID()
record.AddAttrs(slog.String("trace_id", traceID.String()))
}

session, err := appcontext.SessionFromContext(ctx)
if err == nil {
record.AddAttrs(slog.String("session_id", session.SessionID))

if session.OrganisationID != "" {
record.AddAttrs(slog.String("organisation_id", session.OrganisationID))
}
}

return h.handler.Handle(ctx, record)
}

func (h *SlogHandler) WithAttrs(attrs []slog.Attr) slog.Handler {
return NewSlogHandler(h.handler.WithAttrs(attrs))
}

func (h *SlogHandler) WithGroup(name string) slog.Handler {
return NewSlogHandler(h.handler.WithGroup(name))
}
12 changes: 1 addition & 11 deletions web/template/attorney/read_the_lpa.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,7 @@

{{ template "warning" (content .App "youMustReadLpaCarefully") }}

<h2 id="decisions" class="govuk-heading-l govuk-!-margin-bottom-2">
{{ tr .App "lpaDecisions" }}
</h2>

{{ template "lpa-decisions" (lpaDecisions .App .Lpa false) }}

<h2 class="govuk-heading-l govuk-!-margin-bottom-2">
{{ tr .App "peopleNamedOnTheLpa" }}
</h2>

{{ template "people-named-on-lpa" (lpaDecisions .App .Lpa false) }}
{{ template "contextual-lpa" . }}

<form novalidate method="post">
{{ template "continue-button" . }}
Expand Down
52 changes: 21 additions & 31 deletions web/template/certificateprovider/read_the_lpa.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,27 @@
{{ define "pageTitle" }}{{ trFormat .App "readDonorNameLpa" "DonorFullName" .Lpa.Donor.FullName }}{{ end }}

{{ define "main" }}
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<h1 class="govuk-heading-xl">{{ trFormat .App "readDonorNameLpa" "DonorFullName" .Lpa.Donor.FullName }}</h1>

{{ if and .App.IsCertificateProvider .Lpa.SignedAt.IsZero }}
{{ template "warning" (content .App "youShouldReadLpaCarefully") }}
{{ else }}
{{ template "warning" (content .App "youMustReadLpaCarefully") }}
{{ end }}

<h2 id="decisions" class="govuk-heading-l govuk-!-margin-bottom-2">
{{ tr .App "lpaDecisions" }}
</h2>

{{ template "lpa-decisions" (lpaDecisions .App .Lpa false) }}

<h2 class="govuk-heading-l govuk-!-margin-bottom-2">
{{ tr .App "peopleNamedOnTheLpa" }}
</h2>

{{ template "people-named-on-lpa" (lpaDecisions .App .Lpa false) }}

<form novalidate method="post">
<div class="govuk-button-group">
{{ if not .Lpa.SignedAt.IsZero }}
{{ template "continue-button" . }}
{{ end }}
<a href="{{ link .App (global.Paths.CertificateProvider.TaskList.Format .App.LpaID) }}" class="govuk-button {{ if not .Lpa.SignedAt.IsZero }}govuk-button--secondary{{ end }}">{{ tr .App "returnToTaskList" }}</a>
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<h1 class="govuk-heading-xl">{{ trFormat .App "readDonorNameLpa" "DonorFullName" .Lpa.Donor.FullName }}</h1>

{{ if and .App.IsCertificateProvider .Lpa.SignedAt.IsZero }}
{{ template "warning" (content .App "youShouldReadLpaCarefully") }}
{{ else }}
{{ template "warning" (content .App "youMustReadLpaCarefully") }}
{{ end }}

{{ template "contextual-lpa" . }}

<form novalidate method="post">
{{ if .Lpa.SignedAt.IsZero }}
{{ template "button" (button .App "returnToTaskList" "link" (global.Paths.CertificateProvider.TaskList.Format .App.LpaID)) }}
{{ else }}
{{ template "buttons" (button .App "continue") }}
{{ end }}

{{ template "csrf-field" . }}
</form>
</div>
{{ template "csrf-field" . }}
</form>
</div>
</div>
{{ end }}

0 comments on commit 988fd84

Please sign in to comment.