* 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

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

@@ -1465,7 +1465,7 @@ func (a *App) allowChannelMentions(c request.CTX, post *model.Post, numProfiles
// allowGroupMentions returns whether or not the group mentions are allowed for the given post.
func (a *App) allowGroupMentions(c request.CTX, post *model.Post) bool {
if license := a.Srv().License(); license == nil || (license.SkuShortName != model.LicenseShortSkuProfessional && license.SkuShortName != model.LicenseShortSkuEnterprise) {
if !model.MinimumProfessionalLicense(a.Srv().License()) {
return false
}

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

@@ -670,7 +670,6 @@ func (a *App) mergePrepackagedPlugins(remoteMarketplacePlugins map[string]*model
return model.NewAppError("mergePrepackagedPlugins", "app.plugin.config.app_error", nil, "", http.StatusInternalServerError)
}
isEnterpriseLicense := a.License() != nil && a.License().IsE20OrEnterprise()
for _, prepackaged := range pluginsEnvironment.PrepackagedPlugins() {
if prepackaged.Manifest == nil {
continue
@@ -687,7 +686,7 @@ func (a *App) mergePrepackagedPlugins(remoteMarketplacePlugins map[string]*model
// If not enterprise, check version.
// Playbooks is not listed in the marketplace, this only handles prepackaged.
if !isEnterpriseLicense {
if !model.MinimumEnterpriseLicense(a.License()) {
if prepackaged.Manifest.Id == model.PluginIdPlaybooks {
version, err := semver.Parse(prepackaged.Manifest.Version)
if err != nil {
@@ -1033,8 +1032,8 @@ func (ch *Channels) processPrepackagedPlugin(pluginPath *pluginSignaturePath) (*
if err != nil {
return nil, errors.Wrapf(err, "Unable to verify prepackaged playbooks version")
}
license := ch.License()
hasEnterpriseLicense := license != nil && license.IsE20OrEnterprise()
hasEnterpriseLicense := model.MinimumEnterpriseLicense(ch.License())
// Do not install playbooks >=v2 if we do not have an enterprise license
if version.GTE(SemVerV2) && !hasEnterpriseLicense {
@@ -1105,15 +1104,13 @@ func (ch *Channels) pluginIsTransitionallyPrepackaged(m *model.Manifest) bool {
// - the server is not enterprise licensed
// - the playbooks version is <v2
func (ch *Channels) playbooksIsTransitionallyPrepackaged(m *model.Manifest) bool {
license := ch.srv.License()
isNotEnterpriseLicensed := !(license != nil && license.IsE20OrEnterprise())
version, err := semver.Parse(m.Version)
if err != nil {
ch.srv.Log().Warn("unable to parse prepackaged playbooks version - not marking it as transitional.", mlog.String("version", m.Version), mlog.Err(err))
return false
}
return isNotEnterpriseLicensed && version.LT(SemVerV2)
return !model.MinimumEnterpriseLicense(ch.srv.License()) && version.LT(SemVerV2)
}
// shouldPersistTransitionallyPrepackagedPlugin determines if a transitionally prepackaged plugin

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

@@ -55,16 +55,14 @@ func postPriorityCheck(
}
if ack := priority.RequestedAck; ack != nil && *ack {
licenseErr := model.MinimumProfessionalProvidedLicense(license)
if licenseErr != nil {
return licenseErr
if !model.MinimumProfessionalLicense(license) {
return model.NewAppError("", "license_error.feature_unavailable", nil, "feature is not available for the current license", http.StatusNotImplemented)
}
}
if notification := priority.PersistentNotifications; notification != nil && *notification {
licenseErr := model.MinimumProfessionalProvidedLicense(license)
if licenseErr != nil {
return licenseErr
if !model.MinimumProfessionalLicense(license) {
return model.NewAppError("", "license_error.feature_unavailable", nil, "feature is not available for the current license", http.StatusNotImplemented)
}
if !isPersistentNotificationsEnabled {
return priorityForbiddenErr

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

@@ -199,7 +199,7 @@ func (a *App) GetUserCountForReport(filter *model.UserReportOptions) (*int64, *m
}
func (a *App) StartUsersBatchExport(rctx request.CTX, ro *model.UserReportOptions, startAt int64, endAt int64) *model.AppError {
if license := a.Srv().License(); license == nil || (license.SkuShortName != model.LicenseShortSkuProfessional && license.SkuShortName != model.LicenseShortSkuEnterprise) {
if !model.MinimumProfessionalLicense(a.Srv().License()) {
return model.NewAppError("StartUsersBatchExport", "app.report.start_users_batch_export.license_error", nil, "", http.StatusBadRequest)
}

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

@@ -21,8 +21,7 @@ func (scheduler *Scheduler) NextScheduleTime(cfg *model.Config, _ time.Time, _ b
func MakeScheduler(jobServer *jobs.JobServer, licenseFunc func() *model.License) *Scheduler {
enabledFunc := func(_ *model.Config) bool {
l := licenseFunc()
return l != nil && (l.SkuShortName == model.LicenseShortSkuProfessional || l.SkuShortName == model.LicenseShortSkuEnterprise)
return model.MinimumProfessionalLicense(licenseFunc())
}
return &Scheduler{jobs.NewPeriodicScheduler(jobServer, model.JobTypePostPersistentNotifications, 0, enabledFunc)}
}