-
Notifications
You must be signed in to change notification settings - Fork 11
/
reject_request.go
83 lines (76 loc) · 2.06 KB
/
reject_request.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
package email
import (
"bytes"
"context"
"errors"
"html/template"
"path"
"github.com/google/uuid"
"github.com/cmsgov/easi-app/pkg/apperrors"
"github.com/cmsgov/easi-app/pkg/models"
)
type rejectRequest struct {
ProjectName string
GRTEmail string
Requester string
Reason template.HTML
NextSteps template.HTML
Feedback template.HTML
DecisionLink string
}
func (c Client) rejectRequestBody(
systemIntakeID uuid.UUID,
projectName string,
requester string,
reason models.HTML,
nextSteps models.HTML,
feedback models.HTML,
) (string, error) {
decisionPath := path.Join("governance-task-list", systemIntakeID.String(), "request-decision")
data := rejectRequest{
ProjectName: projectName,
GRTEmail: string(c.config.GRTEmail),
Requester: requester,
Reason: reason.ToTemplate(),
NextSteps: nextSteps.ToTemplate(),
Feedback: feedback.ToTemplate(),
DecisionLink: c.urlFromPath(decisionPath),
}
var b bytes.Buffer
if c.templates.rejectRequestTemplate == nil {
return "", errors.New("reject request template is nil")
}
err := c.templates.rejectRequestTemplate.Execute(&b, data)
if err != nil {
return "", err
}
return b.String(), nil
}
// SendRejectRequestEmails sends emails to multiple recipients (possibly including the IT Governance and IT Investment teams) for rejecting a request
func (c Client) SendRejectRequestEmails(
ctx context.Context,
recipients models.EmailNotificationRecipients,
systemIntakeID uuid.UUID,
projectName string,
requester string,
reason models.HTML,
nextSteps models.HTML,
feedback models.HTML,
) error {
subject := "Request in EASi not approved"
body, err := c.rejectRequestBody(systemIntakeID, projectName, requester, reason, nextSteps, feedback)
if err != nil {
return &apperrors.NotificationError{Err: err, DestinationType: apperrors.DestinationTypeEmail}
}
err = c.sender.Send(
ctx,
c.listAllRecipients(recipients),
nil,
subject,
body,
)
if err != nil {
return &apperrors.NotificationError{Err: err, DestinationType: apperrors.DestinationTypeEmail}
}
return nil
}