Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EASI-4529] notification emails #2947

Open
wants to merge 12 commits into
base: feature/EASI-4521_grb_presentation_links
Choose a base branch
from
12 changes: 12 additions & 0 deletions cmd/test_email_templates/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -723,4 +723,16 @@ func sendITGovEmails(ctx context.Context, client *email.Client) {
},
)
noErr(err)

err = client.SystemIntake.SendGRBReviewPresentationLinksUpdatedEmail(
ctx,
email.SendGRBReviewPresentationLinksUpdatedEmailInput{
SystemIntakeID: intakeID,
ProjectName: "Project with Presentation",
RequesterName: "Nobody",
RequesterComponent: "ABCD",
Recipients: emailNotificationRecipients.RegularRecipientEmails,
},
)
noErr(err)
}
8 changes: 8 additions & 0 deletions pkg/email/email.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ type templates struct {
grbReviewDiscussionReply templateCaller
grbReviewDiscussionIndividualTagged templateCaller
grbReviewDiscussionGroupTagged templateCaller
grbReviewPresentationLinksUpdated templateCaller
}

// sender is an interface for swapping out email provider implementations
Expand Down Expand Up @@ -429,6 +430,13 @@ func NewClient(config Config, sender sender) (Client, error) {
}
appTemplates.grbReviewDiscussionGroupTagged = grbReviewDiscussionGroupTagged

grbReviewPresentationLinksUpdatedTemplateName := "grb_review_presentation_links_updated.gohtml"
grbReviewPresentationLinksUpdated := rawTemplates.Lookup(grbReviewPresentationLinksUpdatedTemplateName)
if grbReviewPresentationLinksUpdated == nil {
return Client{}, templateError(grbReviewPresentationLinksUpdatedTemplateName)
}
appTemplates.grbReviewPresentationLinksUpdated = grbReviewPresentationLinksUpdated

