-
Notifications
You must be signed in to change notification settings - Fork 11
/
system_intake_progress_to_new_step.go
95 lines (85 loc) · 2.87 KB
/
system_intake_progress_to_new_step.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
package email
import (
"bytes"
"context"
"errors"
"fmt"
"html/template"
"path"
"github.com/google/uuid"
"github.com/cmsgov/easi-app/pkg/apperrors"
"github.com/cmsgov/easi-app/pkg/graph/model"
"github.com/cmsgov/easi-app/pkg/models"
)
type systemIntakeProgressToNewStepEmailParameters struct {
RequestName string
Step string
RequesterName string
Feedback template.HTML
SystemIntakeRequestLink string
SystemIntakeAdminLink string
ITGovernanceInboxAddress string
AdditionalInfo template.HTML
}
func (sie systemIntakeEmails) systemIntakeProgressToNewStepBody(
systemIntakeID uuid.UUID,
requestName string,
step models.SystemIntakeStep,
requesterName string,
feedback *models.HTML,
additionalInfo *models.HTML,
) (string, error) {
requesterPath := path.Join("governance-task-list", systemIntakeID.String())
adminPath := path.Join("governance-review-team", systemIntakeID.String(), "intake-request")
data := systemIntakeProgressToNewStepEmailParameters{
RequestName: requestName,
Step: HumanizeSnakeCase(string(step)),
RequesterName: requesterName,
Feedback: feedback.ToTemplate(),
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.systemIntakeProgressToNewStep == nil {
return "", errors.New("progress to new step email template is nil")
}
err := sie.client.templates.systemIntakeProgressToNewStep.Execute(&b, data)
if err != nil {
return "", err
}
return b.String(), nil
}
// SendProgressToNewStepNotification notifies user-selected recipients that a system intake form has been progressed to a new step
func (sie systemIntakeEmails) SendProgressToNewStepNotification(
ctx context.Context,
recipients models.EmailNotificationRecipients,
systemIntakeID uuid.UUID,
newStep model.SystemIntakeStepToProgressTo,
requestName string,
requesterName string,
feedback *models.HTML,
additionalInfo *models.HTML,
) error {
if requestName == "" {
requestName = "Draft System Intake"
}
step := models.SystemIntakeStep(newStep)
subject := fmt.Sprintf("%s is ready for a %s", requestName, HumanizeSnakeCase(string(step)))
body, err := sie.systemIntakeProgressToNewStepBody(systemIntakeID, requestName, step, requesterName, feedback, 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
}