diff --git a/api4/insights.go b/api4/insights.go index 9d74a57c2f..c5bfa018ee 100644 --- a/api4/insights.go +++ b/api4/insights.go @@ -99,13 +99,8 @@ func getTopReactionsForTeamSince(c *Context, w http.ResponseWriter, r *http.Requ } func getTopReactionsForUserSince(c *Context, w http.ResponseWriter, r *http.Request) { - // license and guest user check - permissionErr := minimumProfessionalLicense(c) - if permissionErr != nil { - c.Err = permissionErr - return - } - permissionErr = rejectGuests(c) + // guest user check + permissionErr := rejectGuests(c) if permissionErr != nil { c.Err = permissionErr return @@ -233,13 +228,8 @@ func getTopChannelsForTeamSince(c *Context, w http.ResponseWriter, r *http.Reque } func getTopChannelsForUserSince(c *Context, w http.ResponseWriter, r *http.Request) { - // license and guest user check - permissionErr := minimumProfessionalLicense(c) - if permissionErr != nil { - c.Err = permissionErr - return - } - permissionErr = rejectGuests(c) + // guest user check + permissionErr := rejectGuests(c) if permissionErr != nil { c.Err = permissionErr return @@ -367,13 +357,8 @@ func getTopThreadsForTeamSince(c *Context, w http.ResponseWriter, r *http.Reques } func getTopThreadsForUserSince(c *Context, w http.ResponseWriter, r *http.Request) { - // license and guest user check - permissionErr := minimumProfessionalLicense(c) - if permissionErr != nil { - c.Err = permissionErr - return - } - permissionErr = rejectGuests(c) + // guest user check + permissionErr := rejectGuests(c) if permissionErr != nil { c.Err = permissionErr return @@ -433,13 +418,8 @@ func getTopThreadsForUserSince(c *Context, w http.ResponseWriter, r *http.Reques // Top DMs func getTopDMsForUserSince(c *Context, w http.ResponseWriter, r *http.Request) { - // license and guest user check - permissionErr := minimumProfessionalLicense(c) - if permissionErr != nil { - c.Err = permissionErr - return - } - permissionErr = rejectGuests(c) + // guest user check + permissionErr := rejectGuests(c) if permissionErr != nil { c.Err = permissionErr return @@ -540,13 +520,8 @@ func getTopInactiveChannelsForTeamSince(c *Context, w http.ResponseWriter, r *ht // top inactive channels func getTopInactiveChannelsForUserSince(c *Context, w http.ResponseWriter, r *http.Request) { - // license and guest user check - permissionErr := minimumProfessionalLicense(c) - if permissionErr != nil { - c.Err = permissionErr - return - } - permissionErr = rejectGuests(c) + // guest user check + permissionErr := rejectGuests(c) if permissionErr != nil { c.Err = permissionErr return diff --git a/api4/insights_test.go b/api4/insights_test.go index 2443c1ea26..e304a60a49 100644 --- a/api4/insights_test.go +++ b/api4/insights_test.go @@ -242,14 +242,20 @@ func TestGetTopReactionsForTeamSince(t *testing.T) { assert.Error(t, err) CheckForbiddenStatus(t, resp) }) + + t.Run("get-top-reactions-for-team-since invalid license", func(t *testing.T) { + th.App.Srv().SetLicense(model.NewTestLicense("")) + + _, resp, err := client.GetTopReactionsForTeamSince(teamId, model.TimeRangeToday, 0, 5) + assert.Error(t, err) + CheckNotImplementedStatus(t, resp) + }) } func TestGetTopReactionsForUserSince(t *testing.T) { th := Setup(t).InitBasic() defer th.TearDown() - th.App.Srv().SetLicense(model.NewTestLicenseSKU(model.LicenseShortSkuProfessional)) - client := th.Client userId := th.BasicUser.Id @@ -539,14 +545,20 @@ func TestGetTopChannelsForTeamSince(t *testing.T) { assert.Error(t, err) CheckForbiddenStatus(t, resp) }) + + t.Run("get-top-channels-for-team-since invalid license", func(t *testing.T) { + th.App.Srv().SetLicense(model.NewTestLicense("")) + + _, resp, err := client.GetTopChannelsForTeamSince(teamId, model.TimeRangeToday, 0, 5) + assert.Error(t, err) + CheckNotImplementedStatus(t, resp) + }) } func TestGetTopChannelsForUserSince(t *testing.T) { th := Setup(t).InitBasic() defer th.TearDown() - th.App.Srv().SetLicense(model.NewTestLicenseSKU(model.LicenseShortSkuProfessional)) - client := th.Client userId := th.BasicUser.Id @@ -708,12 +720,19 @@ func TestGetTopThreadsForTeamSince(t *testing.T) { topTeamThreadsByUser2IncludingPrivate, _, _ := client.GetTopThreadsForTeamSince(th.BasicTeam.Id, model.TimeRangeToday, 0, 10) require.Nil(t, appErr) require.Len(t, topTeamThreadsByUser2IncludingPrivate.Items, 2) + + t.Run("get-top-threads-for-team-since invalid license", func(t *testing.T) { + th.App.Srv().SetLicense(model.NewTestLicense("")) + + _, resp, err := client.GetTopThreadsForTeamSince(th.BasicTeam.Id, model.TimeRangeToday, 0, 5) + assert.Error(t, err) + CheckNotImplementedStatus(t, resp) + }) } func TestGetTopThreadsForUserSince(t *testing.T) { th := Setup(t).InitBasic() defer th.TearDown() - th.App.Srv().SetLicense(model.NewTestLicenseSKU(model.LicenseShortSkuProfessional)) th.LoginBasic() client := th.Client @@ -958,6 +977,14 @@ func TestGetTopInactiveChannelsForTeamSince(t *testing.T) { assert.Equal(t, expectedTopChannels[i].ID, channel.ID) } }) + + t.Run("get-top-inactive-channels-for-team-since invalid license", func(t *testing.T) { + th.App.Srv().SetLicense(model.NewTestLicense("")) + + _, resp, err := client.GetTopInactiveChannelsForTeamSince(teamId, model.TimeRangeToday, 0, 5) + assert.Error(t, err) + CheckNotImplementedStatus(t, resp) + }) } func TestGetTopDMsForUserSince(t *testing.T) { @@ -970,7 +997,6 @@ func TestGetTopDMsForUserSince(t *testing.T) { *c.TeamSettings.EnableUserDeactivation = true }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableBotAccountCreation = true }) - th.App.Srv().SetLicense(model.NewTestLicenseSKU(model.LicenseShortSkuProfessional)) // basicuser1 - bu1, basicuser - bu // create dm channels for bu-bu, bu1-bu1, bu-bu1, bot-bu @@ -1169,4 +1195,12 @@ func TestNewTeamMembersSince(t *testing.T) { require.Len(t, list.Items, 1) require.False(t, list.HasNext) }) + + t.Run("get-new-team-members-since invalid license", func(t *testing.T) { + th.App.Srv().SetLicense(model.NewTestLicense("")) + + _, resp, err := th.Client.GetNewTeamMembersSince(team.Id, model.TimeRangeToday, 0, 2) + assert.Error(t, err) + CheckNotImplementedStatus(t, resp) + }) } diff --git a/config/client.go b/config/client.go index d70ad24110..1eaef48c60 100644 --- a/config/client.go +++ b/config/client.go @@ -130,7 +130,7 @@ func GenerateClientConfig(c *model.Config, telemetryID string, license *model.Li props["ExperimentalSharedChannels"] = "false" props["CollapsedThreads"] = *c.ServiceSettings.CollapsedThreads props["EnableCustomGroups"] = "false" - props["InsightsEnabled"] = "false" + props["InsightsEnabled"] = strconv.FormatBool(c.FeatureFlags.InsightsEnabled) props["PostPriority"] = strconv.FormatBool(*c.ServiceSettings.PostPriority) if license != nil { @@ -206,10 +206,6 @@ func GenerateClientConfig(c *model.Config, telemetryID string, license *model.Li if license.SkuShortName == model.LicenseShortSkuProfessional || license.SkuShortName == model.LicenseShortSkuEnterprise { props["EnableCustomGroups"] = strconv.FormatBool(*c.ServiceSettings.EnableCustomGroups) } - - if (license.SkuShortName == model.LicenseShortSkuProfessional || license.SkuShortName == model.LicenseShortSkuEnterprise) && c.FeatureFlags.InsightsEnabled { - props["InsightsEnabled"] = "true" - } } return props diff --git a/config/client_test.go b/config/client_test.go index e32834136c..4c23801424 100644 --- a/config/client_test.go +++ b/config/client_test.go @@ -195,7 +195,7 @@ func TestGetClientConfig(t *testing.T) { SkuShortName: "other", }, map[string]string{ - "InsightsEnabled": "false", + "InsightsEnabled": "true", }, }, {