Files
mostlymatter/model/notify_admin.go
Allan Guwatudde bd42f0cd8c [MM-45564] - Notify Admin v2 (#20777)
* [MM-45564] - Notify Admin v2

* add dummy data

* update dummy data

* add store methods

* experiment with recurring task

* complete saving of the notification

* make improvements

* make improvements

* add store layer tests

* fix lint

* update store layer tests

* add app layer unit tests

* add store layers

* add app layer tests

* fix lint

* fix lint

* fix tests

* fix tests lint

* fix lint

* fix lint

* fix retry layer test

* add notifications manual trigger

* filter notifications based on current plan

* add test case

* temp change

* feedback impl

* fix translations

* change job scheduler

* refactor job

* fix store layer tests

* extract i18n

* fix lint

* fix translations

* fix translations

* add license statement for new file

* feedback impl-2

* fix lint

* update make file

* add intl ids

* improve

* fix lint

* feedback impl

* move code and rename files

* fix lint

* feedback impl

* add config for trigger notifications api

* fix tests

* tmp change

* undo temp changes

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2022-09-02 13:52:48 +03:00

76 строки
3.1 KiB
Go

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package model
import (
"fmt"
"net/http"
)
type MattermostPaidFeature string
const (
PaidFeatureGuestAccounts = MattermostPaidFeature("mattermost.feature.guest_accounts")
PaidFeatureCustomUsergroups = MattermostPaidFeature("mattermost.feature.custom_user_groups")
PaidFeatureCreateMultipleTeams = MattermostPaidFeature("mattermost.feature.create_multiple_teams")
PaidFeatureStartcall = MattermostPaidFeature("mattermost.feature.start_call")
PaidFeaturePlaybooksRetrospective = MattermostPaidFeature("mattermost.feature.playbooks_retro")
PaidFeatureUnlimitedMessages = MattermostPaidFeature("mattermost.feature.unlimited_messages")
PaidFeatureUnlimitedFileStorage = MattermostPaidFeature("mattermost.feature.unlimited_file_storage")
PaidFeatureUnlimitedIntegrations = MattermostPaidFeature("mattermost.feature.unlimited_integrations")
PaidFeatureUnlimitedBoardcards = MattermostPaidFeature("mattermost.feature.unlimited_board_cards")
PaidFeatureAllProfessionalfeatures = MattermostPaidFeature("mattermost.feature.all_professional")
PaidFeatureAllEnterprisefeatures = MattermostPaidFeature("mattermost.feature.all_enterprise")
)
var validSKUs map[string]struct{} = map[string]struct{}{
LicenseShortSkuProfessional: {},
LicenseShortSkuEnterprise: {},
}
// These are the features a non admin would typically ping an admin about
var paidFeatures map[MattermostPaidFeature]struct{} = map[MattermostPaidFeature]struct{}{
PaidFeatureGuestAccounts: {},
PaidFeatureCustomUsergroups: {},
PaidFeatureCreateMultipleTeams: {},
PaidFeatureStartcall: {},
PaidFeaturePlaybooksRetrospective: {},
PaidFeatureUnlimitedMessages: {},
PaidFeatureUnlimitedFileStorage: {},
PaidFeatureUnlimitedIntegrations: {},
PaidFeatureUnlimitedBoardcards: {},
PaidFeatureAllProfessionalfeatures: {},
PaidFeatureAllEnterprisefeatures: {},
}
type NotifyAdminToUpgradeRequest struct {
TrialNotification bool `json:"trial_notification"`
RequiredPlan string `json:"required_plan"`
RequiredFeature MattermostPaidFeature `json:"required_feature"`
}
type NotifyAdminData struct {
CreateAt int64 `json:"create_at,omitempty"`
UserId string `json:"user_id"`
RequiredPlan string `json:"required_plan"`
RequiredFeature MattermostPaidFeature `json:"required_feature"`
Trial bool `json:"trial"`
}
func (nad *NotifyAdminData) IsValid() *AppError {
if _, planOk := validSKUs[nad.RequiredPlan]; !planOk {
return NewAppError("NotifyAdmin.IsValid", fmt.Sprintf("Invalid plan, %s provided", nad.RequiredPlan), nil, "", http.StatusBadRequest)
}
if _, featureOk := paidFeatures[nad.RequiredFeature]; !featureOk {
return NewAppError("NotifyAdmin.IsValid", fmt.Sprintf("Invalid feature, %s provided", nad.RequiredFeature), nil, "", http.StatusBadRequest)
}
return nil
}
func (nad *NotifyAdminData) PreSave() {
nad.CreateAt = GetMillis()
}