Skip to content

Commit

Permalink
[MM-59483] Remove legacy preload and custom login code (#3174)
Browse files Browse the repository at this point in the history
* Remove legacy preload script code

* Remove custom login code

* FIx i18n
  • Loading branch information
devinbinnie authored Oct 25, 2024
1 parent 14bb75e commit 6d37cc2
Show file tree
Hide file tree
Showing 26 changed files with 72 additions and 1,040 deletions.
3 changes: 0 additions & 3 deletions i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@
"main.menus.app.view.developerModeDisableContextMenu": "Disable Context Menu",
"main.menus.app.view.developerModeDisableNotificationStorage": "Disable Notification Storage",
"main.menus.app.view.developerModeDisableUserActivityMonitor": "Disable User Activity Monitor",
"main.menus.app.view.developerModeForceLegacyAPI": "Force Legacy API",
"main.menus.app.view.developerModeForceNewAPI": "Force New API",
"main.menus.app.view.devToolsAppWrapper": "Developer Tools for Application Wrapper",
"main.menus.app.view.devToolsCurrentCallWidget": "Developer Tools for Call Widget",
"main.menus.app.view.devToolsCurrentServer": "Developer Tools for Current Server",
Expand Down Expand Up @@ -164,7 +162,6 @@
"renderer.components.errorView.troubleshooting.browserView.canReachFromBrowserWindow": "You can reach <link>{url}</link> from a browser window.",
"renderer.components.errorView.troubleshooting.computerIsConnected": "Your computer is connected to the internet.",
"renderer.components.errorView.troubleshooting.urlIsCorrect.appNameIsCorrect": "The {appName} URL <link>{url}</link> is correct",
"renderer.components.extraBar.back": "Back",
"renderer.components.input.required": "This field is required",
"renderer.components.mainPage.contextMenu.ariaLabel": "Context menu",
"renderer.components.mainPage.titleBar": "{appName}",
Expand Down
12 changes: 0 additions & 12 deletions src/common/communication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,11 @@ export const PLAY_SOUND = 'play_sound';
export const GET_DOWNLOAD_LOCATION = 'get_download_location';

export const UPDATE_MENTIONS = 'update_mentions';
export const IS_UNREAD = 'is_unread';
export const UNREAD_RESULT = 'unread_result';
export const UNREADS_AND_MENTIONS = 'unreads-and-mentions';
export const SESSION_EXPIRED = 'session_expired';

export const REACT_APP_INITIALIZED = 'react-app-initialized';

export const TOGGLE_BACK_BUTTON = 'toggle-back-button';

export const SHOW_SETTINGS_WINDOW = 'show-settings-window';

export const LOADING_SCREEN_ANIMATION_FINISHED = 'loading-screen-animation-finished';
Expand Down Expand Up @@ -93,8 +89,6 @@ export const CHECK_FOR_UPDATES = 'check-for-updates';
export const NO_UPDATE_AVAILABLE = 'no-update-available';

export const BROWSER_HISTORY_PUSH = 'browser-history-push';
export const APP_LOGGED_IN = 'app-logged-in';
export const APP_LOGGED_OUT = 'app-logged-out';
export const TAB_LOGIN_CHANGED = 'tab-login-changed';

export const GET_AVAILABLE_SPELL_CHECKER_LANGUAGES = 'get-available-spell-checker-languages';
Expand All @@ -118,13 +112,11 @@ export const VIEW_FINISHED_RESIZING = 'view-finished-resizing';

// Calls
export const GET_DESKTOP_SOURCES = 'get-desktop-sources';
export const DESKTOP_SOURCES_RESULT = 'desktop-sources-result';
export const DESKTOP_SOURCES_MODAL_REQUEST = 'desktop-sources-modal-request';
export const CALLS_JOIN_CALL = 'calls-join-call';
export const CALLS_LEAVE_CALL = 'calls-leave-call';
export const CALLS_WIDGET_RESIZE = 'calls-widget-resize';
export const CALLS_WIDGET_SHARE_SCREEN = 'calls-widget-share-screen';
export const CALLS_WIDGET_CHANNEL_LINK_CLICK = 'calls-widget-channel-link-click';
export const CALLS_LINK_CLICK = 'calls-link-click';
export const CALLS_JOINED_CALL = 'calls-joined-call';
export const CALLS_POPOUT_FOCUS = 'calls-popout-focus';
Expand Down Expand Up @@ -189,14 +181,10 @@ export const OPEN_WINDOWS_CAMERA_PREFERENCES = 'open-windows-camera-preferences'
export const OPEN_WINDOWS_MICROPHONE_PREFERENCES = 'open-windows-microphone-preferences';
export const GET_MEDIA_ACCESS_STATUS = 'get-media-access-status';

// Legacy code remove signal
export const LEGACY_OFF = 'legacy-off';

export const GET_NONCE = 'get-nonce';

export const DEVELOPER_MODE_UPDATED = 'developer-mode-updated';
export const IS_DEVELOPER_MODE_ENABLED = 'is-developer-mode-enabled';
export const GET_DEVELOPER_MODE_SETTING = 'get-developer-mode-setting';

export const METRICS_SEND = 'metrics-send';
export const METRICS_RECEIVE = 'metrics-receive';
Expand Down
15 changes: 0 additions & 15 deletions src/common/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export const MAX_LOADING_SCREEN_SECONDS = 4 * SECOND;

export const TAB_BAR_HEIGHT = 40;
export const TAB_BAR_PADDING = 4;
export const BACK_BAR_HEIGHT = 36;
export const THREE_DOT_MENU_WIDTH = 40;
export const THREE_DOT_MENU_WIDTH_MAC = 80;
export const MENU_SHADOW_WIDTH = 24;
Expand Down Expand Up @@ -55,20 +54,6 @@ export const URLValidationStatus = {
URLUpdated: 'URL_UPDATED',
};

// supported custom login paths (oath, saml)
export const customLoginRegexPaths = [
/^\/oauth\/authorize$/i,
/^\/oauth\/deauthorize$/i,
/^\/oauth\/access_token$/i,
/^\/oauth\/[A-Za-z0-9]+\/complete$/i,
/^\/oauth\/[A-Za-z0-9]+\/login$/i,
/^\/oauth\/[A-Za-z0-9]+\/signup$/i,
/^\/api\/v3\/oauth\/[A-Za-z0-9]+\/complete$/i,
/^\/signup\/[A-Za-z0-9]+\/complete$/i,
/^\/login\/[A-Za-z0-9]+\/complete$/i,
/^\/login\/sso\/saml$/i,
];

export const nonTeamUrlPaths = [
'plugins',
'signup',
Expand Down
40 changes: 0 additions & 40 deletions src/common/utils/url.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
isValidURI,
parseURL,
isInternalURL,
isCustomLoginURL,
isCallsPopOutURL,
isTrustedURL,
} from 'common/utils/url';
Expand Down Expand Up @@ -204,45 +203,6 @@ describe('common/utils/url', () => {
});
});

