-
Notifications
You must be signed in to change notification settings - Fork 11
/
system_intake_close.go
99 lines (88 loc) · 2.75 KB
/
system_intake_close.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package email
import (
"bytes"
"context"
"errors"
"fmt"
"html/template"
"path"
"time"
"github.com/google/uuid"
"github.com/cmsgov/easi-app/pkg/apperrors"
"github.com/cmsgov/easi-app/pkg/models"
)
type systemIntakeCloseRequestEmailParameters struct {
RequestName string
RequesterName string
Reason template.HTML
SubmittedAt string
SystemIntakeRequestLink string
SystemIntakeAdminLink string
ITGovernanceInboxAddress string
AdditionalInfo template.HTML
}
func (sie systemIntakeEmails) closeRequestBody(
systemIntakeID uuid.UUID,
requestName string,
requesterName string,
reason *models.HTML,
submittedAt *time.Time,
additionalInfo *models.HTML,
) (string, error) {
requesterPath := path.Join("governance-task-list", systemIntakeID.String())
adminPath := path.Join("governance-review-team", systemIntakeID.String(), "intake-request")
var submissionDate string
if submittedAt != nil {
submissionDate = submittedAt.Format("01/02/2006")
}
data := systemIntakeCloseRequestEmailParameters{
RequestName: requestName,
RequesterName: requesterName,
Reason: reason.ToTemplate(),
SubmittedAt: submissionDate,
SystemIntakeRequestLink: sie.client.urlFromPath(requesterPath),
SystemIntakeAdminLink: sie.client.urlFromPath(adminPath),
ITGovernanceInboxAddress: sie.client.config.GRTEmail.String(),
AdditionalInfo: additionalInfo.ToTemplate(),
}
var b bytes.Buffer
if sie.client.templates.systemIntakeCloseRequest == nil {
return "", errors.New("close request email template is nil")
}
err := sie.client.templates.systemIntakeCloseRequest.Execute(&b, data)
if err != nil {
return "", err
}
return b.String(), nil
}
// SendCloseRequestNotification notifies user-selected recipients that a system intake form needs edits
func (sie systemIntakeEmails) SendCloseRequestNotification(
ctx context.Context,
recipients models.EmailNotificationRecipients,
systemIntakeID uuid.UUID,
requestName string,
requesterName string,
reason *models.HTML,
submittedAt *time.Time,
additionalInfo *models.HTML,
) error {
if requestName == "" {
requestName = "Draft System Intake"
}
subject := fmt.Sprintf("The Governance Team has closed %s in EASi", requestName)
body, err := sie.closeRequestBody(systemIntakeID, requestName, requesterName, reason, submittedAt, additionalInfo)
if err != nil {
return &apperrors.NotificationError{Err: err, DestinationType: apperrors.DestinationTypeEmail}
}
err = sie.client.sender.Send(
ctx,
sie.client.listAllRecipients(recipients),
nil,
subject,
body,
)
if err != nil {
return &apperrors.NotificationError{Err: err, DestinationType: apperrors.DestinationTypeEmail}
}
return nil
}