MM-10606: License feature flag for custom schemes. (#8804)
* MM-10606: Add new field to license for custom schemes. * Add feature flag to license check for Schemes.
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
a09dc68e1d
Коммит
463065c8ba
@@ -26,7 +26,7 @@ func createScheme(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if c.App.License() == nil {
|
||||
if c.App.License() == nil || !*c.App.License().Features.CustomPermissionsSchemes {
|
||||
c.Err = model.NewAppError("Api4.CreateScheme", "api.scheme.create_scheme.license.error", nil, "", http.StatusNotImplemented)
|
||||
return
|
||||
}
|
||||
@@ -161,7 +161,7 @@ func patchScheme(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if c.App.License() == nil {
|
||||
if c.App.License() == nil || !*c.App.License().Features.CustomPermissionsSchemes {
|
||||
c.Err = model.NewAppError("Api4.PatchScheme", "api.scheme.patch_scheme.license.error", nil, "", http.StatusNotImplemented)
|
||||
return
|
||||
}
|
||||
@@ -192,7 +192,7 @@ func deleteScheme(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if c.App.License() == nil {
|
||||
if c.App.License() == nil || !*c.App.License().Features.CustomPermissionsSchemes {
|
||||
c.Err = model.NewAppError("Api4.DeleteScheme", "api.scheme.delete_scheme.license.error", nil, "", http.StatusNotImplemented)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ func TestCreateScheme(t *testing.T) {
|
||||
th := Setup().InitBasic().InitSystemAdmin()
|
||||
defer th.TearDown()
|
||||
|
||||
th.App.SetLicense(model.NewTestLicense(""))
|
||||
th.App.SetLicense(model.NewTestLicense("custom_permissions_schemes"))
|
||||
|
||||
// Mark the migration as done.
|
||||
<-th.App.Srv.Store.System().PermanentDeleteByName(model.MIGRATION_KEY_ADVANCED_PERMISSIONS_PHASE_2)
|
||||
@@ -124,7 +124,7 @@ func TestCreateScheme(t *testing.T) {
|
||||
assert.Nil(t, res.Err)
|
||||
|
||||
th.LoginSystemAdmin()
|
||||
th.App.SetLicense(model.NewTestLicense(""))
|
||||
th.App.SetLicense(model.NewTestLicense("custom_permissions_schemes"))
|
||||
|
||||
scheme7 := &model.Scheme{
|
||||
Name: model.NewId(),
|
||||
@@ -139,7 +139,7 @@ func TestGetScheme(t *testing.T) {
|
||||
th := Setup().InitBasic().InitSystemAdmin()
|
||||
defer th.TearDown()
|
||||
|
||||
th.App.SetLicense(model.NewTestLicense(""))
|
||||
th.App.SetLicense(model.NewTestLicense("custom_permissions_schemes"))
|
||||
|
||||
// Basic test of creating a team scheme.
|
||||
scheme1 := &model.Scheme{
|
||||
@@ -201,7 +201,7 @@ func TestGetSchemes(t *testing.T) {
|
||||
th := Setup().InitBasic().InitSystemAdmin()
|
||||
defer th.TearDown()
|
||||
|
||||
th.App.SetLicense(model.NewTestLicense(""))
|
||||
th.App.SetLicense(model.NewTestLicense("custom_permissions_schemes"))
|
||||
|
||||
scheme1 := &model.Scheme{
|
||||
Name: model.NewId(),
|
||||
@@ -266,7 +266,7 @@ func TestGetTeamsForScheme(t *testing.T) {
|
||||
th := Setup().InitBasic().InitSystemAdmin()
|
||||
defer th.TearDown()
|
||||
|
||||
th.App.SetLicense(model.NewTestLicense(""))
|
||||
th.App.SetLicense(model.NewTestLicense("custom_permissions_schemes"))
|
||||
|
||||
<-th.App.Srv.Store.System().PermanentDeleteByName(model.MIGRATION_KEY_ADVANCED_PERMISSIONS_PHASE_2)
|
||||
res := <-th.App.Srv.Store.System().Save(&model.System{Name: model.MIGRATION_KEY_ADVANCED_PERMISSIONS_PHASE_2, Value: "true"})
|
||||
@@ -363,7 +363,7 @@ func TestGetChannelsForScheme(t *testing.T) {
|
||||
th := Setup().InitBasic().InitSystemAdmin()
|
||||
defer th.TearDown()
|
||||
|
||||
th.App.SetLicense(model.NewTestLicense(""))
|
||||
th.App.SetLicense(model.NewTestLicense("custom_permissions_schemes"))
|
||||
|
||||
<-th.App.Srv.Store.System().PermanentDeleteByName(model.MIGRATION_KEY_ADVANCED_PERMISSIONS_PHASE_2)
|
||||
res := <-th.App.Srv.Store.System().Save(&model.System{Name: model.MIGRATION_KEY_ADVANCED_PERMISSIONS_PHASE_2, Value: "true"})
|
||||
@@ -462,7 +462,7 @@ func TestPatchScheme(t *testing.T) {
|
||||
th := Setup().InitBasic().InitSystemAdmin()
|
||||
defer th.TearDown()
|
||||
|
||||
th.App.SetLicense(model.NewTestLicense(""))
|
||||
th.App.SetLicense(model.NewTestLicense("custom_permissions_schemes"))
|
||||
|
||||
// Mark the migration as done.
|
||||
<-th.App.Srv.Store.System().PermanentDeleteByName(model.MIGRATION_KEY_ADVANCED_PERMISSIONS_PHASE_2)
|
||||
@@ -555,7 +555,7 @@ func TestPatchScheme(t *testing.T) {
|
||||
assert.Nil(t, res.Err)
|
||||
|
||||
th.LoginSystemAdmin()
|
||||
th.App.SetLicense(model.NewTestLicense(""))
|
||||
th.App.SetLicense(model.NewTestLicense("custom_permissions_schemes"))
|
||||
|
||||
_, r12 := th.SystemAdminClient.PatchScheme(s6.Id, schemePatch)
|
||||
CheckNotImplementedStatus(t, r12)
|
||||
@@ -566,7 +566,7 @@ func TestDeleteScheme(t *testing.T) {
|
||||
defer th.TearDown()
|
||||
|
||||
t.Run("ValidTeamScheme", func(t *testing.T) {
|
||||
th.App.SetLicense(model.NewTestLicense(""))
|
||||
th.App.SetLicense(model.NewTestLicense("custom_permissions_schemes"))
|
||||
|
||||
// Mark the migration as done.
|
||||
<-th.App.Srv.Store.System().PermanentDeleteByName(model.MIGRATION_KEY_ADVANCED_PERMISSIONS_PHASE_2)
|
||||
@@ -641,7 +641,7 @@ func TestDeleteScheme(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("ValidChannelScheme", func(t *testing.T) {
|
||||
th.App.SetLicense(model.NewTestLicense(""))
|
||||
th.App.SetLicense(model.NewTestLicense("custom_permissions_schemes"))
|
||||
|
||||
// Mark the migration as done.
|
||||
<-th.App.Srv.Store.System().PermanentDeleteByName(model.MIGRATION_KEY_ADVANCED_PERMISSIONS_PHASE_2)
|
||||
@@ -704,7 +704,7 @@ func TestDeleteScheme(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("FailureCases", func(t *testing.T) {
|
||||
th.App.SetLicense(model.NewTestLicense(""))
|
||||
th.App.SetLicense(model.NewTestLicense("custom_permissions_schemes"))
|
||||
|
||||
// Mark the migration as done.
|
||||
<-th.App.Srv.Store.System().PermanentDeleteByName(model.MIGRATION_KEY_ADVANCED_PERMISSIONS_PHASE_2)
|
||||
@@ -741,7 +741,7 @@ func TestDeleteScheme(t *testing.T) {
|
||||
res = <-th.App.Srv.Store.System().PermanentDeleteByName(model.MIGRATION_KEY_ADVANCED_PERMISSIONS_PHASE_2)
|
||||
assert.Nil(t, res.Err)
|
||||
|
||||
th.App.SetLicense(model.NewTestLicense(""))
|
||||
th.App.SetLicense(model.NewTestLicense("custom_permissions_schemes"))
|
||||
|
||||
_, r6 := th.SystemAdminClient.DeleteScheme(s1.Id)
|
||||
CheckNotImplementedStatus(t, r6)
|
||||
|
||||
@@ -56,6 +56,7 @@ type Features struct {
|
||||
EmailNotificationContents *bool `json:"email_notification_contents"`
|
||||
DataRetention *bool `json:"data_retention"`
|
||||
MessageExport *bool `json:"message_export"`
|
||||
CustomPermissionsSchemes *bool `json:"custom_permissions_schemes"`
|
||||
|
||||
// after we enabled more features for webrtc we'll need to control them with this
|
||||
FutureFeatures *bool `json:"future_features"`
|
||||
@@ -78,6 +79,7 @@ func (f *Features) ToMap() map[string]interface{} {
|
||||
"email_notification_contents": *f.EmailNotificationContents,
|
||||
"data_retention": *f.DataRetention,
|
||||
"message_export": *f.MessageExport,
|
||||
"custom_permissions_schemes": *f.CustomPermissionsSchemes,
|
||||
"future": *f.FutureFeatures,
|
||||
}
|
||||
}
|
||||
@@ -158,6 +160,10 @@ func (f *Features) SetDefaults() {
|
||||
if f.MessageExport == nil {
|
||||
f.MessageExport = NewBool(*f.FutureFeatures)
|
||||
}
|
||||
|
||||
if f.CustomPermissionsSchemes == nil {
|
||||
f.CustomPermissionsSchemes = NewBool(*f.FutureFeatures)
|
||||
}
|
||||
}
|
||||
|
||||
func (l *License) IsExpired() bool {
|
||||
|
||||
@@ -28,6 +28,8 @@ func TestLicenseFeaturesToMap(t *testing.T) {
|
||||
CheckTrue(t, m["elastic_search"].(bool))
|
||||
CheckTrue(t, m["email_notification_contents"].(bool))
|
||||
CheckTrue(t, m["data_retention"].(bool))
|
||||
CheckTrue(t, m["message_export"].(bool))
|
||||
CheckTrue(t, m["custom_permissions_schemes"].(bool))
|
||||
CheckTrue(t, m["future"].(bool))
|
||||
}
|
||||
|
||||
@@ -50,6 +52,8 @@ func TestLicenseFeaturesSetDefaults(t *testing.T) {
|
||||
CheckTrue(t, *f.Elasticsearch)
|
||||
CheckTrue(t, *f.EmailNotificationContents)
|
||||
CheckTrue(t, *f.DataRetention)
|
||||
CheckTrue(t, *f.MessageExport)
|
||||
CheckTrue(t, *f.CustomPermissionsSchemes)
|
||||
CheckTrue(t, *f.FutureFeatures)
|
||||
|
||||
f = Features{}
|
||||
@@ -70,6 +74,8 @@ func TestLicenseFeaturesSetDefaults(t *testing.T) {
|
||||
*f.PasswordRequirements = true
|
||||
*f.Elasticsearch = true
|
||||
*f.DataRetention = true
|
||||
*f.MessageExport = true
|
||||
*f.CustomPermissionsSchemes = true
|
||||
*f.EmailNotificationContents = true
|
||||
|
||||
f.SetDefaults()
|
||||
@@ -89,6 +95,8 @@ func TestLicenseFeaturesSetDefaults(t *testing.T) {
|
||||
CheckTrue(t, *f.Elasticsearch)
|
||||
CheckTrue(t, *f.EmailNotificationContents)
|
||||
CheckTrue(t, *f.DataRetention)
|
||||
CheckTrue(t, *f.MessageExport)
|
||||
CheckTrue(t, *f.CustomPermissionsSchemes)
|
||||
CheckFalse(t, *f.FutureFeatures)
|
||||
}
|
||||
|
||||
@@ -171,6 +179,8 @@ func TestLicenseToFromJson(t *testing.T) {
|
||||
CheckBool(t, *f1.PasswordRequirements, *f.PasswordRequirements)
|
||||
CheckBool(t, *f1.Elasticsearch, *f.Elasticsearch)
|
||||
CheckBool(t, *f1.DataRetention, *f.DataRetention)
|
||||
CheckBool(t, *f1.MessageExport, *f.MessageExport)
|
||||
CheckBool(t, *f1.CustomPermissionsSchemes, *f.CustomPermissionsSchemes)
|
||||
CheckBool(t, *f1.FutureFeatures, *f.FutureFeatures)
|
||||
|
||||
invalid := `{"asdf`
|
||||
|
||||
@@ -152,6 +152,7 @@ func GetClientLicense(l *model.License) map[string]string {
|
||||
props["PhoneNumber"] = l.Customer.PhoneNumber
|
||||
props["EmailNotificationContents"] = strconv.FormatBool(*l.Features.EmailNotificationContents)
|
||||
props["MessageExport"] = strconv.FormatBool(*l.Features.MessageExport)
|
||||
props["CustomPermissionsSchemes"] = strconv.FormatBool(*l.Features.CustomPermissionsSchemes)
|
||||
}
|
||||
|
||||
return props
|
||||
|
||||
Ссылка в новой задаче
Block a user