[MM-43649] - Ability for end users to notify admin to upgrade workspace (#20338)
* [MM-43649] - Ability for end users to notify admin to upgrade workspace * add test case * move code to app layer * feedback impl * feedback impl-1 * feedback impl * simplify logic * fix typo and lint * fix app layers * Use a single critical section for users notified admin (#20488) * Use a single critical section for users notifying admin * change persistence mechanism * add more tests * change bot message * fix translations * update logic to notify once within cooloff period Co-authored-by: Mattermod <mattermod@users.noreply.github.com> Co-authored-by: Nathaniel Allred <neallred@protonmail.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
dad8eab777
Коммит
1d9fa3c333
@@ -3,7 +3,11 @@
|
||||
|
||||
package model
|
||||
|
||||
import "strings"
|
||||
import (
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
EventTypeFailedPayment = "failed-payment"
|
||||
@@ -37,6 +41,9 @@ const (
|
||||
SubscriptionFamilyOnPrem = SubscriptionFamily("on-prem")
|
||||
)
|
||||
|
||||
const defaultCloudNotifyAdminCoolOffDays = 30
|
||||
const CloudNotifyAdminInfo = "cloud_notify_admin_info"
|
||||
|
||||
// Product model represents a product on the cloud system.
|
||||
type Product struct {
|
||||
ID string `json:"id"`
|
||||
@@ -228,3 +235,23 @@ type ProductLimits struct {
|
||||
Messages *MessagesLimits `json:"messages,omitempty"`
|
||||
Teams *TeamsLimits `json:"teams,omitempty"`
|
||||
}
|
||||
|
||||
type NotifyAdminToUpgradeRequest struct {
|
||||
CurrentTeamId string `json:"current_team_id"`
|
||||
}
|
||||
|
||||
type AdminNotificationUserInfo struct {
|
||||
LastUserIDToNotify string
|
||||
LastNotificationTimestamp int64
|
||||
}
|
||||
|
||||
func CanNotify(lastNotificationTimestamp int64) bool {
|
||||
coolOffPeriodDaysEnv := os.Getenv("MM_CLOUD_NOTIFY_ADMIN_COOL_OFF_DAYS")
|
||||
coolOffPeriodDays, parseError := strconv.ParseFloat(coolOffPeriodDaysEnv, 64)
|
||||
if parseError != nil {
|
||||
coolOffPeriodDays = defaultCloudNotifyAdminCoolOffDays
|
||||
}
|
||||
daysToMillis := coolOffPeriodDays * 24 * 60 * 60 * 1000
|
||||
timeDiff := GetMillis() - lastNotificationTimestamp
|
||||
return timeDiff >= int64(daysToMillis)
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user