Premium SKU (#30396)
* Added premium SKU * removed duplicate enterprise license check functions * Added license check on API layer * lint fix * lint fix * refactured signature: * test: Add comprehensive tests for license tier check functions * fixed test * text update * optimised license checks * fixedf test * Updated license valid function * webapp license checks * handling prekium SKU in webappp: * added plugin api method and general refactoring * Updated tests --------- Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
21ca303b5e
Коммит
a9f09cadc2
@@ -23,8 +23,19 @@ const (
|
||||
LicenseShortSkuE20 = "E20"
|
||||
LicenseShortSkuProfessional = "professional"
|
||||
LicenseShortSkuEnterprise = "enterprise"
|
||||
LicenseShortSkuPremium = "premium"
|
||||
|
||||
ProfessionalTier = 10
|
||||
EnterpriseTier = 20
|
||||
PremiumTier = 30
|
||||
)
|
||||
|
||||
var LicenseToLicenseTier = map[string]int{
|
||||
LicenseShortSkuProfessional: ProfessionalTier,
|
||||
LicenseShortSkuEnterprise: EnterpriseTier,
|
||||
LicenseShortSkuPremium: PremiumTier,
|
||||
}
|
||||
|
||||
const (
|
||||
LicenseUpForRenewalEmailSent = "LicenseUpForRenewalEmailSent"
|
||||
)
|
||||
@@ -356,8 +367,7 @@ func (l *License) IsSanctionedTrial() bool {
|
||||
func (l *License) HasEnterpriseMarketplacePlugins() bool {
|
||||
return *l.Features.EnterprisePlugins ||
|
||||
l.SkuShortName == LicenseShortSkuE20 ||
|
||||
l.SkuShortName == LicenseShortSkuProfessional ||
|
||||
l.SkuShortName == LicenseShortSkuEnterprise
|
||||
MinimumProfessionalLicense(l)
|
||||
}
|
||||
|
||||
func (l *License) HasRemoteClusterService() bool {
|
||||
@@ -371,8 +381,7 @@ func (l *License) HasRemoteClusterService() bool {
|
||||
}
|
||||
|
||||
return (l.Features != nil && l.Features.RemoteClusterService != nil && *l.Features.RemoteClusterService) ||
|
||||
l.SkuShortName == LicenseShortSkuProfessional ||
|
||||
l.SkuShortName == LicenseShortSkuEnterprise
|
||||
MinimumProfessionalLicense(l)
|
||||
}
|
||||
|
||||
func (l *License) HasSharedChannels() bool {
|
||||
@@ -381,13 +390,7 @@ func (l *License) HasSharedChannels() bool {
|
||||
}
|
||||
|
||||
return (l.Features != nil && l.Features.SharedChannels != nil && *l.Features.SharedChannels) ||
|
||||
l.SkuShortName == LicenseShortSkuProfessional ||
|
||||
l.SkuShortName == LicenseShortSkuEnterprise
|
||||
}
|
||||
|
||||
// IsE20OrEnterprise returns true when the license is for E20 or Enterprise.
|
||||
func (l *License) IsE20OrEnterprise() bool {
|
||||
return l.SkuShortName == LicenseShortSkuE20 || l.SkuShortName == LicenseShortSkuEnterprise
|
||||
MinimumProfessionalLicense(l)
|
||||
}
|
||||
|
||||
// NewTestLicense returns a license that expires in the future and has the given features.
|
||||
@@ -459,9 +462,19 @@ func (lr *LicenseRecord) PreSave() {
|
||||
lr.CreateAt = GetMillis()
|
||||
}
|
||||
|
||||
func MinimumProfessionalProvidedLicense(license *License) *AppError {
|
||||
if license == nil || (license.SkuShortName != LicenseShortSkuProfessional && license.SkuShortName != LicenseShortSkuEnterprise) {
|
||||
return NewAppError("", NoTranslation, nil, "license is neither professional nor enterprise", http.StatusNotImplemented)
|
||||
}
|
||||
return nil
|
||||
// MinimumProfessionalLicense returns true if the provided license is at least a professional license.
|
||||
// Higher tier licenses also satisfy the condition.
|
||||
func MinimumProfessionalLicense(license *License) bool {
|
||||
return license != nil && LicenseToLicenseTier[license.SkuShortName] >= ProfessionalTier
|
||||
}
|
||||
|
||||
// MinimumEnterpriseLicense returns true if the provided license is at least a enterprise license.
|
||||
// Higher tier licenses also satisfy the condition.
|
||||
func MinimumEnterpriseLicense(license *License) bool {
|
||||
return license != nil && LicenseToLicenseTier[license.SkuShortName] >= EnterpriseTier
|
||||
}
|
||||
|
||||
// MinimumPremiumLicense returns true if the provided license is at least a premium license.
|
||||
func MinimumPremiumLicense(license *License) bool {
|
||||
return license != nil && LicenseToLicenseTier[license.SkuShortName] >= PremiumTier
|
||||
}
|
||||
|
||||
@@ -485,3 +485,189 @@ func TestLicenseHasSharedChannels(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestMinimumProfessionalLicense(t *testing.T) {
|
||||
testCases := []struct {
|
||||
description string
|
||||
license *License
|
||||
expectedValue bool
|
||||
}{
|
||||
{
|
||||
"nil license",
|
||||
nil,
|
||||
false,
|
||||
},
|
||||
{
|
||||
"professional license",
|
||||
&License{
|
||||
SkuShortName: LicenseShortSkuProfessional,
|
||||
},
|
||||
true,
|
||||
},
|
||||
{
|
||||
"enterprise license",
|
||||
&License{
|
||||
SkuShortName: LicenseShortSkuEnterprise,
|
||||
},
|
||||
true,
|
||||
},
|
||||
{
|
||||
"premium license",
|
||||
&License{
|
||||
SkuShortName: LicenseShortSkuPremium,
|
||||
},
|
||||
true,
|
||||
},
|
||||
{
|
||||
"E10 license",
|
||||
&License{
|
||||
SkuShortName: LicenseShortSkuE10,
|
||||
},
|
||||
false,
|
||||
},
|
||||
{
|
||||
"E20 license",
|
||||
&License{
|
||||
SkuShortName: LicenseShortSkuE20,
|
||||
},
|
||||
false,
|
||||
},
|
||||
{
|
||||
"unknown license",
|
||||
&License{
|
||||
SkuShortName: "unknown",
|
||||
},
|
||||
false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
t.Run(testCase.description, func(t *testing.T) {
|
||||
assert.Equal(t, testCase.expectedValue, MinimumProfessionalLicense(testCase.license))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestMinimumEnterpriseLicense(t *testing.T) {
|
||||
testCases := []struct {
|
||||
description string
|
||||
license *License
|
||||
expectedValue bool
|
||||
}{
|
||||
{
|
||||
"nil license",
|
||||
nil,
|
||||
false,
|
||||
},
|
||||
{
|
||||
"professional license",
|
||||
&License{
|
||||
SkuShortName: LicenseShortSkuProfessional,
|
||||
},
|
||||
false,
|
||||
},
|
||||
{
|
||||
"enterprise license",
|
||||
&License{
|
||||
SkuShortName: LicenseShortSkuEnterprise,
|
||||
},
|
||||
true,
|
||||
},
|
||||
{
|
||||
"premium license",
|
||||
&License{
|
||||
SkuShortName: LicenseShortSkuPremium,
|
||||
},
|
||||
true,
|
||||
},
|
||||
{
|
||||
"E10 license",
|
||||
&License{
|
||||
SkuShortName: LicenseShortSkuE10,
|
||||
},
|
||||
false,
|
||||
},
|
||||
{
|
||||
"E20 license",
|
||||
&License{
|
||||
SkuShortName: LicenseShortSkuE20,
|
||||
},
|
||||
false,
|
||||
},
|
||||
{
|
||||
"unknown license",
|
||||
&License{
|
||||
SkuShortName: "unknown",
|
||||
},
|
||||
false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
t.Run(testCase.description, func(t *testing.T) {
|
||||
assert.Equal(t, testCase.expectedValue, MinimumEnterpriseLicense(testCase.license))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestMinimumPremiumLicense(t *testing.T) {
|
||||
testCases := []struct {
|
||||
description string
|
||||
license *License
|
||||
expectedValue bool
|
||||
}{
|
||||
{
|
||||
"nil license",
|
||||
nil,
|
||||
false,
|
||||
},
|
||||
{
|
||||
"professional license",
|
||||
&License{
|
||||
SkuShortName: LicenseShortSkuProfessional,
|
||||
},
|
||||
false,
|
||||
},
|
||||
{
|
||||
"enterprise license",
|
||||
&License{
|
||||
SkuShortName: LicenseShortSkuEnterprise,
|
||||
},
|
||||
false,
|
||||
},
|
||||
{
|
||||
"premium license",
|
||||
&License{
|
||||
SkuShortName: LicenseShortSkuPremium,
|
||||
},
|
||||
true,
|
||||
},
|
||||
{
|
||||
"E10 license",
|
||||
&License{
|
||||
SkuShortName: LicenseShortSkuE10,
|
||||
},
|
||||
false,
|
||||
},
|
||||
{
|
||||
"E20 license",
|
||||
&License{
|
||||
SkuShortName: LicenseShortSkuE20,
|
||||
},
|
||||
false,
|
||||
},
|
||||
{
|
||||
"unknown license",
|
||||
&License{
|
||||
SkuShortName: "unknown",
|
||||
},
|
||||
false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
t.Run(testCase.description, func(t *testing.T) {
|
||||
assert.Equal(t, testCase.expectedValue, MinimumPremiumLicense(testCase.license))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user