describe('isCustomLoginURL', () => {
it('should match correct URL', () => {
expect(isCustomLoginURL(
new URL('http://server.com/oauth/authorize'),
new URL('http://server.com'),
)).toBe(true);
});
it('should not match incorrect URL', () => {
expect(isCustomLoginURL(
new URL('http://server.com/oauth/notauthorize'),
new URL('http://server.com'),
)).toBe(false);
});
it('should not match base URL', () => {
expect(isCustomLoginURL(
new URL('http://server.com/'),
new URL('http://server.com'),
)).toBe(false);
});
it('should match with subpath', () => {
expect(isCustomLoginURL(
new URL('http://server.com/subpath/oauth/authorize'),
new URL('http://server.com/subpath'),
)).toBe(true);
});
it('should not match with different subpath', () => {
expect(isCustomLoginURL(
new URL('http://server.com/subpath/oauth/authorize'),
new URL('http://server.com/different/subpath'),
)).toBe(false);
});
it('should not match with oauth subpath', () => {
expect(isCustomLoginURL(
new URL('http://server.com/oauth/authorize'),
new URL('http://server.com/oauth/authorize'),
)).toBe(false);
});
});

describe('isCallsPopOutURL', () => {
it('should match correct URL', () => {
expect(isCallsPopOutURL(
Expand Down
18 changes: 1 addition & 17 deletions src/common/utils/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import {isHttpsUri, isHttpUri, isUri} from 'valid-url';

import buildConfig from 'common/config/buildConfig';
import {customLoginRegexPaths, nonTeamUrlPaths, CALLS_PLUGIN_ID} from 'common/utils/constants';
import {nonTeamUrlPaths, CALLS_PLUGIN_ID} from 'common/utils/constants';

export const getFormattedPathName = (pn: string) => (pn.endsWith('/') ? pn : `${pn}/`);
export const parseURL = (inputURL: string | URL) => {
Expand Down Expand Up @@ -77,22 +77,6 @@ export const isTeamUrl = (serverURL: URL, inputURL: URL, withApi?: boolean) => {
}
return !(paths.some((testPath) => isUrlType(testPath, serverURL, inputURL)));
};
export const isCustomLoginURL = (inputURL: URL, serverURL: URL) => {
if (!isTrustedURL(inputURL, serverURL)) {
return false;
}
const subpath = serverURL.pathname;
const urlPath = inputURL.pathname;
const replacement = subpath.endsWith('/') ? '/' : '';
const replacedPath = urlPath.replace(subpath, replacement);
for (const regexPath of customLoginRegexPaths) {
if (replacedPath.match(regexPath)) {
return true;
}
}

return false;
};

export const isCallsPopOutURL = (serverURL: URL, inputURL: URL, callID: string) => {
const matches = inputURL.pathname.match(new RegExp(`^${escapeRegExp(getFormattedPathName(serverURL.pathname))}([A-Za-z0-9-_]+)/`, 'i'));
Expand Down
10 changes: 0 additions & 10 deletions src/main/authManager.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ jest.mock('common/utils/url', () => {
isTrustedURL: (url) => {
return url.toString() === 'http://trustedurl.com/';
},
isCustomLoginURL: (url) => {
return url.toString() === 'http://customloginurl.com/';
},
};
});

Expand Down Expand Up @@ -73,13 +70,6 @@ describe('main/authManager', () => {
expect(authManager.popPermissionModal).not.toBeCalled();
});

it('should popLoginModal when isCustomLoginURL', () => {
ViewManager.getViewByWebContentsId.mockReturnValue({view: {server: {url: new URL('http://customloginurl.com/')}}});
authManager.handleAppLogin({preventDefault: jest.fn()}, {id: 1}, {url: 'http://customloginurl.com/'}, null, jest.fn());
expect(authManager.popLoginModal).toBeCalled();
expect(authManager.popPermissionModal).not.toBeCalled();
});

it('should popLoginModal when has permission', () => {
ViewManager.getViewByWebContentsId.mockReturnValue({view: {server: {url: new URL('http://haspermissionurl.com/')}}});
authManager.handleAppLogin({preventDefault: jest.fn()}, {id: 1}, {url: 'http://haspermissionurl.com/'}, null, jest.fn());
Expand Down
4 changes: 2 additions & 2 deletions src/main/authManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type {AuthenticationResponseDetails, AuthInfo, WebContents, Event} from '

import {Logger} from 'common/log';
import {BASIC_AUTH_PERMISSION} from 'common/permissions';
import {isCustomLoginURL, isTrustedURL, parseURL} from 'common/utils/url';
import {isTrustedURL, parseURL} from 'common/utils/url';
import TrustedOriginsStore from 'main/trustedOrigins';
import {getLocalPreload} from 'main/utils';
import modalManager from 'main/views/modalManager';
Expand Down Expand Up @@ -45,7 +45,7 @@ export class AuthManager {
}

this.loginCallbackMap.set(request.url, callback); // if callback is undefined set it to null instead so we know we have set it up with no value
if (isTrustedURL(parsedURL, serverURL) || isCustomLoginURL(parsedURL, serverURL) || TrustedOriginsStore.checkPermission(parsedURL, BASIC_AUTH_PERMISSION)) {
if (isTrustedURL(parsedURL, serverURL) || TrustedOriginsStore.checkPermission(parsedURL, BASIC_AUTH_PERMISSION)) {
this.popLoginModal(request, authInfo);
} else {
this.popPermissionModal(request, authInfo, BASIC_AUTH_PERMISSION);
Expand Down
3 changes: 1 addition & 2 deletions src/main/developerMode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import {ipcMain} from 'electron';
import {EventEmitter} from 'events';

import {DEVELOPER_MODE_UPDATED, IS_DEVELOPER_MODE_ENABLED, UPDATE_PATHS, GET_DEVELOPER_MODE_SETTING} from 'common/communication';
import {DEVELOPER_MODE_UPDATED, IS_DEVELOPER_MODE_ENABLED, UPDATE_PATHS} from 'common/communication';
import JsonFileManager from 'common/JsonFileManager';
import {developerModeJson} from 'main/constants';

Expand All @@ -18,7 +18,6 @@ export class DeveloperMode extends EventEmitter {
this.json = new JsonFileManager(file);

ipcMain.handle(IS_DEVELOPER_MODE_ENABLED, this.enabled);
ipcMain.handle(GET_DEVELOPER_MODE_SETTING, (_, setting) => this.get(setting));
}

enabled = () => process.env.MM_DESKTOP_DEVELOPER_MODE === 'true';
Expand Down
16 changes: 0 additions & 16 deletions src/main/menus/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,22 +214,6 @@ export function createTemplate(config: Config, updateManager: UpdateManager) {
DeveloperMode.toggle('disableContextMenu');
},
},
{
label: localizeMessage('main.menus.app.view.developerModeForceLegacyAPI', 'Force Legacy API'),
type: 'checkbox' as const,
checked: DeveloperMode.get('forceLegacyAPI'),
click() {
DeveloperMode.toggle('forceLegacyAPI');
},
},
{
label: localizeMessage('main.menus.app.view.developerModeForceNewAPI', 'Force New API'),
type: 'checkbox' as const,
checked: DeveloperMode.get('forceNewAPI'),
click() {
DeveloperMode.toggle('forceNewAPI');
},
},
]);
}

Expand Down
Loading

0 comments on commit 6d37cc2

Please sign in to comment.