From 2a119ba07bc3e06385fd22f7efc3bfc7fb2bbc3f Mon Sep 17 00:00:00 2001 From: Avinash Lingaloo <> Date: Mon, 14 Jun 2021 09:59:38 +0400 Subject: [PATCH] MM_36205 : Code clean up --- app/constants/authentication.ts | 12 ++++++++++ app/constants/index.ts | 2 ++ app/constants/view.ts | 6 ----- app/screens/index.tsx | 17 --------------- app/screens/login_options/gitlab.tsx | 4 ++-- app/screens/login_options/google.tsx | 4 ++-- app/screens/login_options/office365.tsx | 4 ++-- app/screens/login_options/open_id.tsx | 4 ++-- app/screens/login_options/saml.tsx | 4 ++-- app/screens/sso/index.tsx | 29 +++++++++++++------------ app/screens/sso/sso_with_webview.tsx | 17 +++------------ 11 files changed, 42 insertions(+), 61 deletions(-) create mode 100644 app/constants/authentication.ts diff --git a/app/constants/authentication.ts b/app/constants/authentication.ts new file mode 100644 index 0000000000..71e7373343 --- /dev/null +++ b/app/constants/authentication.ts @@ -0,0 +1,12 @@ +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. +// See LICENSE.txt for license information. + +import keyMirror from '@utils/key_mirror'; + +export default keyMirror({ + GITLAB: null, + GOOGLE: null, + OFFICE365: null, + OPENID: null, + SAML: null, +}); diff --git a/app/constants/index.ts b/app/constants/index.ts index cab4c0ba59..ed9020ecb0 100644 --- a/app/constants/index.ts +++ b/app/constants/index.ts @@ -2,6 +2,7 @@ // See LICENSE.txt for license information. import Attachment from './attachment'; +import Authentication from './authentication'; import Database from './database'; import DeepLink from './deep_linking'; import Device from './device'; @@ -16,6 +17,7 @@ import WebsocketEvents from './websocket'; export { Attachment, + Authentication, Database, DeepLink, Device, diff --git a/app/constants/view.ts b/app/constants/view.ts index a5c0ca465f..f049705255 100644 --- a/app/constants/view.ts +++ b/app/constants/view.ts @@ -76,12 +76,6 @@ const ViewTypes = keyMirror({ REMOVE_LAST_CHANNEL_FOR_TEAM: null, - GITLAB: null, - GOOGLE: null, - OFFICE365: null, - OPENID: null, - SAML: null, - SET_INITIAL_POST_VISIBILITY: null, RECEIVED_FOCUSED_POST: null, LOADING_POSTS: null, diff --git a/app/screens/index.tsx b/app/screens/index.tsx index 13b8a02773..8a55e170ba 100644 --- a/app/screens/index.tsx +++ b/app/screens/index.tsx @@ -37,23 +37,6 @@ const withIntl = (Screen: React.ComponentType) => { } } -const withDatabaseProvider = async (Screens: React.ComponentType) => { - - const databaseClient = new DatabaseManager() - const serverDatabase = await databaseClient.getActiveServerDatabase(); - - if(!serverDatabase){ - // server database has not been set yet - return (); - } - return ( - - - - ) - -} - Navigation.setLazyComponentRegistrator((screenName) => { let screen: any|undefined; let extraStyles: StyleProp; diff --git a/app/screens/login_options/gitlab.tsx b/app/screens/login_options/gitlab.tsx index 965e7cd1df..8094f7ce15 100644 --- a/app/screens/login_options/gitlab.tsx +++ b/app/screens/login_options/gitlab.tsx @@ -6,7 +6,7 @@ import {Image, Text} from 'react-native'; import Button from 'react-native-button'; import LocalConfig from '@assets/config.json'; -import ViewTypes from '@constants/view'; +import {Authentication} from '@constants'; import {makeStyleSheetFromTheme} from '@utils/theme'; const GitLabOption = ({config, onPress, theme}: LoginOptionWithConfigProps) => { @@ -14,7 +14,7 @@ const GitLabOption = ({config, onPress, theme}: LoginOptionWithConfigProps) => { const forceHideFromLocal = LocalConfig.HideGitLabLoginExperimental; const handlePress = () => { - onPress(ViewTypes.GITLAB); + onPress(Authentication.GITLAB); }; if (!forceHideFromLocal && config.EnableSignUpWithGitLab === 'true') { diff --git a/app/screens/login_options/google.tsx b/app/screens/login_options/google.tsx index d6548d7fd3..7a80eb832a 100644 --- a/app/screens/login_options/google.tsx +++ b/app/screens/login_options/google.tsx @@ -6,14 +6,14 @@ import {Image} from 'react-native'; import Button from 'react-native-button'; import FormattedText from '@components/formatted_text'; -import ViewTypes from '@constants/view'; +import {Authentication} from '@constants'; import {makeStyleSheetFromTheme} from '@utils/theme'; const GoogleOption = ({config, onPress, theme}: LoginOptionWithConfigProps) => { const styles = getStyleSheet(theme); const handlePress = () => { - onPress(ViewTypes.GOOGLE); + onPress(Authentication.GOOGLE); }; if (config.EnableSignUpWithGoogle === 'true') { diff --git a/app/screens/login_options/office365.tsx b/app/screens/login_options/office365.tsx index c9b8fc3dde..92fde8aefa 100644 --- a/app/screens/login_options/office365.tsx +++ b/app/screens/login_options/office365.tsx @@ -6,7 +6,7 @@ import Button from 'react-native-button'; import LocalConfig from '@assets/config.json'; import FormattedText from '@components/formatted_text'; -import ViewTypes from '@constants/view'; +import {Authentication} from '@constants'; import {makeStyleSheetFromTheme} from '@utils/theme'; const Office365Option = ({config, license, onPress, theme}: LoginOptionWithConfigAndLicenseProps) => { @@ -16,7 +16,7 @@ const Office365Option = ({config, license, onPress, theme}: LoginOptionWithConfi license.Office365OAuth === 'true'; const handlePress = () => { - onPress(ViewTypes.OFFICE365); + onPress(Authentication.OFFICE365); }; if (!forceHideFromLocal && o365Enabled) { diff --git a/app/screens/login_options/open_id.tsx b/app/screens/login_options/open_id.tsx index c360876018..24aa4937c7 100644 --- a/app/screens/login_options/open_id.tsx +++ b/app/screens/login_options/open_id.tsx @@ -5,7 +5,7 @@ import React from 'react'; import Button from 'react-native-button'; import FormattedText from '@components/formatted_text'; -import ViewTypes from '@constants/view'; +import {Authentication} from '@constants'; import {isMinimumServerVersion} from '@utils/helpers'; import {makeStyleSheetFromTheme} from '@utils/theme'; @@ -14,7 +14,7 @@ const OpenIdOption = ({config, license, onPress, theme}: LoginOptionWithConfigAn const openIdEnabled = config.EnableSignUpWithOpenId === 'true' && license.IsLicensed === 'true' && isMinimumServerVersion(config.Version, 5, 33, 0); const handlePress = () => { - onPress(ViewTypes.OPENID); + onPress(Authentication.OPENID); }; if (openIdEnabled) { diff --git a/app/screens/login_options/saml.tsx b/app/screens/login_options/saml.tsx index a44505ac80..560aa29268 100644 --- a/app/screens/login_options/saml.tsx +++ b/app/screens/login_options/saml.tsx @@ -6,7 +6,7 @@ import {Text} from 'react-native'; import Button from 'react-native-button'; import LocalConfig from '@assets/config.json'; -import ViewTypes from '@constants/view'; +import {Authentication} from '@constants'; import {makeStyleSheetFromTheme} from '@utils/theme'; const SamlOption = ({config, license, onPress, theme}: LoginOptionWithConfigAndLicenseProps) => { @@ -15,7 +15,7 @@ const SamlOption = ({config, license, onPress, theme}: LoginOptionWithConfigAndL const enabled = config.EnableSaml === 'true' && license.IsLicensed === 'true' && license.SAML === 'true'; const handlePress = () => { - onPress(ViewTypes.SAML); + onPress(Authentication.SAML); }; if (!forceHideFromLocal && enabled) { diff --git a/app/screens/sso/index.tsx b/app/screens/sso/index.tsx index 836b83b6d4..aa22ba02d1 100644 --- a/app/screens/sso/index.tsx +++ b/app/screens/sso/index.tsx @@ -1,18 +1,17 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. -import {Client4} from '@client/rest'; -import ViewTypes from '@constants/view'; -import emmProvider from '@init/emm_provider'; +import React from 'react'; +import {useIntl} from 'react-intl'; +import {Client4} from '@client/rest'; +import {Authentication} from '@constants'; +import {useManagedConfig} from '@mattermost/react-native-emm'; import {scheduleExpiredNotification} from '@requests/remote/push_notification'; import {ssoLogin} from '@requests/remote/user'; - import {resetToChannel} from '@screens/navigation'; import {ErrorApi} from '@typings/api/client4'; import {isMinimumServerVersion} from '@utils/helpers'; -import React from 'react'; -import {useIntl} from 'react-intl'; import SSOWithRedirectURL from './sso_with_redirect_url'; import SSOWithWebView from './sso_with_webview'; @@ -27,31 +26,33 @@ interface SSOProps { const SSO = ({config, serverUrl, ssoType, theme}: SSOProps) => { const intl = useIntl(); + const managedConfig = useManagedConfig(); + const [loginError, setLoginError] = React.useState(''); let completeUrlPath = ''; let loginUrl = ''; switch (ssoType) { - case ViewTypes.GOOGLE: { + case Authentication.GOOGLE: { completeUrlPath = '/signup/google/complete'; loginUrl = `${serverUrl}/oauth/google/mobile_login`; break; } - case ViewTypes.GITLAB: { + case Authentication.GITLAB: { completeUrlPath = '/signup/gitlab/complete'; loginUrl = `${serverUrl}/oauth/gitlab/mobile_login`; break; } - case ViewTypes.SAML: { + case Authentication.SAML: { completeUrlPath = '/login/sso/saml'; loginUrl = `${serverUrl}/login/sso/saml?action=mobile`; break; } - case ViewTypes.OFFICE365: { + case Authentication.OFFICE365: { completeUrlPath = '/signup/office365/complete'; loginUrl = `${serverUrl}/oauth/office365/mobile_login`; break; } - case ViewTypes.OPENID: { + case Authentication.OPENID: { completeUrlPath = '/signup/openid/complete'; loginUrl = `${serverUrl}/oauth/openid/mobile_login`; break; @@ -104,8 +105,8 @@ const SSO = ({config, serverUrl, ssoType, theme}: SSOProps) => { theme, }; - //fixme: where is inAppSessionAuth defined ?? - if (!isSSOWithRedirectURLAvailable || emmProvider.inAppSessionAuth === true) { + if (!isSSOWithRedirectURLAvailable || managedConfig?.inAppSessionAuth === 'true') { + //fixme: force it to get here return ( { return ; }; -export default React.memo(SSO); +export default SSO; diff --git a/app/screens/sso/sso_with_webview.tsx b/app/screens/sso/sso_with_webview.tsx index b67ef56112..6be4d13103 100644 --- a/app/screens/sso/sso_with_webview.tsx +++ b/app/screens/sso/sso_with_webview.tsx @@ -17,8 +17,7 @@ import urlParse from 'url-parse'; import {Client4} from '@client/rest'; import Loading from '@components/loading'; -import StatusBar from '@components/status_bar'; -import ViewTypes from '@constants/view'; +import {Authentication} from '@constants'; import {popTopScreen} from '@screens/navigation'; import {changeOpacity, makeStyleSheetFromTheme} from '@utils/theme'; @@ -69,15 +68,6 @@ interface SSOWithWebViewProps { theme: Partial } -// type CookieResponseType = { -// MMAUTHTOKEN: string | { -// value: string -// }; -// MMCSRF: string | { -// value: string -// }; -// } - function SSOWithWebView({completeUrlPath, loginError, loginUrl, onCSRFToken, onMMToken, serverUrl, ssoType, theme}: SSOWithWebViewProps) { const style = getStyleSheet(theme); const intl = useIntl(); @@ -187,7 +177,7 @@ function SSOWithWebView({completeUrlPath, loginError, loginUrl, onCSRFToken, onM const parsed = urlParse(url); let isLastRedirect = url.includes(completeUrlPath); - if (ssoType === ViewTypes.SAML) { + if (ssoType === Authentication.SAML) { isLastRedirect = isLastRedirect && !parsed.query; } @@ -198,7 +188,7 @@ function SSOWithWebView({completeUrlPath, loginError, loginUrl, onCSRFToken, onM const renderWebView = () => { if (shouldRenderWebView) { - const userAgent = ssoType === ViewTypes.GOOGLE ? 'Mozilla/5.0 (Linux; Android 10; Android SDK built for x86 Build/LMY48X) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/81.0.4044.117 Mobile Safari/608.2.11' : undefined; + const userAgent = ssoType === Authentication.GOOGLE ? 'Mozilla/5.0 (Linux; Android 10; Android SDK built for x86 Build/LMY48X) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/81.0.4044.117 Mobile Safari/608.2.11' : undefined; return ( - {error || loginError ? ( {error || loginError}