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-2713] Email Notification on Model Plan Dates Changed - Updates to Include All Fields #651

Merged
merged 71 commits into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
01e35fa
feat: add ams model id and other fields to general characteristics
OddTomBrooks Jun 6, 2023
89fb650
Merge branch 'main' into EASI-2899/backend_add_demo_code_other_fields
OddTomBrooks Jun 8, 2023
57845e4
chore: migrated model abbreviation to model plan
OddTomBrooks Jun 8, 2023
a8c14f8
Merge branch 'EASI-2899/backend_add_demo_code_other_fields' of github…
OddTomBrooks Jun 8, 2023
4906c1d
chore: add role to plan discussion, begin updating store queries
OddTomBrooks Jun 13, 2023
e5e51bd
feat: updated sql to include role
OddTomBrooks Jun 14, 2023
4a5fb01
chore: updated user_role naming to be consistent, fix: most recent di…
OddTomBrooks Jun 15, 2023
153a976
chore: updated postman collection
OddTomBrooks Jun 15, 2023
c503598
Merge branch 'main' into EASI-3000/read_view_users_contribute_discuss…
OddTomBrooks Jun 20, 2023
da4c803
Merge branch 'main' into EASI-3000/read_view_users_contribute_discuss…
OddTomBrooks Jun 20, 2023
1292e35
chore: cleaned up old migration
OddTomBrooks Jun 20, 2023
79db26c
Merge branch 'EASI-3000/read_view_users_contribute_discussions' of gi…
OddTomBrooks Jun 20, 2023
66166ac
chore: removed testing code
OddTomBrooks Jun 20, 2023
12e80e7
chore: removed old ghost code from branch-off
OddTomBrooks Jun 20, 2023
acee4e3
chore: go mod tidy
OddTomBrooks Jun 20, 2023
94a1407
fix: updated inputs to fix broken tests
OddTomBrooks Jun 20, 2023
006d23f
fix: added user role to plan discussion test inputs
OddTomBrooks Jun 20, 2023
d875313
chore: updated postman collection
OddTomBrooks Jun 20, 2023
15bfc75
Merge branch 'main' into EASI-3000/read_view_users_contribute_discuss…
OddTomBrooks Jun 20, 2023
9da9c95
feat: added user role description to plan discussion with constraints…
OddTomBrooks Jun 22, 2023
ce34d86
Merge branch 'EASI-3000/read_view_users_contribute_discussions' of gi…
OddTomBrooks Jun 22, 2023
2abfd1f
wip: email notifications when model plan dates change
OddTomBrooks Jun 26, 2023
a08fcd6
fix: reverted file to main version
OddTomBrooks Jun 26, 2023
2dda5fc
chore: removed debug print code
OddTomBrooks Jun 26, 2023
7525899
chore: fix sql constraints, remove trigger
OddTomBrooks Jun 26, 2023
dc6c7f8
wip: bug fixes and refactoring
OddTomBrooks Jun 27, 2023
4d278f0
fix: added userRole and userRoleDiscussion to discussion replies, imp…
OddTomBrooks Jun 27, 2023
f62fa35
fix: server tests relating to discussion reply create input
OddTomBrooks Jun 27, 2023
ede9da7
chore: simplified email recipients table, added email recipient seeding
OddTomBrooks Jun 27, 2023
01b9f47
Merge branch 'EASI-3000/read_view_users_contribute_discussions' into …
OddTomBrooks Jun 27, 2023
d7a0e4c
chore: fixed broken unit test
OddTomBrooks Jun 27, 2023
5e0d386
fix: resolved broken unit test
OddTomBrooks Jun 28, 2023
0f241df
Merge branch 'main' into EASI-2713/email_notif_on_model_plan_dates_ch…
OddTomBrooks Jun 28, 2023
e8d6236
Merge branch 'main' into EASI-2713/email_notif_on_model_plan_dates_ch…
OddTomBrooks Jun 30, 2023
a8c9134
chore: simplified some unnecessary code
OddTomBrooks Jul 3, 2023
75d69a7
Merge branch 'EASI-2713/email_notif_on_model_plan_dates_changed' of g…
OddTomBrooks Jul 3, 2023
9d680dd
Merge branch 'EASI-2713/email_notif_on_model_plan_dates_changed' of g…
OddTomBrooks Jul 3, 2023
6169391
Merge branch 'main' into EASI-2713/email_notif_on_model_plan_dates_ch…
OddTomBrooks Jul 5, 2023
36c9b40
chore: cleaned up migrations from merging features
OddTomBrooks Jul 5, 2023
8f8e8f3
Merge branch 'main' into EASI-2713/email_notif_on_model_plan_dates_ch…
OddTomBrooks Jul 5, 2023
af33245
chore: migrated date changed recipient emails to envrc as we don't ha…
OddTomBrooks Jul 6, 2023
da8f087
Merge branch 'EASI-2713/email_notif_on_model_plan_dates_changed' of g…
OddTomBrooks Jul 6, 2023
c206873
Merge branch 'main' into EASI-2713/email_notif_on_model_plan_dates_ch…
OddTomBrooks Jul 6, 2023
5379575
chore: removed ghost code
OddTomBrooks Jul 12, 2023
a4d543c
chore: added checkDateFieldChanged documentation
OddTomBrooks Jul 12, 2023
b5891f6
wip: design changes to simplify model plan date changes email
OddTomBrooks Jul 17, 2023
6a637bd
fix: composing date ranges into common key structs
OddTomBrooks Jul 17, 2023
ffe85dc
chore: several major bugs resolved regarding email date changes
OddTomBrooks Jul 17, 2023
986805b
chore: updated unit tests
OddTomBrooks Jul 18, 2023
63a3368
Merge branch 'main' into EASI-2713/email_notif_on_model_plan_dates_ch…
OddTomBrooks Jul 18, 2023
47aa771
chore: removed debug print and updated gomod
OddTomBrooks Jul 18, 2023
62ea129
Merge branch 'EASI-2713/email_notif_on_model_plan_dates_changed' of g…
OddTomBrooks Jul 18, 2023
95e446a
chore: removed gomod change
OddTomBrooks Jul 18, 2023
8582665
chore: simplified template and removed unnecessary data structure sim…
OddTomBrooks Jul 19, 2023
f530c75
Merge branch 'main' into EASI-2713/email_notif_on_model_plan_dates_ch…
OddTomBrooks Jul 19, 2023
81601cc
chore: restructured code and removed debug print statements
OddTomBrooks Jul 19, 2023
c80e5d9
Merge branch 'EASI-2713/email_notif_on_model_plan_dates_changed' of g…
OddTomBrooks Jul 19, 2023
d408bd4
fix: date change evaluation bugs
OddTomBrooks Jul 20, 2023
dc19e69
Merge branch 'main' into EASI-2713/email_notif_on_model_plan_dates_ch…
ClayBenson94 Jul 20, 2023
310882d
chore: removed print statements, added test coverage TODOs
OddTomBrooks Jul 20, 2023
2f0a89d
Merge branch 'EASI-2713/email_notif_on_model_plan_dates_changed' of g…
OddTomBrooks Jul 20, 2023
7c958bc
chore: added test coverage to plan_basics_helper
OddTomBrooks Jul 20, 2023
d14c9e1
Merge branch 'main' into EASI-2713/email_notif_on_model_plan_dates_ch…
OddTomBrooks Jul 20, 2023
13cdbb1
Added 'copytime' to non-range fields to prevent pointer updates from …
ClayBenson94 Jul 21, 2023
de879ea
chore: added all fields to date change email output
OddTomBrooks Jul 25, 2023
9b518c1
chore: added all fields to date change email output
OddTomBrooks Jul 25, 2023
7314a48
chore: updated unit tests
OddTomBrooks Jul 25, 2023
661991b
Merge branch 'main' into EASI-2713/email_notif_on_model_plan_dates_ch…
OddTomBrooks Jul 25, 2023
a9efe97
chore: removed debug prints
OddTomBrooks Jul 25, 2023
a87833f
bug: fix for 01/01/0001 date results in emails
OddTomBrooks Jul 26, 2023
762d447
Merge branch 'main' into EASI-2713/email_notif_on_model_plan_dates_ch…
OddTomBrooks Aug 1, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/email/model_plan_date_changed.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type ModelPlanDateChangedSubjectContent struct {
// DateChange defines the parameters necessary for parsing date changes, both singular and ranges
// If the OldRange and NewRange are both nil, then the change is singular
type DateChange struct {
IsChanged bool
Field string
IsRange bool
OldDate, NewDate *time.Time
Expand Down
39 changes: 19 additions & 20 deletions pkg/email/templates/model_plan_date_changed_body.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,39 +85,38 @@ <h2 style="padding-top: 14pt;">Dates updated for {{.ModelName}}</h2>
<br/>
<br/>
<h3>Anticipated high level timeline</h3>
<br />

{{define "oldDate"}}
{{if .}}
{{.Format "01/02/2006"}}
{{else}}
no date entered
{{end}}
{{end}}
<br/>

{{define "newDate"}}
{{define "date"}}
{{if .}}
{{.Format "01/02/2006"}}
{{else}}
no date entered
<i>no date entered</i>
{{end}}
{{end}}

{{range .DateChanges}}
<p>
<b>{{.Field}}:</b>
<br />
<br/>
{{if .IsRange}}
<span style="color: red; text-decoration: line-through;">
{{template "oldDate" .OldRangeStart}} - {{template "oldDate" .OldRangeEnd}}<br/>
</span>
{{template "newDate" .NewRangeStart}} - {{template "newDate" .NewRangeEnd}}
{{if .IsChanged}}
<span style="color: #D54309; text-decoration: line-through;">
{{template "date" .OldRangeStart}} - {{template "date" .OldRangeEnd}}<br/>
</span>
{{template "date" .NewRangeStart}} - {{template "date" .NewRangeEnd}}
{{else}}
{{template "date" .OldRangeStart}} - {{template "date" .OldRangeEnd}}
{{end}}
{{else}}
<span style="color: red; text-decoration: line-through;">{{template "oldDate" .OldDate}}</span><br/>
{{template "newDate" .NewDate}}
{{if .IsChanged}}
<span style="color: #D54309; text-decoration: line-through;">{{template "date" .OldDate}}</span> - {{template "date" .NewDate}}
{{else}}
{{template "date" .OldDate}}
{{end}}
{{end}}
<br />
<br />
<br/>
<br/>
</p>
{{end}}

Expand Down
25 changes: 23 additions & 2 deletions pkg/graph/resolvers/plan_basics.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package resolvers

import (
"context"
"time"

"github.com/cmsgov/mint-app/pkg/email"
"github.com/cmsgov/mint-app/pkg/shared/oddmail"
Expand Down Expand Up @@ -118,6 +119,14 @@ func extractChangedDates(changes map[string]interface{}, existing *models.PlanBa
return dateChanges, nil
}

func sanitizeZeroDate(date *time.Time) *time.Time {
if date == nil || (date != nil && date.IsZero()) {
return nil
}

return date
}

func sendDateChangedEmails(
emailService oddmail.EmailService,
emailTemplateService email.TemplateService,
Expand All @@ -138,8 +147,20 @@ func sendDateChangedEmails(
}

dateChangeSlice := make([]email.DateChange, 0, len(dateChanges))
for _, v := range dateChanges {
dateChangeSlice = append(dateChangeSlice, v)

// Loop over the field data map to ensure order of the date changes in the email
orderedCommonKeys := getOrderedCommonKeys()
for _, commonKey := range orderedCommonKeys {
dateChange := dateChanges[commonKey]

dateChange.OldDate = sanitizeZeroDate(dateChange.OldDate)
dateChange.NewDate = sanitizeZeroDate(dateChange.NewDate)
dateChange.OldRangeStart = sanitizeZeroDate(dateChange.OldRangeStart)
dateChange.NewRangeStart = sanitizeZeroDate(dateChange.NewRangeStart)
dateChange.OldRangeEnd = sanitizeZeroDate(dateChange.OldRangeEnd)
dateChange.NewRangeEnd = sanitizeZeroDate(dateChange.NewRangeEnd)

dateChangeSlice = append(dateChangeSlice, dateChange)
}

emailBody, err := emailTemplate.GetExecutedBody(email.ModelPlanDateChangedBodyContent{
Expand Down
70 changes: 63 additions & 7 deletions pkg/graph/resolvers/plan_basics_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ func (dp *DateProcessor) ExtractChangedDates() (map[string]email.DateChange, err
dateChanges := make(map[string]email.DateChange)

for fieldKey, fieldData := range fieldDataMap {

isFieldChanged, oldValue, newValue := dp.checkDateFieldChanged(fieldKey)
if isFieldChanged {
if fieldData.IsRange { // check if the field is a range
Expand All @@ -74,8 +73,9 @@ func (dp *DateProcessor) ExtractChangedDates() (map[string]email.DateChange, err
}

dateChangeValue := &email.DateChange{
Field: fieldData.HumanReadableName,
IsRange: true,
IsChanged: true,
Field: fieldData.HumanReadableName,
IsRange: true,
}

// Determine the values for the other end of the range
Expand Down Expand Up @@ -126,12 +126,54 @@ func (dp *DateProcessor) ExtractChangedDates() (map[string]email.DateChange, err
dateChanges[fieldData.CommonKey] = *dateChangeValue
} else {
dateChanges[fieldKey] = email.DateChange{
Field: fieldData.HumanReadableName,
IsRange: false,
OldDate: copyTime(oldValue),
NewDate: copyTime(newValue),
IsChanged: true,
Field: fieldData.HumanReadableName,
IsRange: false,
OldDate: copyTime(oldValue),
NewDate: copyTime(newValue),
}
}
}
}

if len(dateChanges) == 0 {
return dateChanges, nil
}

for fieldKey, fieldData := range fieldDataMap {
if _, isChanged := dateChanges[fieldData.CommonKey]; !isChanged {
// Only handle start of range in range dates to simplify logic
if fieldData.IsRange && !fieldData.IsRangeStart {
continue
}

dateChange := email.DateChange{
IsChanged: false,
Field: fieldData.HumanReadableName,
IsRange: fieldData.IsRange,
}

if fieldData.IsRange {
if dp.existing[fieldKey] != nil {
dateChange.OldRangeStart = copyTime(dp.existing[fieldKey].(*time.Time))
} else {
dateChange.OldRangeStart = nil
}

if dp.existing[fieldKey] != nil {
dateChange.OldRangeEnd = copyTime(dp.existing[fieldData.OtherRangeKey].(*time.Time))
} else {
dateChange.OldRangeEnd = nil
}
} else {
if dp.existing[fieldKey] != nil {
dateChange.OldDate = copyTime(dp.existing[fieldKey].(*time.Time))
} else {
dateChange.OldDate = nil
}
}

dateChanges[fieldData.CommonKey] = dateChange
}
}

Expand Down Expand Up @@ -203,6 +245,7 @@ func getFieldDataMap() map[string]dateFieldData {
"completeICIP": {
HumanReadableName: "Complete ICIP",
IsRange: false,
CommonKey: "completeICIP",
},
"clearanceStarts": {
HumanReadableName: "Clearance",
Expand All @@ -221,6 +264,7 @@ func getFieldDataMap() map[string]dateFieldData {
"announced": {
HumanReadableName: "Announce model",
IsRange: false,
CommonKey: "announced",
},
"applicationsStart": {
HumanReadableName: "Application period",
Expand Down Expand Up @@ -253,7 +297,19 @@ func getFieldDataMap() map[string]dateFieldData {
"wrapUpEnds": {
HumanReadableName: "Model wrap-up end date",
IsRange: false,
CommonKey: "wrapUpEnds",
},
}
return fieldData
}

func getOrderedCommonKeys() []string {
return []string{
"completeICIP",
"clearance",
"announced",
"applications",
"performancePeriod",
"wrapUpEnds",
}
}
Loading
Loading