[CLD-6536] Adjustments to cloud annual renewal announcement bar (#25927)

* Adjustments to cloud annual renewal announcement bar

* Add exclusion for trials

* Add more exceptions for when on trial during renewal period

* Add support for simulated_current_time_ms

* A few more changes to allow us to test this post-merge

* Fix tests, pipeline

* Final fix around emails

---------

Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
Nick Misasi
2024-01-16 17:48:59 -05:00
коммит произвёл GitHub
родитель d1e37783cc
Коммит 7039176d31
8 изменённых файлов: 50 добавлений и 22 удалений

Просмотреть файл

@@ -111,6 +111,10 @@ func getSubscription(c *Context, w http.ResponseWriter, r *http.Request) {
}
}
if model.GetServiceEnvironment() != model.ServiceEnvironmentTest {
subscription.SimulatedCurrentTimeMs = nil
}
if !c.App.Config().FeatureFlags.CloudAnnualRenewals {
subscription.WillRenew = ""
subscription.CancelAt = nil

Просмотреть файл

@@ -285,6 +285,10 @@ func (a *App) DoSubscriptionRenewalCheck() {
return
}
if subscription.IsFreeTrial == "true" {
return // Don't send renewal emails for free trials
}
sysVar, err := a.Srv().Store().System().GetByName(model.CloudRenewalEmail)
if err != nil {
// We only care about the error if it wasn't a not found error
@@ -318,13 +322,13 @@ func (a *App) DoSubscriptionRenewalCheck() {
// Only send the email if within the period and it's not already been sent
// This allows the email to send on day 59 if for whatever reason it was unable to on day 60
if daysToExpiration <= 60 && daysToExpiration > 30 && prevSentEmail != 60 {
if daysToExpiration <= 60 && daysToExpiration > 30 && prevSentEmail != 60 && !(prevSentEmail < 60) {
emailFunc = a.Srv().EmailService.SendCloudRenewalEmail60
prevSentEmail = 60
} else if daysToExpiration <= 30 && daysToExpiration > 7 && prevSentEmail != 30 {
} else if daysToExpiration <= 30 && daysToExpiration > 7 && prevSentEmail != 30 && !(prevSentEmail < 30) {
emailFunc = a.Srv().EmailService.SendCloudRenewalEmail30
prevSentEmail = 30
} else if daysToExpiration <= 7 && daysToExpiration > 3 && prevSentEmail != 7 {
} else if daysToExpiration <= 7 && daysToExpiration >= 0 && prevSentEmail != 7 {
emailFunc = a.Srv().EmailService.SendCloudRenewalEmail7
prevSentEmail = 7
}

Просмотреть файл

@@ -5,8 +5,6 @@ package model
import (
"encoding/json"
"os"
"strconv"
"strings"
"time"
)
@@ -185,17 +183,16 @@ type Subscription struct {
BillingType string `json:"billing_type"`
CancelAt *int64 `json:"cancel_at"`
WillRenew string `json:"will_renew"`
SimulatedCurrentTimeMs *int64 `json:"simulated_current_time_ms"`
}
func (s *Subscription) DaysToExpiration() int64 {
now := time.Now().UnixMilli()
// Allows us to base the current time off of an environment variable for testing purposes
if GetServiceEnvironment() == ServiceEnvironmentTest {
if currTime, set := os.LookupEnv("CLOUD_MOCK_CURRENT_TIME"); set {
timeInt, err := strconv.ParseInt(currTime, 10, 64)
if err == nil {
now = time.Unix(timeInt, 0).UnixMilli()
}
// In the test environment we have test clocks. A test clock is a ms timestamp
// If it's not nil, we use it as the current time in all calculations
if s.SimulatedCurrentTimeMs != nil {
now = *s.SimulatedCurrentTimeMs
}
}
daysToExpiry := (s.EndAt - now) / (1000 * 60 * 60 * 24)