client := Client{
config: config,
templates: appTemplates,
Expand Down
2 changes: 1 addition & 1 deletion pkg/email/grb_review_discussion_group_tagged.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type GRBReviewDiscussionGroupTaggedBody struct {

func (sie systemIntakeEmails) grbReviewDiscussionGroupTaggedBody(input SendGRBReviewDiscussionGroupTaggedEmailInput) (string, error) {
if sie.client.templates.grbReviewDiscussionGroupTagged == nil {
return "", errors.New("grb review discussion reply template is nil")
return "", errors.New("grb review discussion group tagged template is nil")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed err msg

}

grbReviewPath := path.Join("it-governance", input.SystemIntakeID.String(), "grb-review")
Expand Down
2 changes: 1 addition & 1 deletion pkg/email/grb_review_discussion_individual_tagged.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type GRBReviewDiscussionIndividualTaggedBody struct {

func (sie systemIntakeEmails) grbReviewDiscussionIndividualTaggedBody(input SendGRBReviewDiscussionIndividualTaggedEmailInput) (string, error) {
if sie.client.templates.grbReviewDiscussionIndividualTagged == nil {
return "", errors.New("grb review discussion reply template is nil")
return "", errors.New("grb review discussion individual tagged template is nil")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed err msg

}

grbReviewPath := path.Join("it-governance", input.SystemIntakeID.String(), "grb-review")
Expand Down
70 changes: 70 additions & 0 deletions pkg/email/grb_review_presentation_links_updated.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package email

import (
"bytes"
"context"
"errors"
"fmt"
"path"

"github.com/google/uuid"

"github.com/cms-enterprise/easi-app/pkg/models"
)

type SendGRBReviewPresentationLinksUpdatedEmailInput struct {
SystemIntakeID uuid.UUID
ProjectName string
RequesterName string
RequesterComponent string
Recipients []models.EmailAddress
}

type grbReviewPresentationLinksUpdatedBody struct {
ProjectName string
RequesterName string
RequesterComponent string
SystemIntakeLink string
ITGovernanceInboxAddress models.EmailAddress
}

func (sie systemIntakeEmails) grbReviewPresentationLinksUpdatedBody(input SendGRBReviewPresentationLinksUpdatedEmailInput) (string, error) {
if sie.client.templates.grbReviewPresentationLinksUpdated == nil {
return "", errors.New("grb review presentation links updated template is nil")
}

grbReviewPath := path.Join("it-governance", input.SystemIntakeID.String(), "grb-review")

data := grbReviewPresentationLinksUpdatedBody{
ProjectName: input.ProjectName,
SystemIntakeLink: sie.client.urlFromPath(grbReviewPath),
RequesterName: input.RequesterName,
RequesterComponent: input.RequesterComponent,
ITGovernanceInboxAddress: sie.client.config.GRTEmail,
}

var b bytes.Buffer
if err := sie.client.templates.grbReviewPresentationLinksUpdated.Execute(&b, data); err != nil {
return "", err
}

return b.String(), nil
}

func (sie systemIntakeEmails) SendGRBReviewPresentationLinksUpdatedEmail(ctx context.Context, input SendGRBReviewPresentationLinksUpdatedEmailInput) error {
subject := fmt.Sprintf("Presentation links updated on the GRB review for %s", input.ProjectName)

body, err := sie.grbReviewPresentationLinksUpdatedBody(input)
if err != nil {
return err
}

return sie.client.sender.Send(
ctx,
NewEmail().
WithToAddresses(input.Recipients).
WithCCAddresses([]models.EmailAddress{sie.client.config.GRTEmail}).
WithSubject(subject).
WithBody(body),
)
}
76 changes: 76 additions & 0 deletions pkg/email/grb_review_presentation_links_updated_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package email

import (
"context"
"fmt"
"path"

"github.com/google/uuid"

"github.com/cms-enterprise/easi-app/pkg/models"
)

func (s *EmailTestSuite) TestSendGRBReviewPresentationLinksUpdatedEmail() {
ctx := context.Background()
intakeID := uuid.MustParse("24dd7736-e4c2-4f67-8844-51187de49069")
requestName := "Presentation Links"
requester := "Nobody"
requesterComponent := "ABCD"
recipients := []models.EmailAddress{"someone@cms.gov"}

sender := mockSender{}
client, err := NewClient(s.config, &sender)
s.NoError(err)

err = client.SystemIntake.SendGRBReviewPresentationLinksUpdatedEmail(
ctx,
SendGRBReviewPresentationLinksUpdatedEmailInput{
SystemIntakeID: intakeID,
ProjectName: requestName,
RequesterName: requester,
RequesterComponent: requesterComponent,
Recipients: recipients,
},
)
s.NoError(err)

expectedSubject := fmt.Sprintf("Presentation links updated on the GRB review for %s", requestName)
s.Equal(expectedSubject, sender.subject)

s.ElementsMatch(sender.toAddresses, recipients)
s.ElementsMatch(sender.ccAddresses, []models.EmailAddress{s.config.GRTEmail})

intakePath := path.Join("it-governance", intakeID.String(), "grb-review")

grbReviewLink := client.urlFromPath(intakePath)

expectedEmail := fmt.Sprintf(`
<h1 class="header-title">EASi</h1>
<p class="header-subtitle">Easy Access to System Information</p>

<p>The Governance Admin Team has updated the presentation recording links on the GRB review for %[1]s. You
may view the recording and/or slide deck using the link below.</p>

<p><strong><a href="%[2]s">View this request in EASi</a></strong></p>

<br>
<div class="no-margin">
<p><strong>Request summary:</strong></p>
<p><strong>Project title:</strong> %[1]s</p>
<p><strong>Requester:</strong> %[3]s, %[4]s</p>
</div>

<br>
<p>If you have questions, please contact the Governance Team at <a
href="mailto:%[5]s">%[5]s</a>.</p>
<hr>
<p>You will continue to receive email notifications about this request until it is closed.</p>`,
requestName,
grbReviewLink,
requester,
requesterComponent,
s.config.GRTEmail.String(),
)

s.EqualHTML(expectedEmail, sender.body)
}
8 changes: 4 additions & 4 deletions pkg/email/system_intake_admin_upload_doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ type systemIntakeAdminUploadDocBody struct {
}

func (sie systemIntakeEmails) systemIntakeAdminUploadDocBody(input SendSystemIntakeAdminUploadDocEmailInput) (string, error) {
if sie.client.templates.systemIntakeAdminUploadDocTemplate == nil {
return "", errors.New("system intake admin upload doc template is nil")
}

link := path.Join("it-governance", input.SystemIntakeID.String(), "grb-review")

data := systemIntakeAdminUploadDocBody{
Expand All @@ -39,10 +43,6 @@ func (sie systemIntakeEmails) systemIntakeAdminUploadDocBody(input SendSystemInt
ITGovernanceInboxAddress: sie.client.config.GRTEmail.String(),
}

if sie.client.templates.systemIntakeAdminUploadDocTemplate == nil {
return "", errors.New("system intake admin upload doc template is nil")
}

var b bytes.Buffer
if err := sie.client.templates.systemIntakeAdminUploadDocTemplate.Execute(&b, data); err != nil {
return "", err
Expand Down
3 changes: 1 addition & 2 deletions pkg/email/system_intake_admin_upload_doc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (s *EmailTestSuite) TestSendSystemIntakeAdminUploadDocEmail() {

<br>
<div class="no-margin">
<p><u>Request Summary</u></p>
<p><strong>Request summary:</strong></p>
<p><strong>Project title:</strong> %[1]s</p>
<p><strong>Requester:</strong> %[3]s, %[4]s
</p>
Expand All @@ -49,7 +49,6 @@ func (s *EmailTestSuite) TestSendSystemIntakeAdminUploadDocEmail() {
<br>
<p>If you have questions, please contact the Governance Team at <a
href="mailto:%[5]s">%[5]s</a>.</p>
<br>
<hr>
<p>You will continue to receive email notifications about your request until it is closed.</p>`,
requestName,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{{template "easi_header.gohtml"}}

<p>The Governance Admin Team has updated the presentation recording links on the GRB review for {{.ProjectName}}. You
may view the recording and/or slide deck using the link below.</p>

<p><strong><a href="{{.SystemIntakeLink}}">View this request in EASi</a></strong></p>

<br>
<div class="no-margin">
<p><strong>Request summary:</strong></p>
<p><strong>Project title:</strong> {{.ProjectName}}</p>
<p><strong>Requester:</strong> {{.RequesterName}}, {{.RequesterComponent}}</p>
</div>

<br>
<p>If you have questions, please contact the Governance Team at <a
href="mailto:{{.ITGovernanceInboxAddress}}">{{.ITGovernanceInboxAddress}}</a>.</p>
<hr>
<p>You will continue to receive email notifications about this request until it is closed.</p>
3 changes: 1 addition & 2 deletions pkg/email/templates/system_intake_admin_upload_doc.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<br>
<div class="no-margin">
<p><u>Request Summary</u></p>
<p><strong>Request summary:</strong></p>
<p><strong>Project title:</strong> {{.RequestName}}</p>
<p><strong>Requester:</strong> {{.RequesterName}}, {{.RequestComponent}}</p>
</div>
Expand All @@ -17,6 +17,5 @@
<br>
<p>If you have questions, please contact the Governance Team at <a
href="mailto:{{.ITGovernanceInboxAddress}}">{{.ITGovernanceInboxAddress}}</a>.</p>
<br>
<hr>
<p>You will continue to receive email notifications about your request until it is closed.</p>
Loading