From 964b8d3b3621d5ce7cae360663ea20ecde9dec5f Mon Sep 17 00:00:00 2001 From: Avinash Lingaloo <> Date: Mon, 14 Jun 2021 20:23:19 +0400 Subject: [PATCH] fix : code clean up from reviews --- android/app/src/main/AndroidManifest.xml | 1 + app/components/loading/index.tsx | 3 +-- app/components/status_bar/index.tsx | 24 --------------------- app/constants/index.ts | 4 ++-- app/constants/{authentication.ts => sso.ts} | 0 app/mattermost.ts | 1 - app/queries/preference.ts | 15 ------------- app/requests/remote/user.ts | 8 +------ app/screens/login/index.tsx | 2 +- app/screens/login/login.test.js | 2 +- 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 | 12 +++++------ app/screens/sso/sso_with_webview.tsx | 6 +++--- app/utils/database.ts | 6 +++--- ios/Mattermost.xcodeproj/project.pbxproj | 6 ++++-- 19 files changed, 33 insertions(+), 77 deletions(-) delete mode 100644 app/components/status_bar/index.tsx rename app/constants/{authentication.ts => sso.ts} (100%) delete mode 100644 app/queries/preference.ts diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 1cc02c6422..b46df195ca 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -31,6 +31,7 @@ android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode" android:windowSoftInputMode="adjustResize" android:launchMode="singleTask" + android:taskAffinity="" > diff --git a/app/components/loading/index.tsx b/app/components/loading/index.tsx index d5f65a273e..4fcb96b509 100644 --- a/app/components/loading/index.tsx +++ b/app/components/loading/index.tsx @@ -2,7 +2,6 @@ // See LICENSE.txt for license information. import React from 'react'; - import {ActivityIndicator, StyleSheet, View, ViewStyle} from 'react-native'; type LoadingProps = { @@ -11,7 +10,7 @@ type LoadingProps = { style?: ViewStyle, } -const Loading = ({size = 'large', color = 'grey', style = {}}: LoadingProps) => { +const Loading = ({size = 'large', color = 'grey', style}: LoadingProps) => { return ( { - const zTheme: Theme = theme ?? getThemeFromState(); - const color = headerColor ? tinyColor(headerColor) : tinyColor(zTheme.sidebarHeaderBg); - const barStyle: StatusBarStyle = color.isLight() && Platform.OS === 'ios' ? 'dark-content' : 'light-content'; - - return ( - - ); -}; - -export default StatusBar; diff --git a/app/constants/index.ts b/app/constants/index.ts index ed9020ecb0..5fd5a6c60c 100644 --- a/app/constants/index.ts +++ b/app/constants/index.ts @@ -2,7 +2,7 @@ // See LICENSE.txt for license information. import Attachment from './attachment'; -import Authentication from './authentication'; +import SSO from './sso'; import Database from './database'; import DeepLink from './deep_linking'; import Device from './device'; @@ -17,7 +17,7 @@ import WebsocketEvents from './websocket'; export { Attachment, - Authentication, + SSO, Database, DeepLink, Device, diff --git a/app/constants/authentication.ts b/app/constants/sso.ts similarity index 100% rename from app/constants/authentication.ts rename to app/constants/sso.ts diff --git a/app/mattermost.ts b/app/mattermost.ts index b370a66a08..3ca35456a7 100644 --- a/app/mattermost.ts +++ b/app/mattermost.ts @@ -85,7 +85,6 @@ export function componentDidAppearListener({componentId}: ComponentDidAppearEven case 'SettingsSidebar': DeviceEventEmitter.emit(NavigationConstants.BLUR_POST_DRAFT); break; - default: break; } } diff --git a/app/queries/preference.ts b/app/queries/preference.ts deleted file mode 100644 index 965f57e9e5..0000000000 --- a/app/queries/preference.ts +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. -// See LICENSE.txt for license information. - -import {Database, Q} from '@nozbe/watermelondb'; - -import {MM_TABLES} from '@constants/database'; -import Preference from '@typings/database/preference'; - -export const getTheme = async (database: Database) => { - const userTheme = await database.collections.get(MM_TABLES.SERVER.PREFERENCE).query(Q.where('category', 'theme')).fetch() as Preference[]; - if (userTheme?.[0]) { - return userTheme[0].value; - } - return null; -}; diff --git a/app/requests/remote/user.ts b/app/requests/remote/user.ts index 1baeb11510..4464193dd2 100644 --- a/app/requests/remote/user.ts +++ b/app/requests/remote/user.ts @@ -103,7 +103,7 @@ export const login = async ({ldapOnly = false, loginId, mfaToken, password}: Log }; export const loadMe = async ({deviceToken, user}: LoadMeArgs) => { - let currentUser = user ?? undefined; + let currentUser = user; const {activeServerDatabase, error} = await getActiveServerDatabase(); if (!activeServerDatabase) { @@ -130,12 +130,6 @@ export const loadMe = async ({deviceToken, user}: LoadMeArgs) => { } try { - if (!currentUser) { - return { - error, - currentUser: undefined, - }; - } const analyticsClient = analytics.create(Client4.getUrl()); analyticsClient.setUserId(currentUser.id); analyticsClient.setUserRoles(currentUser.roles); diff --git a/app/screens/login/index.tsx b/app/screens/login/index.tsx index ffe4ca9ff8..a9e3ed9331 100644 --- a/app/screens/login/index.tsx +++ b/app/screens/login/index.tsx @@ -159,7 +159,7 @@ const Login: NavigationFunctionComponent = ({config, license, theme}: LoginProps const goToMfa = () => { const screen = 'MFA'; - const title = intl.formatMessage({id: 'mobile.routes.mfa', defaultMessage: 'Multi-factor Authentication'}); + const title = intl.formatMessage({id: 'mobile.routes.mfa', defaultMessage: 'Multi-factor SSO'}); goToScreen(screen, title, {goToChannel, loginId, password}); }; diff --git a/app/screens/login/login.test.js b/app/screens/login/login.test.js index 84ee6c9935..c06807ca91 100644 --- a/app/screens/login/login.test.js +++ b/app/screens/login/login.test.js @@ -104,7 +104,7 @@ describe('Login', () => { expect(goToScreen). toHaveBeenCalledWith( 'MFA', - 'Multi-factor Authentication', + 'Multi-factor SSO', { goToChannel: expect.anything(), loginId, diff --git a/app/screens/login_options/gitlab.tsx b/app/screens/login_options/gitlab.tsx index 8094f7ce15..9f463dc137 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 {Authentication} from '@constants'; +import {SSO} 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(Authentication.GITLAB); + onPress(SSO.GITLAB); }; if (!forceHideFromLocal && config.EnableSignUpWithGitLab === 'true') { diff --git a/app/screens/login_options/google.tsx b/app/screens/login_options/google.tsx index 7a80eb832a..6879014cdb 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 {Authentication} from '@constants'; +import {SSO} from '@constants'; import {makeStyleSheetFromTheme} from '@utils/theme'; const GoogleOption = ({config, onPress, theme}: LoginOptionWithConfigProps) => { const styles = getStyleSheet(theme); const handlePress = () => { - onPress(Authentication.GOOGLE); + onPress(SSO.GOOGLE); }; if (config.EnableSignUpWithGoogle === 'true') { diff --git a/app/screens/login_options/office365.tsx b/app/screens/login_options/office365.tsx index 92fde8aefa..f71941251f 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 {Authentication} from '@constants'; +import {SSO} 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(Authentication.OFFICE365); + onPress(SSO.OFFICE365); }; if (!forceHideFromLocal && o365Enabled) { diff --git a/app/screens/login_options/open_id.tsx b/app/screens/login_options/open_id.tsx index 24aa4937c7..2392d17d42 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 {Authentication} from '@constants'; +import {SSO} 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(Authentication.OPENID); + onPress(SSO.OPENID); }; if (openIdEnabled) { diff --git a/app/screens/login_options/saml.tsx b/app/screens/login_options/saml.tsx index 560aa29268..2a3a372edd 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 {Authentication} from '@constants'; +import {SSO} 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(Authentication.SAML); + onPress(SSO.SAML); }; if (!forceHideFromLocal && enabled) { diff --git a/app/screens/sso/index.tsx b/app/screens/sso/index.tsx index 908039fc76..e35db60fc5 100644 --- a/app/screens/sso/index.tsx +++ b/app/screens/sso/index.tsx @@ -5,7 +5,7 @@ import React, {useState} from 'react'; import {useIntl} from 'react-intl'; import {Client4} from '@client/rest'; -import {Authentication} from '@constants'; +import {SSO} from '@constants'; import {useManagedConfig} from '@mattermost/react-native-emm'; import {scheduleExpiredNotification} from '@requests/remote/push_notification'; import {ssoLogin} from '@requests/remote/user'; @@ -32,27 +32,27 @@ const SSO = ({config, serverUrl, ssoType, theme}: SSOProps) => { let completeUrlPath = ''; let loginUrl = ''; switch (ssoType) { - case Authentication.GOOGLE: { + case SSO.GOOGLE: { completeUrlPath = '/signup/google/complete'; loginUrl = `${serverUrl}/oauth/google/mobile_login`; break; } - case Authentication.GITLAB: { + case SSO.GITLAB: { completeUrlPath = '/signup/gitlab/complete'; loginUrl = `${serverUrl}/oauth/gitlab/mobile_login`; break; } - case Authentication.SAML: { + case SSO.SAML: { completeUrlPath = '/login/sso/saml'; loginUrl = `${serverUrl}/login/sso/saml?action=mobile`; break; } - case Authentication.OFFICE365: { + case SSO.OFFICE365: { completeUrlPath = '/signup/office365/complete'; loginUrl = `${serverUrl}/oauth/office365/mobile_login`; break; } - case Authentication.OPENID: { + case SSO.OPENID: { completeUrlPath = '/signup/openid/complete'; loginUrl = `${serverUrl}/oauth/openid/mobile_login`; break; diff --git a/app/screens/sso/sso_with_webview.tsx b/app/screens/sso/sso_with_webview.tsx index 569e997d19..3cd054e5f2 100644 --- a/app/screens/sso/sso_with_webview.tsx +++ b/app/screens/sso/sso_with_webview.tsx @@ -17,7 +17,7 @@ import urlParse from 'url-parse'; import {Client4} from '@client/rest'; import Loading from '@components/loading'; -import {Authentication} from '@constants'; +import {SSO} from '@constants'; import {popTopScreen} from '@screens/navigation'; import {changeOpacity, makeStyleSheetFromTheme} from '@utils/theme'; @@ -177,7 +177,7 @@ const SSOWithWebView = ({completeUrlPath, loginError, loginUrl, onCSRFToken, onM const parsed = urlParse(url); let isLastRedirect = url.includes(completeUrlPath); - if (ssoType === Authentication.SAML) { + if (ssoType === SSO.SAML) { isLastRedirect = isLastRedirect && !parsed.query; } @@ -188,7 +188,7 @@ const SSOWithWebView = ({completeUrlPath, loginError, loginUrl, onCSRFToken, onM const renderWebView = () => { if (shouldRenderWebView) { - 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; + const userAgent = ssoType === SSO.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 ( { - const connectionName = displayName ?? urlParse(Client4.getUrl())?.hostname; + const connectionName = displayName ?? urlParse(serverUrl)?.hostname; try { const databaseClient = new DatabaseManager(); diff --git a/ios/Mattermost.xcodeproj/project.pbxproj b/ios/Mattermost.xcodeproj/project.pbxproj index 743a0a4388..86253c3440 100644 --- a/ios/Mattermost.xcodeproj/project.pbxproj +++ b/ios/Mattermost.xcodeproj/project.pbxproj @@ -828,8 +828,9 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; CODE_SIGN_ENTITLEMENTS = Mattermost/Mattermost.entitlements; - CODE_SIGN_IDENTITY = "iPhone Developer"; + CODE_SIGN_IDENTITY = "Apple Development"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 333; DEAD_CODE_STRIPPING = NO; DEVELOPMENT_TEAM = UQ8HT4Q2XM; @@ -870,8 +871,9 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; CODE_SIGN_ENTITLEMENTS = Mattermost/Mattermost.entitlements; - CODE_SIGN_IDENTITY = "iPhone Developer"; + CODE_SIGN_IDENTITY = "Apple Development"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 333; DEAD_CODE_STRIPPING = NO; DEVELOPMENT_TEAM = UQ8HT4Q2XM;