From b445440600a2c2c30fe9caf61604d743eef7bd53 Mon Sep 17 00:00:00 2001 From: Allan Guwatudde Date: Thu, 30 Jun 2022 09:18:13 +0300 Subject: [PATCH] [MM-45053] - Remove 'trial of Mattermost ending soon' product emails (#20550) * [MM-45053] - Remove 'trial of Mattermost ending soon' product emails * remove trial end warning email --- api4/cloud.go | 15 - app/app_iface.go | 2 - app/cloud.go | 59 --- app/email/email.go | 54 --- app/email/email_test.go | 81 ---- app/email/mocks/ServiceInterface.go | 28 -- app/email/service.go | 2 - app/opentracing/opentracing_layer.go | 44 --- i18n/en.json | 32 -- model/cloud.go | 2 - templates/cloud_trial_end_warning.html | 505 ------------------------- templates/cloud_trial_end_warning.mjml | 48 --- templates/cloud_trial_ended_email.html | 505 ------------------------- templates/cloud_trial_ended_email.mjml | 48 --- 14 files changed, 1425 deletions(-) delete mode 100644 templates/cloud_trial_end_warning.html delete mode 100644 templates/cloud_trial_end_warning.mjml delete mode 100644 templates/cloud_trial_ended_email.html delete mode 100644 templates/cloud_trial_ended_email.mjml diff --git a/api4/cloud.go b/api4/cloud.go index 60190cd3ca..9c23f30fca 100644 --- a/api4/cloud.go +++ b/api4/cloud.go @@ -7,7 +7,6 @@ import ( "bytes" "encoding/binary" "encoding/json" - "fmt" "io/ioutil" "net/http" "time" @@ -603,20 +602,6 @@ func handleCWSWebhook(c *Context, w http.ResponseWriter, r *http.Request) { c.Err = model.NewAppError("SendCloudWelcomeEmail", "api.user.send_cloud_welcome_email.error", nil, err.Error(), http.StatusInternalServerError) return } - case model.EventTypeTrialWillEnd: - endTimeStamp := event.SubscriptionTrialEndUnixTimeStamp - t := time.Unix(endTimeStamp, 0) - trialEndDate := fmt.Sprintf("%s %d, %d", t.Month(), t.Day(), t.Year()) - - if appErr := c.App.SendCloudTrialEndWarningEmail(trialEndDate, *c.App.Config().ServiceSettings.SiteURL); appErr != nil { - c.Err = appErr - return - } - case model.EventTypeTrialEnded: - if appErr := c.App.SendCloudTrialEndedEmail(); appErr != nil { - c.Err = appErr - return - } case model.EventTypeSubscriptionChanged: // event.ProductLimits is nil if there was no change if event.ProductLimits != nil { diff --git a/app/app_iface.go b/app/app_iface.go index d202338c0d..c80b3df099 100644 --- a/app/app_iface.go +++ b/app/app_iface.go @@ -1000,8 +1000,6 @@ type AppIface interface { SendAckToPushProxy(ack *model.PushNotificationAck) error SendAutoResponse(c *request.Context, channel *model.Channel, receiver *model.User, post *model.Post) (bool, *model.AppError) SendAutoResponseIfNecessary(c *request.Context, channel *model.Channel, sender *model.User, post *model.Post) (bool, *model.AppError) - SendCloudTrialEndWarningEmail(trialEndDate, siteURL string) *model.AppError - SendCloudTrialEndedEmail() *model.AppError SendEmailVerification(user *model.User, newEmail, redirect string) *model.AppError SendEphemeralPost(userID string, post *model.Post) *model.Post SendNotifications(post *model.Post, team *model.Team, channel *model.Channel, sender *model.User, parentPostList *model.PostList, setOnline bool) ([]string, error) diff --git a/app/cloud.go b/app/cloud.go index 1d90b4ec1a..7b23f469b5 100644 --- a/app/cloud.go +++ b/app/cloud.go @@ -123,62 +123,3 @@ func (a *App) SendNoCardPaymentFailedEmail() *model.AppError { } return nil } - -func (a *App) SendCloudTrialEndWarningEmail(trialEndDate, siteURL string) *model.AppError { - sysAdmins, e := a.getSysAdminsEmailRecipients() - if e != nil { - return e - } - - // we want to at least have one email sent out to an admin - countNotOks := 0 - - for admin := range sysAdmins { - name := sysAdmins[admin].FirstName - if name == "" { - name = sysAdmins[admin].Username - } - err := a.Srv().EmailService.SendCloudTrialEndWarningEmail(sysAdmins[admin].Email, name, trialEndDate, sysAdmins[admin].Locale, siteURL) - if err != nil { - a.Log().Error("Error sending trial ending warning to", mlog.String("email", sysAdmins[admin].Email), mlog.Err(err)) - countNotOks++ - } - } - - // if not even one admin got an email, we consider that this operation errored - if countNotOks == len(sysAdmins) { - return model.NewAppError("app.SendCloudTrialEndWarningEmail", "app.user.send_emails.app_error", nil, "", http.StatusInternalServerError) - } - - return nil -} - -func (a *App) SendCloudTrialEndedEmail() *model.AppError { - sysAdmins, e := a.getSysAdminsEmailRecipients() - if e != nil { - return e - } - - // we want to at least have one email sent out to an admin - countNotOks := 0 - - for admin := range sysAdmins { - name := sysAdmins[admin].FirstName - if name == "" { - name = sysAdmins[admin].Username - } - - err := a.Srv().EmailService.SendCloudTrialEndedEmail(sysAdmins[admin].Email, name, sysAdmins[admin].Locale, *a.Config().ServiceSettings.SiteURL) - if err != nil { - a.Log().Error("Error sending trial ended email to", mlog.String("email", sysAdmins[admin].Email), mlog.Err(err)) - countNotOks++ - } - } - - // if not even one admin got an email, we consider that this operation errored - if countNotOks == len(sysAdmins) { - return model.NewAppError("app.SendCloudTrialEndedEmail", "app.user.send_emails.app_error", nil, "", http.StatusInternalServerError) - } - - return nil -} diff --git a/app/email/email.go b/app/email/email.go index 80772dcdef..27eb9ab895 100644 --- a/app/email/email.go +++ b/app/email/email.go @@ -14,7 +14,6 @@ import ( "os" "strconv" "strings" - "time" "github.com/mattermost/mattermost-server/v6/model" "github.com/mattermost/mattermost-server/v6/shared/i18n" @@ -256,59 +255,6 @@ func (es *Service) SendCloudUpgradeConfirmationEmail(userEmail, name, date, loca return nil } -func (es *Service) SendCloudTrialEndWarningEmail(userEmail, name, trialEndDate, locale, siteURL string) error { - T := i18n.GetUserTranslations(locale) - subject := T("api.templates.cloud_trial_ending_email.subject") - - data := es.NewEmailTemplateData(locale) - data.Props["Title"] = T("api.templates.cloud_trial_ending_email.title") - data.Props["SubTitle"] = T("api.templates.cloud_trial_ending_email.subtitle", map[string]interface{}{"Name": name, "TrialEnd": trialEndDate}) - data.Props["SiteURL"] = siteURL - data.Props["ButtonURL"] = fmt.Sprintf("%s/admin_console/billing/subscription?action=show_purchase_modal", siteURL) - data.Props["Button"] = T("api.templates.cloud_trial_ending_email.add_payment_method") - data.Props["QuestionTitle"] = T("api.templates.questions_footer.title") - data.Props["QuestionInfo"] = T("api.templates.questions_footer.info") - - body, err := es.templatesContainer.RenderToString("cloud_trial_end_warning", data) - if err != nil { - return err - } - - if err := es.sendEmailWithCustomReplyTo(userEmail, subject, body, *es.config().SupportSettings.SupportEmail); err != nil { - return err - } - - return nil -} - -func (es *Service) SendCloudTrialEndedEmail(userEmail, name, locale, siteURL string) error { - T := i18n.GetUserTranslations(locale) - subject := T("api.templates.cloud_trial_ended_email.subject") - - t := time.Now() - todayDate := fmt.Sprintf("%s %d, %d", t.Month(), t.Day(), t.Year()) - - data := es.NewEmailTemplateData(locale) - data.Props["Title"] = T("api.templates.cloud_trial_ended_email.title") - data.Props["SubTitle"] = T("api.templates.cloud_trial_ended_email.subtitle", map[string]interface{}{"Name": name, "TodayDate": todayDate}) - data.Props["SiteURL"] = siteURL - data.Props["ButtonURL"] = fmt.Sprintf("%s/admin_console/billing/subscription", siteURL) - data.Props["Button"] = T("api.templates.cloud_trial_ended_email.start_subscription") - data.Props["QuestionTitle"] = T("api.templates.questions_footer.title") - data.Props["QuestionInfo"] = T("api.templates.questions_footer.info") - - body, err := es.templatesContainer.RenderToString("cloud_trial_ended_email", data) - if err != nil { - return err - } - - if err := es.sendEmailWithCustomReplyTo(userEmail, subject, body, *es.config().SupportSettings.SupportEmail); err != nil { - return err - } - - return nil -} - // SendCloudWelcomeEmail sends the cloud version of the welcome email func (es *Service) SendCloudWelcomeEmail(userEmail, locale, teamInviteID, workSpaceName, dns, siteURL string) error { T := i18n.GetUserTranslations(locale) diff --git a/app/email/email_test.go b/app/email/email_test.go index b74636257b..5742a67c73 100644 --- a/app/email/email_test.go +++ b/app/email/email_test.go @@ -182,87 +182,6 @@ func TestSendInviteEmails(t *testing.T) { }) } -func TestSendCloudTrialEndWarningEmail(t *testing.T) { - th := Setup(t).InitBasic() - defer th.TearDown() - th.ConfigureInbucketMail() - - emailTo := "testclouduser@example.com" - emailToUsername := strings.Split(emailTo, "@")[0] - th.UpdateConfig(func(cfg *model.Config) { - *cfg.SupportSettings.SupportEmail = "support@mattermost.com" - }) - - t.Run("SendCloudTrialEndWarningEmail", func(t *testing.T) { - verifyMailbox := func(t *testing.T) { - t.Helper() - - var resultsMailbox mail.JSONMessageHeaderInbucket - err2 := mail.RetryInbucket(5, func() error { - var err error - resultsMailbox, err = mail.GetMailBox(emailTo) - return err - }) - if err2 != nil { - t.Skipf("No email was received, maybe due load on the server: %v", err2) - } - - require.Len(t, resultsMailbox, 1) - require.Contains(t, resultsMailbox[0].To[0], emailTo, "Wrong To: recipient") - resultsEmail, err := mail.GetMessageFromMailbox(emailTo, resultsMailbox[0].ID) - require.NoError(t, err, "Could not get message from mailbox") - require.Contains(t, resultsEmail.Body.HTML, "http://testserver", "Wrong received message %s", resultsEmail.Body.Text) - require.Contains(t, resultsEmail.Body.HTML, emailToUsername, "Wrong received message %s", resultsEmail.Body.Text) - require.Contains(t, resultsEmail.Body.Text, "http://testserver", "Wrong received message %s", resultsEmail.Body.Text) - require.Contains(t, resultsEmail.Body.Text, emailToUsername, "Wrong received message %s", resultsEmail.Body.Text) - require.Contains(t, resultsEmail.Body.Text, "support@mattermost.com") - } - mail.DeleteMailBox(emailTo) - - err := th.service.SendCloudTrialEndWarningEmail(emailTo, emailToUsername, "June 23, 2200", th.BasicUser.Locale, "http://testserver") - require.NoError(t, err) - - verifyMailbox(t) - }) -} - -func TestSendCloudTrialEndedEmail(t *testing.T) { - th := Setup(t).InitBasic() - defer th.TearDown() - th.ConfigureInbucketMail() - - emailTo := "testclouduser@example.com" - emailToUsername := strings.Split(emailTo, "@")[0] - - t.Run("SendCloudTrialEndedEmail", func(t *testing.T) { - verifyMailbox := func(t *testing.T) { - t.Helper() - - var resultsMailbox mail.JSONMessageHeaderInbucket - err2 := mail.RetryInbucket(5, func() error { - var err error - resultsMailbox, err = mail.GetMailBox(emailTo) - return err - }) - if err2 != nil { - t.Skipf("No email was received, maybe due load on the server: %v", err2) - } - - require.Len(t, resultsMailbox, 1) - require.Contains(t, resultsMailbox[0].To[0], emailTo, "Wrong To: recipient") - resultsEmail, err := mail.GetMessageFromMailbox(emailTo, resultsMailbox[0].ID) - require.NoError(t, err, "Could not get message from mailbox") - require.Contains(t, resultsEmail.Body.Text, "Your free 30-day trial of Mattermost has ended", "Wrong received message %s", resultsEmail.Body.Text) - } - mail.DeleteMailBox(emailTo) - - err := th.service.SendCloudTrialEndedEmail(emailTo, emailToUsername, "June 23, 2200", th.BasicUser.Locale) - require.NoError(t, err) - - verifyMailbox(t) - }) -} - func TestSendCloudUpgradedEmail(t *testing.T) { th := Setup(t).InitBasic() defer th.TearDown() diff --git a/app/email/mocks/ServiceInterface.go b/app/email/mocks/ServiceInterface.go index 6043885665..68b97109fc 100644 --- a/app/email/mocks/ServiceInterface.go +++ b/app/email/mocks/ServiceInterface.go @@ -125,34 +125,6 @@ func (_m *ServiceInterface) SendChangeUsernameEmail(newUsername string, _a1 stri return r0 } -// SendCloudTrialEndWarningEmail provides a mock function with given fields: userEmail, name, trialEndDate, locale, siteURL -func (_m *ServiceInterface) SendCloudTrialEndWarningEmail(userEmail string, name string, trialEndDate string, locale string, siteURL string) error { - ret := _m.Called(userEmail, name, trialEndDate, locale, siteURL) - - var r0 error - if rf, ok := ret.Get(0).(func(string, string, string, string, string) error); ok { - r0 = rf(userEmail, name, trialEndDate, locale, siteURL) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// SendCloudTrialEndedEmail provides a mock function with given fields: userEmail, name, locale, siteURL -func (_m *ServiceInterface) SendCloudTrialEndedEmail(userEmail string, name string, locale string, siteURL string) error { - ret := _m.Called(userEmail, name, locale, siteURL) - - var r0 error - if rf, ok := ret.Get(0).(func(string, string, string, string) error); ok { - r0 = rf(userEmail, name, locale, siteURL) - } else { - r0 = ret.Error(0) - } - - return r0 -} - // SendCloudUpgradeConfirmationEmail provides a mock function with given fields: userEmail, name, trialEndDate, locale, siteURL, workspaceName func (_m *ServiceInterface) SendCloudUpgradeConfirmationEmail(userEmail string, name string, trialEndDate string, locale string, siteURL string, workspaceName string) error { ret := _m.Called(userEmail, name, trialEndDate, locale, siteURL, workspaceName) diff --git a/app/email/service.go b/app/email/service.go index 933cec8907..c4001af6be 100644 --- a/app/email/service.go +++ b/app/email/service.go @@ -129,8 +129,6 @@ type ServiceInterface interface { SendVerifyEmail(userEmail, locale, siteURL, token, redirect string) error SendSignInChangeEmail(email, method, locale, siteURL string) error SendWelcomeEmail(userID string, email string, verified bool, disableWelcomeEmail bool, locale, siteURL, redirect string) error - SendCloudTrialEndWarningEmail(userEmail, name, trialEndDate, locale, siteURL string) error - SendCloudTrialEndedEmail(userEmail, name, locale, siteURL string) error SendCloudUpgradeConfirmationEmail(userEmail, name, trialEndDate, locale, siteURL, workspaceName string) error SendCloudWelcomeEmail(userEmail, locale, teamInviteID, workSpaceName, dns, siteURL string) error SendPasswordChangeEmail(email, method, locale, siteURL string) error diff --git a/app/opentracing/opentracing_layer.go b/app/opentracing/opentracing_layer.go index 3c4410122b..db76b6626b 100644 --- a/app/opentracing/opentracing_layer.go +++ b/app/opentracing/opentracing_layer.go @@ -14857,50 +14857,6 @@ func (a *OpenTracingAppLayer) SendAutoResponseIfNecessary(c *request.Context, ch return resultVar0, resultVar1 } -func (a *OpenTracingAppLayer) SendCloudTrialEndWarningEmail(trialEndDate string, siteURL string) *model.AppError { - origCtx := a.ctx - span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.SendCloudTrialEndWarningEmail") - - a.ctx = newCtx - a.app.Srv().Store.SetContext(newCtx) - defer func() { - a.app.Srv().Store.SetContext(origCtx) - a.ctx = origCtx - }() - - defer span.Finish() - resultVar0 := a.app.SendCloudTrialEndWarningEmail(trialEndDate, siteURL) - - if resultVar0 != nil { - span.LogFields(spanlog.Error(resultVar0)) - ext.Error.Set(span, true) - } - - return resultVar0 -} - -func (a *OpenTracingAppLayer) SendCloudTrialEndedEmail() *model.AppError { - origCtx := a.ctx - span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.SendCloudTrialEndedEmail") - - a.ctx = newCtx - a.app.Srv().Store.SetContext(newCtx) - defer func() { - a.app.Srv().Store.SetContext(origCtx) - a.ctx = origCtx - }() - - defer span.Finish() - resultVar0 := a.app.SendCloudTrialEndedEmail() - - if resultVar0 != nil { - span.LogFields(spanlog.Error(resultVar0)) - ext.Error.Set(span, true) - } - - return resultVar0 -} - func (a *OpenTracingAppLayer) SendEmailVerification(user *model.User, newEmail string, redirect string) *model.AppError { origCtx := a.ctx span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.SendEmailVerification") diff --git a/i18n/en.json b/i18n/en.json index 6e4b2d3bd1..05fe271ff8 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -3135,38 +3135,6 @@ "id": "api.team.update_team_scheme.scheme_scope.error", "translation": "Unable to set the scheme to the team because the supplied scheme is not a team scheme." }, - { - "id": "api.templates.cloud_trial_ended_email.start_subscription", - "translation": "Start Subscription" - }, - { - "id": "api.templates.cloud_trial_ended_email.subject", - "translation": "Mattermost cloud trial has ended" - }, - { - "id": "api.templates.cloud_trial_ended_email.subtitle", - "translation": "{{.Name}}, your 30-day free trial of Mattermost Cloud Enterprise ended on {{.TodayDate}}. We hope you’ve enjoyed our flexible and secure collaboration platform. Please add your payment information to ensure your team can continue collaborating with Mattermost." - }, - { - "id": "api.templates.cloud_trial_ended_email.title", - "translation": "Your free 30-day trial of Mattermost has ended" - }, - { - "id": "api.templates.cloud_trial_ending_email.add_payment_method", - "translation": "Add Payment method" - }, - { - "id": "api.templates.cloud_trial_ending_email.subject", - "translation": "Mattermost cloud trial ending" - }, - { - "id": "api.templates.cloud_trial_ending_email.subtitle", - "translation": "{{.Name}}, your 30-day trial of Mattermost is ending in 3 days, on {{.TrialEnd}}. Please add your payment information to ensure your team can continue enjoying the benefits of Mattermost Cloud." - }, - { - "id": "api.templates.cloud_trial_ending_email.title", - "translation": "Your free 30-day trial of Mattermost is ending soon" - }, { "id": "api.templates.cloud_upgrade_confirmation.subject", "translation": "Mattermost Upgrade Confirmation" diff --git a/model/cloud.go b/model/cloud.go index e8fb1e3c4b..92645a4cee 100644 --- a/model/cloud.go +++ b/model/cloud.go @@ -11,8 +11,6 @@ const ( EventTypeSendAdminWelcomeEmail = "send-admin-welcome-email" EventTypeSendUpgradeConfirmationEmail = "send-upgrade-confirmation-email" EventTypeSubscriptionChanged = "subscription-changed" - EventTypeTrialWillEnd = "trial-will-end" - EventTypeTrialEnded = "trial-ended" ) var MockCWS string diff --git a/templates/cloud_trial_end_warning.html b/templates/cloud_trial_end_warning.html deleted file mode 100644 index 1f19dc3121..0000000000 --- a/templates/cloud_trial_end_warning.html +++ /dev/null @@ -1,505 +0,0 @@ -{{define "cloud_trial_end_warning"}} - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- -
- - - - - - -
- -
- - - - - - -
- -
- - - - - - -
- - - - - - -
- -
-
-
- -
-
- -
- - - - - - -
- -
- - - - - - - - - - - - -
-
{{.Props.Title}}
-
-
{{.Props.SubTitle}}
-
- - - - -
- - {{.Props.Button}} - -
-
-
- -
-
- -
- - - - - - -
- -
- - - - - - -
- - - - - - - - - -
- - - - - - -
- -
-
-
{{.Props.QuestionInfo}} - - {{.Props.SupportEmail}} - -
-
-
-
- -
-
- -
- - - - - - -
- -
- - - - - - -
-
{{.Props.Organization}} - {{.Props.FooterV2}} -
-
-
- -
-
- -
-
- -
- - - - -{{end}} diff --git a/templates/cloud_trial_end_warning.mjml b/templates/cloud_trial_end_warning.mjml deleted file mode 100644 index 1e4a459a17..0000000000 --- a/templates/cloud_trial_end_warning.mjml +++ /dev/null @@ -1,48 +0,0 @@ - - - - - - - - - - - - - - - {{.Props.Title}} - - - {{.Props.SubTitle}} - - - {{.Props.Button}} - - - - - - - - {{.Props.QuestionInfo}} - - {{.Props.SupportEmail}} - - - - - - - - {{.Props.Organization}} - {{.Props.FooterV2}} - - - - - - - - diff --git a/templates/cloud_trial_ended_email.html b/templates/cloud_trial_ended_email.html deleted file mode 100644 index 2f22baed47..0000000000 --- a/templates/cloud_trial_ended_email.html +++ /dev/null @@ -1,505 +0,0 @@ -{{define "cloud_trial_ended_email"}} - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- -
- - - - - - -
- -
- - - - - - -
- -
- - - - - - -
- - - - - - -
- -
-
-
- -
-
- -
- - - - - - -
- -
- - - - - - - - - - - - -
-
{{.Props.Title}}
-
-
{{.Props.SubTitle}}
-
- - - - -
- - {{.Props.Button}} - -
-
-
- -
-
- -
- - - - - - -
- -
- - - - - - -
- - - - - - - - - -
- - - - - - -
- -
-
-
{{.Props.QuestionInfo}} - - {{.Props.SupportEmail}} - -
-
-
-
- -
-
- -
- - - - - - -
- -
- - - - - - -
-
{{.Props.Organization}} - {{.Props.FooterV2}} -
-
-
- -
-
- -
-
- -
- - - - -{{end}} diff --git a/templates/cloud_trial_ended_email.mjml b/templates/cloud_trial_ended_email.mjml deleted file mode 100644 index c7c7bb5a5b..0000000000 --- a/templates/cloud_trial_ended_email.mjml +++ /dev/null @@ -1,48 +0,0 @@ - - - - - - - - - - - - - - - {{.Props.Title}} - - - {{.Props.SubTitle}} - - - {{.Props.Button}} - - - - - - - - {{.Props.QuestionInfo}} - - {{.Props.SupportEmail}} - - - - - - - - {{.Props.Organization}} - {{.Props.FooterV2}} - - - - - - - -