From 728eae2cb5252acaa161e6dff1f805fd2e5977e1 Mon Sep 17 00:00:00 2001 From: Christopher Speller Date: Fri, 1 Nov 2024 06:30:25 -0700 Subject: [PATCH] Enable to AI plugin by default (#28770) * Enable to AI plugin by default * Fix tests. --- server/config/diff_test.go | 9 +++++++ server/public/model/config.go | 5 ++++ server/public/model/config_test.go | 33 +++++++++++++++++++++++++ server/public/model/plugin_constants.go | 1 + server/public/model/usage.go | 1 + 5 files changed, 49 insertions(+) diff --git a/server/config/diff_test.go b/server/config/diff_test.go index c794ba0765..4346bfa71f 100644 --- a/server/config/diff_test.go +++ b/server/config/diff_test.go @@ -789,6 +789,9 @@ func TestDiff(t *testing.T) { "com.mattermost.calls": { Enable: true, }, + "mattermost-ai": { + Enable: true, + }, "playbooks": { Enable: true, }, @@ -821,6 +824,9 @@ func TestDiff(t *testing.T) { "com.mattermost.calls": { Enable: true, }, + "mattermost-ai": { + Enable: true, + }, "playbooks": { Enable: true, }, @@ -845,6 +851,9 @@ func TestDiff(t *testing.T) { "com.mattermost.calls": { Enable: true, }, + "mattermost-ai": { + Enable: true, + }, "playbooks": { Enable: true, }, diff --git a/server/public/model/config.go b/server/public/model/config.go index b0d7879503..ef0d3de51d 100644 --- a/server/public/model/config.go +++ b/server/public/model/config.go @@ -3190,6 +3190,11 @@ func (s *PluginSettings) SetDefaults(ls LogSettings) { s.PluginStates[PluginIdPlaybooks] = &PluginState{Enable: true} } + if s.PluginStates[PluginIdAI] == nil { + // Enable the AI plugin by default + s.PluginStates[PluginIdAI] = &PluginState{Enable: true} + } + if s.EnableMarketplace == nil { s.EnableMarketplace = NewPointer(PluginSettingsDefaultEnableMarketplace) } diff --git a/server/public/model/config_test.go b/server/public/model/config_test.go index 82fd7ba64a..1d3fc7c9f3 100644 --- a/server/public/model/config_test.go +++ b/server/public/model/config_test.go @@ -1800,6 +1800,39 @@ func TestConfigDefaultCallsPluginState(t *testing.T) { }) } +func TestConfigDefaultAIPluginState(t *testing.T) { + t.Run("should enable AI plugin by default on self-hosted", func(t *testing.T) { + c1 := Config{} + c1.SetDefaults() + + assert.True(t, c1.PluginSettings.PluginStates["mattermost-ai"].Enable) + }) + + t.Run("should enable AI plugin by default on Cloud", func(t *testing.T) { + os.Setenv("MM_CLOUD_INSTALLATION_ID", "test") + defer os.Unsetenv("MM_CLOUD_INSTALLATION_ID") + c1 := Config{} + c1.SetDefaults() + + assert.True(t, c1.PluginSettings.PluginStates["mattermost-ai"].Enable) + }) + + t.Run("should not re-enable AI plugin after it has been disabled", func(t *testing.T) { + c1 := Config{ + PluginSettings: PluginSettings{ + PluginStates: map[string]*PluginState{ + "mattermost-ai": { + Enable: false, + }, + }, + }, + } + + c1.SetDefaults() + assert.False(t, c1.PluginSettings.PluginStates["mattermost-ai"].Enable) + }) +} + func TestConfigGetMessageRetentionHours(t *testing.T) { tests := []struct { name string diff --git a/server/public/model/plugin_constants.go b/server/public/model/plugin_constants.go index fa7006745f..85e4612af7 100644 --- a/server/public/model/plugin_constants.go +++ b/server/public/model/plugin_constants.go @@ -10,4 +10,5 @@ const ( PluginIdCalls = "com.mattermost.calls" PluginIdNPS = "com.mattermost.nps" PluginIdChannelExport = "com.mattermost.plugin-channel-export" + PluginIdAI = "mattermost-ai" ) diff --git a/server/public/model/usage.go b/server/public/model/usage.go index 413ee2b8e6..1845f2d0c8 100644 --- a/server/public/model/usage.go +++ b/server/public/model/usage.go @@ -23,6 +23,7 @@ var InstalledIntegrationsIgnoredPlugins = map[string]struct{}{ PluginIdCalls: {}, PluginIdNPS: {}, PluginIdChannelExport: {}, + PluginIdAI: {}, } type InstalledIntegration struct {