* 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>
Этот коммит содержится в:
Harshil Sharma
2025-04-03 13:07:54 +05:30
коммит произвёл GitHub
родитель 21ca303b5e
Коммит a9f09cadc2
30 изменённых файлов: 409 добавлений и 163 удалений

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

@@ -2453,7 +2453,7 @@ func convertGroupMessageToChannel(c *Context, w http.ResponseWriter, r *http.Req
}
func canEditChannelBanner(license *model.License, originalChannel *model.Channel) *model.AppError {
if license == nil || !license.IsE20OrEnterprise() {
if !model.MinimumPremiumLicense(license) {
return model.NewAppError("", "license_error.feature_unavailable", nil, "feature is not available for the current license", http.StatusForbidden)
}

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

@@ -810,7 +810,7 @@ func TestPatchChannel(t *testing.T) {
t.Run("Should be able to configure channel banner on a channel", func(t *testing.T) {
client.Logout(context.Background())
th.LoginBasic()
th.App.Srv().SetLicense(model.NewTestLicenseSKU(model.LicenseShortSkuEnterprise))
th.App.Srv().SetLicense(model.NewTestLicenseSKU(model.LicenseShortSkuPremium))
defer func() {
th.App.Srv().RemoveLicense()
}()
@@ -845,7 +845,7 @@ func TestPatchChannel(t *testing.T) {
t.Run("Cannot enable channel banner without configuring it", func(t *testing.T) {
client.Logout(context.Background())
th.LoginBasic()
th.App.Srv().SetLicense(model.NewTestLicenseSKU(model.LicenseShortSkuEnterprise))
th.App.Srv().SetLicense(model.NewTestLicenseSKU(model.LicenseShortSkuPremium))
defer func() {
th.App.Srv().RemoveLicense()
}()
@@ -905,7 +905,7 @@ func TestPatchChannel(t *testing.T) {
t.Run("Cannot configure channel banner on a DM channel", func(t *testing.T) {
client.Logout(context.Background())
th.LoginBasic()
th.App.Srv().SetLicense(model.NewTestLicenseSKU(model.LicenseShortSkuEnterprise))
th.App.Srv().SetLicense(model.NewTestLicenseSKU(model.LicenseShortSkuPremium))
defer func() {
th.App.Srv().RemoveLicense()
}()
@@ -932,7 +932,7 @@ func TestPatchChannel(t *testing.T) {
t.Run("Cannot configure channel banner on a GM channel", func(t *testing.T) {
client.Logout(context.Background())
th.LoginBasic()
th.App.Srv().SetLicense(model.NewTestLicenseSKU(model.LicenseShortSkuEnterprise))
th.App.Srv().SetLicense(model.NewTestLicenseSKU(model.LicenseShortSkuPremium))
defer func() {
th.App.Srv().RemoveLicense()
}()
@@ -5728,7 +5728,7 @@ func TestCanEditChannelBanner(t *testing.T) {
})
t.Run("when channel type is direct message", func(t *testing.T) {
license := model.NewTestLicenseSKU(model.LicenseShortSkuEnterprise)
license := model.NewTestLicenseSKU(model.LicenseShortSkuPremium)
channel := &model.Channel{
Type: model.ChannelTypeDirect,
}
@@ -5741,7 +5741,7 @@ func TestCanEditChannelBanner(t *testing.T) {
})
t.Run("when channel type is group message", func(t *testing.T) {
license := model.NewTestLicenseSKU(model.LicenseShortSkuEnterprise)
license := model.NewTestLicenseSKU(model.LicenseShortSkuPremium)
channel := &model.Channel{
Type: model.ChannelTypeGroup,
}
@@ -5753,7 +5753,7 @@ func TestCanEditChannelBanner(t *testing.T) {
})
t.Run("when channel type is open and license is valid", func(t *testing.T) {
license := model.NewTestLicenseSKU(model.LicenseShortSkuEnterprise)
license := model.NewTestLicenseSKU(model.LicenseShortSkuPremium)
channel := &model.Channel{
Type: model.ChannelTypeOpen,
}
@@ -5763,7 +5763,7 @@ func TestCanEditChannelBanner(t *testing.T) {
})
t.Run("when channel type is private and license is valid", func(t *testing.T) {
license := model.NewTestLicenseSKU(model.LicenseShortSkuEnterprise)
license := model.NewTestLicenseSKU(model.LicenseShortSkuPremium)
channel := &model.Channel{
Type: model.ChannelTypePrivate,
}

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

@@ -27,7 +27,7 @@ func (api *API) InitCustomProfileAttributes() {
}
func listCPAFields(c *Context, w http.ResponseWriter, r *http.Request) {
if c.App.Channels().License() == nil || !c.App.Channels().License().IsE20OrEnterprise() {
if !model.MinimumEnterpriseLicense(c.App.Channels().License()) {
c.Err = model.NewAppError("Api4.listCPAFields", "api.custom_profile_attributes.license_error", nil, "", http.StatusForbidden)
return
}
@@ -49,7 +49,7 @@ func createCPAField(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if c.App.Channels().License() == nil || !c.App.Channels().License().IsE20OrEnterprise() {
if !model.MinimumEnterpriseLicense(c.App.Channels().License()) {
c.Err = model.NewAppError("Api4.createCPAField", "api.custom_profile_attributes.license_error", nil, "", http.StatusForbidden)
return
}
@@ -89,7 +89,7 @@ func patchCPAField(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if c.App.Channels().License() == nil || !c.App.Channels().License().IsE20OrEnterprise() {
if !model.MinimumEnterpriseLicense(c.App.Channels().License()) {
c.Err = model.NewAppError("Api4.patchCPAField", "api.custom_profile_attributes.license_error", nil, "", http.StatusForbidden)
return
}
@@ -151,7 +151,7 @@ func deleteCPAField(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if c.App.Channels().License() == nil || !c.App.Channels().License().IsE20OrEnterprise() {
if !model.MinimumEnterpriseLicense(c.App.Channels().License()) {
c.Err = model.NewAppError("Api4.deleteCPAField", "api.custom_profile_attributes.license_error", nil, "", http.StatusForbidden)
return
}
@@ -255,7 +255,7 @@ func sanitizePropertyValue(cpaField *model.CPAField, rawValue json.RawMessage) (
}
func patchCPAValues(c *Context, w http.ResponseWriter, r *http.Request) {
if c.App.Channels().License() == nil || !c.App.Channels().License().IsE20OrEnterprise() {
if !model.MinimumEnterpriseLicense(c.App.Channels().License()) {
c.Err = model.NewAppError("Api4.patchCPAValues", "api.custom_profile_attributes.license_error", nil, "", http.StatusForbidden)
return
}
@@ -327,7 +327,7 @@ func patchCPAValues(c *Context, w http.ResponseWriter, r *http.Request) {
}
func listCPAValues(c *Context, w http.ResponseWriter, r *http.Request) {
if c.App.Channels().License() == nil || !c.App.Channels().License().IsE20OrEnterprise() {
if !model.MinimumEnterpriseLicense(c.App.Channels().License()) {
c.Err = model.NewAppError("Api4.listCPAValues", "api.custom_profile_attributes.license_error", nil, "", http.StatusForbidden)
return
}

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

@@ -1482,7 +1482,7 @@ func licensedAndConfiguredForGroupBySource(app *app.App, source model.GroupSourc
return model.NewAppError("", "api.ldap_groups.license_error", nil, "", http.StatusForbidden)
}
if source == model.GroupSourceCustom && lic.SkuShortName != model.LicenseShortSkuProfessional && lic.SkuShortName != model.LicenseShortSkuEnterprise {
if source == model.GroupSourceCustom && !model.MinimumProfessionalLicense(lic) {
return model.NewAppError("", "api.custom_groups.license_error", nil, "", http.StatusBadRequest)
}

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

@@ -238,10 +238,6 @@ func requireLicense(c *Context) *model.AppError {
return nil
}
func minimumProfessionalLicense(c *Context) *model.AppError {
return model.MinimumProfessionalProvidedLicense(c.App.Srv().License())
}
func setHandlerOpts(handler *web.Handler, opts ...APIHandlerOption) {
if len(opts) == 0 {
return

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

@@ -21,7 +21,9 @@ func (api *API) InitIPFiltering() {
}
func ensureIPFilteringInterface(c *Context, where string) (einterfaces.IPFilteringInterface, bool) {
if c.App.IPFiltering() == nil || !c.App.Config().FeatureFlags.CloudIPFiltering || c.App.License() == nil || !c.App.License().IsCloud() || c.App.License().SkuShortName != model.LicenseShortSkuEnterprise {
license := c.App.License()
ipFilteringFeatureFlag := c.App.Config().FeatureFlags.CloudIPFiltering
if c.App.IPFiltering() == nil || !ipFilteringFeatureFlag || license == nil || !license.IsCloud() || !model.MinimumEnterpriseLicense(license) {
c.Err = model.NewAppError(where, "api.context.ip_filtering.not_available.app_error", nil, "", http.StatusNotImplemented)
return nil, false
}

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

@@ -63,7 +63,7 @@ func ensureOutgoingOAuthConnectionInterface(c *Context, where string) (einterfac
return nil, false
}
if c.App.OutgoingOAuthConnections() == nil || c.App.License() == nil || c.App.License().SkuShortName != model.LicenseShortSkuEnterprise {
if c.App.OutgoingOAuthConnections() == nil || !model.MinimumEnterpriseLicense(c.App.License()) {
c.Err = model.NewAppError(where, "api.license.upgrade_needed.app_error", nil, "", http.StatusNotImplemented)
return nil, false
}

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

@@ -1083,11 +1083,11 @@ func unpinPost(c *Context, w http.ResponseWriter, _ *http.Request) {
func acknowledgePost(c *Context, w http.ResponseWriter, r *http.Request) {
// license check
permissionErr := minimumProfessionalLicense(c)
if permissionErr != nil {
c.Err = permissionErr
if !model.MinimumProfessionalLicense(c.App.Srv().License()) {
c.Err = model.NewAppError("", model.NoTranslation, nil, "feature is not available for the current license", http.StatusNotImplemented)
return
}
c.RequirePostId().RequireUserId()
if c.Err != nil {
return
@@ -1122,11 +1122,11 @@ func acknowledgePost(c *Context, w http.ResponseWriter, r *http.Request) {
func unacknowledgePost(c *Context, w http.ResponseWriter, r *http.Request) {
// license check
permissionErr := minimumProfessionalLicense(c)
if permissionErr != nil {
c.Err = permissionErr
if !model.MinimumProfessionalLicense(c.App.Srv().License()) {
c.Err = model.NewAppError("", "license_error.feature_unavailable", nil, "feature is not available for the current license", http.StatusNotImplemented)
return
}
c.RequirePostId().RequireUserId()
if c.Err != nil {
return