From f51a7d31db3b91ba5dcbf2ddcebceb94f67f359b Mon Sep 17 00:00:00 2001 From: Devin Binnie <52460000+devinbinnie@users.noreply.github.com> Date: Fri, 23 Jun 2023 09:50:39 -0400 Subject: [PATCH] [MM-53294] Fix bad user feedback when plugins are disabled (#2772) --- src/app/serverViewState.test.js | 12 ++++++------ src/app/serverViewState.ts | 2 +- src/main/server/serverInfo.ts | 8 +++++++- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/app/serverViewState.test.js b/src/app/serverViewState.test.js index d4aa0a48..e6415b54 100644 --- a/src/app/serverViewState.test.js +++ b/src/app/serverViewState.test.js @@ -336,7 +336,7 @@ describe('app/serverViewState', () => { beforeEach(() => { MattermostServer.mockImplementation(({url}) => ({url})); ServerInfo.mockImplementation(({url}) => ({ - fetchRemoteInfo: jest.fn().mockImplementation(() => ({ + fetchConfigData: jest.fn().mockImplementation(() => ({ serverVersion: '7.8.0', siteName: 'Mattermost', siteURL: url, @@ -400,7 +400,7 @@ describe('app/serverViewState', () => { it('should attempt HTTP when HTTPS fails, and generate a warning', async () => { ServerInfo.mockImplementation(({url}) => ({ - fetchRemoteInfo: jest.fn().mockImplementation(() => { + fetchConfigData: jest.fn().mockImplementation(() => { if (url.startsWith('https:')) { return undefined; } @@ -420,7 +420,7 @@ describe('app/serverViewState', () => { it('should show a warning when the ping request times out', async () => { ServerInfo.mockImplementation(() => ({ - fetchRemoteInfo: jest.fn().mockImplementation(() => { + fetchConfigData: jest.fn().mockImplementation(() => { throw new Error(); }), })); @@ -432,7 +432,7 @@ describe('app/serverViewState', () => { it('should update the users URL when the Site URL is different', async () => { ServerInfo.mockImplementation(() => ({ - fetchRemoteInfo: jest.fn().mockImplementation(() => { + fetchConfigData: jest.fn().mockImplementation(() => { return { serverVersion: '7.8.0', siteName: 'Mattermost', @@ -448,7 +448,7 @@ describe('app/serverViewState', () => { it('should warn the user when the Site URL is different but unreachable', async () => { ServerInfo.mockImplementation(({url}) => ({ - fetchRemoteInfo: jest.fn().mockImplementation(() => { + fetchConfigData: jest.fn().mockImplementation(() => { if (url === 'https://mainserver.com/') { return undefined; } @@ -468,7 +468,7 @@ describe('app/serverViewState', () => { it('should warn the user when the Site URL already exists as another server', async () => { ServerManager.lookupViewByURL.mockReturnValue({server: {name: 'Server 1', id: 'server-1', url: new URL('https://mainserver.com')}}); ServerInfo.mockImplementation(() => ({ - fetchRemoteInfo: jest.fn().mockImplementation(() => { + fetchConfigData: jest.fn().mockImplementation(() => { return { serverVersion: '7.8.0', siteName: 'Mattermost', diff --git a/src/app/serverViewState.ts b/src/app/serverViewState.ts index 71ea3a2b..9987e7ca 100644 --- a/src/app/serverViewState.ts +++ b/src/app/serverViewState.ts @@ -343,7 +343,7 @@ export class ServerViewState { const server = new MattermostServer({name: 'temp', url: parsedURL.toString()}, false); const serverInfo = new ServerInfo(server); try { - const remoteInfo = await serverInfo.fetchRemoteInfo(); + const remoteInfo = await serverInfo.fetchConfigData(); return remoteInfo; } catch (error) { return undefined; diff --git a/src/main/server/serverInfo.ts b/src/main/server/serverInfo.ts index df354281..f3a5ad00 100644 --- a/src/main/server/serverInfo.ts +++ b/src/main/server/serverInfo.ts @@ -16,11 +16,17 @@ export class ServerInfo { this.remoteInfo = {}; } - fetchRemoteInfo = async () => { + fetchConfigData = async () => { await this.getRemoteInfo( new URL(`${this.server.url.toString()}/api/v4/config/client?format=old`), this.onGetConfig, ); + + return this.remoteInfo; + } + + fetchRemoteInfo = async () => { + await this.fetchConfigData(); await this.getRemoteInfo>( new URL(`${this.server.url.toString()}/api/v4/plugins/webapp`), this.onGetPlugins,