From e64cdfb34bda65cdf06dc4cace581929d9d62016 Mon Sep 17 00:00:00 2001 From: Scott Bishel Date: Mon, 26 Aug 2024 16:03:17 -0600 Subject: [PATCH] MM-58066-Use Client Config to determine AppsEnabled (#27872) * remove enabling apps plugin by default * use client config to determine creating app bindings. * update the way dispatch is made * updated type setting * fixed unit test * prevent a nil check * dispatch batch --------- Co-authored-by: Mattermost Build --- server/config/client.go | 1 + webapp/channels/src/actions/websocket_actions.jsx | 4 ++-- webapp/channels/src/actions/websocket_actions.test.jsx | 3 +++ .../src/packages/mattermost-redux/src/actions/general.ts | 8 ++++++-- webapp/platform/types/src/config.ts | 1 + 5 files changed, 13 insertions(+), 4 deletions(-) diff --git a/server/config/client.go b/server/config/client.go index 5151f6f4e0a..77110debd1c 100644 --- a/server/config/client.go +++ b/server/config/client.go @@ -302,6 +302,7 @@ func GenerateLimitedClientConfig(c *model.Config, telemetryID string, license *m props["HasImageProxy"] = strconv.FormatBool(*c.ImageProxySettings.Enable) props["PluginsEnabled"] = strconv.FormatBool(*c.PluginSettings.Enable) + props["AppsPluginEnabled"] = strconv.FormatBool(*c.PluginSettings.Enable && c.PluginSettings.PluginStates[model.PluginIdApps] != nil && c.PluginSettings.PluginStates[model.PluginIdApps].Enable) props["PasswordMinimumLength"] = strconv.Itoa(*c.PasswordSettings.MinimumLength) props["PasswordRequireLowercase"] = strconv.FormatBool(*c.PasswordSettings.Lowercase) diff --git a/webapp/channels/src/actions/websocket_actions.jsx b/webapp/channels/src/actions/websocket_actions.jsx index 61e04a69aa2..aaf8d9ece73 100644 --- a/webapp/channels/src/actions/websocket_actions.jsx +++ b/webapp/channels/src/actions/websocket_actions.jsx @@ -66,7 +66,7 @@ import { import {removeNotVisibleUsers} from 'mattermost-redux/actions/websocket'; import {Client4} from 'mattermost-redux/client'; import {General, Permissions} from 'mattermost-redux/constants'; -import {appsFeatureFlagEnabled} from 'mattermost-redux/selectors/entities/apps'; +import {appsEnabled} from 'mattermost-redux/selectors/entities/apps'; import { getChannel, getChannelMembersInChannels, @@ -230,7 +230,7 @@ export function reconnect() { const mostRecentId = getMostRecentPostIdInChannel(state, currentChannelId); const mostRecentPost = getPost(state, mostRecentId); - if (appsFeatureFlagEnabled(state)) { + if (appsEnabled(state)) { dispatch(handleRefreshAppsBindings()); } diff --git a/webapp/channels/src/actions/websocket_actions.test.jsx b/webapp/channels/src/actions/websocket_actions.test.jsx index 5b3485f3ad3..2ee1f0c94b0 100644 --- a/webapp/channels/src/actions/websocket_actions.test.jsx +++ b/webapp/channels/src/actions/websocket_actions.test.jsx @@ -86,6 +86,9 @@ jest.mock('plugins', () => ({ let mockState = { entities: { + apps: { + enablePlugin: false, + }, users: { currentUserId: 'currentUserId', profiles: { diff --git a/webapp/channels/src/packages/mattermost-redux/src/actions/general.ts b/webapp/channels/src/packages/mattermost-redux/src/actions/general.ts index e87c38d99b9..a4da3c15fed 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/actions/general.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/actions/general.ts @@ -1,11 +1,13 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. +import {batchActions} from 'redux-batched-actions'; + import {LogLevel} from '@mattermost/types/client4'; import type {ClientConfig} from '@mattermost/types/config'; import type {SystemSetting} from '@mattermost/types/general'; -import {GeneralTypes} from 'mattermost-redux/action_types'; +import {AppsTypes, GeneralTypes} from 'mattermost-redux/action_types'; import {Client4} from 'mattermost-redux/client'; import type {ActionFuncAsync} from 'mattermost-redux/types/actions'; @@ -26,7 +28,9 @@ export function getClientConfig(): ActionFuncAsync { Client4.setEnableLogging(data.EnableDeveloper === 'true'); Client4.setDiagnosticId(data.DiagnosticId); - dispatch({type: GeneralTypes.CLIENT_CONFIG_RECEIVED, data}); + const type = data.AppsPluginEnabled === 'true' ? AppsTypes.APPS_PLUGIN_ENABLED : AppsTypes.APPS_PLUGIN_DISABLED; + const actions = [{type: GeneralTypes.CLIENT_CONFIG_RECEIVED, data}, {type}]; + dispatch(batchActions(actions)); return {data}; }; diff --git a/webapp/platform/types/src/config.ts b/webapp/platform/types/src/config.ts index c928f6f7507..ada10b0c99e 100644 --- a/webapp/platform/types/src/config.ts +++ b/webapp/platform/types/src/config.ts @@ -11,6 +11,7 @@ export type ClientConfig = { AndroidLatestVersion: string; AndroidMinVersion: string; AppDownloadLink: string; + AppsPluginEnabled: string; AsymmetricSigningPublicKey: string; AvailableLocales: string; BannerColor: string;