/
system_intake_lcid_expiration_alert.go
127 lines (114 loc) · 3.14 KB
/
system_intake_lcid_expiration_alert.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
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 lcidExperationAlert struct {
ProjectName string
RequesterName string
LifecycleID string
LCIDIssuedAt string
ExpiresAt string
Scope template.HTML
CostBaseline string
NextSteps template.HTML
GRTEmail string
RequesterLink string
GRTLink string
}
func (c Client) lcidExpirationBody(
ctx context.Context,
systemIntakeID uuid.UUID,
projectName string,
requesterName string,
lcid string,
lcidIssuedAt *time.Time,
lcidExpirationDate *time.Time,
scope models.HTML,
lifecycleCostBaseline string,
nextSteps models.HTML,
) (string, error) {
requesterPath := path.Join("governance-task-list", systemIntakeID.String())
grtPath := path.Join("governance-review-team", systemIntakeID.String(), "lcid")
var issuedAt string
if lcidIssuedAt != nil {
issuedAt = lcidIssuedAt.Format("01/02/2006")
}
var expiresAt string
if lcidExpirationDate != nil {
expiresAt = lcidExpirationDate.Format("01/02/2006")
}
data := lcidExperationAlert{
ProjectName: projectName,
RequesterName: requesterName,
LifecycleID: lcid,
LCIDIssuedAt: issuedAt,
ExpiresAt: expiresAt,
Scope: scope.ToTemplate(),
CostBaseline: lifecycleCostBaseline,
NextSteps: nextSteps.ToTemplate(),
GRTEmail: string(c.config.GRTEmail),
RequesterLink: c.urlFromPath(requesterPath),
GRTLink: c.urlFromPath(grtPath),
}
var b bytes.Buffer
if c.templates.lcidExpirationAlertTemplate == nil {
return "", errors.New("LCID expiration alert template is nil")
}
err := c.templates.lcidExpirationAlertTemplate.Execute(&b, data)
if err != nil {
return "", err
}
return b.String(), nil
}
// SendLCIDExpirationAlertEmail sends an email to the governance mailbox notifying them about LCID that is expiring soon
func (c Client) SendLCIDExpirationAlertEmail(
ctx context.Context,
recipients models.EmailNotificationRecipients,
systemIntakeID uuid.UUID,
projectName string,
requesterName string,
lcid string,
lcidIssuedAt *time.Time,
lcidExpirationDate *time.Time,
scope models.HTML,
lifecycleCostBaseline string,
nextSteps models.HTML,
) error {
subject := fmt.Sprintf("Warning: Your Life Cycle ID (%s) for %s is about to expire", lcid, projectName)
body, err := c.lcidExpirationBody(
ctx,
systemIntakeID,
projectName,
requesterName,
lcid,
lcidIssuedAt,
lcidExpirationDate,
scope,
lifecycleCostBaseline,
nextSteps,
)
if err != nil {
return &apperrors.NotificationError{Err: err, DestinationType: apperrors.DestinationTypeEmail}
}
err = c.sender.Send(
ctx,
c.listAllRecipients(recipients),
nil, // TODO: This is nil b/c we set the ShouldNotifyITGovernance bool as true in recipients.
// This however doesn't cc the governance mailbox but sends directly to it, we should maybe allow for specification between cc'ing and sending directly?
subject,
body,
)
if err != nil {
return &apperrors.NotificationError{Err: err, DestinationType: apperrors.DestinationTypeEmail}
}
return nil
}