From f134dadea9b175f845b7d3d7a80255a36fa1820e Mon Sep 17 00:00:00 2001 From: Guilherme Gazzo Date: Mon, 18 Sep 2023 12:31:28 -0300 Subject: [PATCH] remove connectToCloud option --- .../functions/checkUserHasCloudLogin.ts | 4 +-- .../server/functions/connectWorkspace.ts | 7 ----- .../server/functions/disconnectWorkspace.ts | 17 ++--------- .../functions/getUserCloudAccessToken.ts | 4 +-- .../functions/getWorkspaceAccessToken.ts | 4 +-- .../getWorkspaceAccessTokenWithScope.ts | 4 +-- .../cloud/server/functions/getWorkspaceKey.ts | 4 +-- .../functions/retrieveRegistrationStatus.ts | 2 -- .../functions/startRegisterWorkspace.ts | 4 +-- .../cloud/server/functions/syncWorkspace.ts | 6 ++-- .../app/cloud/server/functions/userLogout.ts | 4 +-- apps/meteor/app/cloud/server/methods.ts | 5 ++-- apps/meteor/client/startup/startup.ts | 4 +-- .../views/admin/cloud/RegisterWorkspace.tsx | 30 ++++--------------- .../components/RegisterWorkspaceMenu.tsx | 9 +----- packages/core-typings/src/ICloud.ts | 1 - 16 files changed, 31 insertions(+), 78 deletions(-) diff --git a/apps/meteor/app/cloud/server/functions/checkUserHasCloudLogin.ts b/apps/meteor/app/cloud/server/functions/checkUserHasCloudLogin.ts index 033f2e3b94da5..a17c71d80dc9c 100644 --- a/apps/meteor/app/cloud/server/functions/checkUserHasCloudLogin.ts +++ b/apps/meteor/app/cloud/server/functions/checkUserHasCloudLogin.ts @@ -3,9 +3,9 @@ import { Users } from '@rocket.chat/models'; import { retrieveRegistrationStatus } from './retrieveRegistrationStatus'; export async function checkUserHasCloudLogin(userId: string) { - const { connectToCloud, workspaceRegistered } = await retrieveRegistrationStatus(); + const { workspaceRegistered } = await retrieveRegistrationStatus(); - if (!connectToCloud || !workspaceRegistered) { + if (!workspaceRegistered) { return false; } diff --git a/apps/meteor/app/cloud/server/functions/connectWorkspace.ts b/apps/meteor/app/cloud/server/functions/connectWorkspace.ts index 3c8a587fa5581..8223522e2723e 100644 --- a/apps/meteor/app/cloud/server/functions/connectWorkspace.ts +++ b/apps/meteor/app/cloud/server/functions/connectWorkspace.ts @@ -1,18 +1,11 @@ -import { Settings } from '@rocket.chat/models'; import { serverFetch as fetch } from '@rocket.chat/server-fetch'; import { SystemLogger } from '../../../../server/lib/logger/system'; import { settings } from '../../../settings/server'; import { getRedirectUri } from './getRedirectUri'; -import { retrieveRegistrationStatus } from './retrieveRegistrationStatus'; import { saveRegistrationData } from './saveRegistrationData'; export async function connectWorkspace(token: string) { - const { connectToCloud } = await retrieveRegistrationStatus(); - if (!connectToCloud) { - await Settings.updateValueById('Register_Server', true); - } - // shouldn't get here due to checking this on the method // but this is just to double check if (!token) { diff --git a/apps/meteor/app/cloud/server/functions/disconnectWorkspace.ts b/apps/meteor/app/cloud/server/functions/disconnectWorkspace.ts index c72a96297f376..d6055063ccfe6 100644 --- a/apps/meteor/app/cloud/server/functions/disconnectWorkspace.ts +++ b/apps/meteor/app/cloud/server/functions/disconnectWorkspace.ts @@ -1,17 +1,4 @@ -import { Settings } from '@rocket.chat/models'; - -import { retrieveRegistrationStatus } from './retrieveRegistrationStatus'; -import { syncWorkspace } from './syncWorkspace'; - +/** @deprecated */ export async function disconnectWorkspace() { - const { connectToCloud } = await retrieveRegistrationStatus(); - if (!connectToCloud) { - return true; - } - - await Settings.updateValueById('Register_Server', false); - - await syncWorkspace(true); - - return true; + throw new Error('Deprecated'); } diff --git a/apps/meteor/app/cloud/server/functions/getUserCloudAccessToken.ts b/apps/meteor/app/cloud/server/functions/getUserCloudAccessToken.ts index d7d87417e3492..bf39a50b62345 100644 --- a/apps/meteor/app/cloud/server/functions/getUserCloudAccessToken.ts +++ b/apps/meteor/app/cloud/server/functions/getUserCloudAccessToken.ts @@ -11,9 +11,9 @@ import { retrieveRegistrationStatus } from './retrieveRegistrationStatus'; import { userLoggedOut } from './userLoggedOut'; export async function getUserCloudAccessToken(userId: string, forceNew = false, scope = '', save = true) { - const { connectToCloud, workspaceRegistered } = await retrieveRegistrationStatus(); + const { workspaceRegistered } = await retrieveRegistrationStatus(); - if (!connectToCloud || !workspaceRegistered) { + if (!workspaceRegistered) { return ''; } diff --git a/apps/meteor/app/cloud/server/functions/getWorkspaceAccessToken.ts b/apps/meteor/app/cloud/server/functions/getWorkspaceAccessToken.ts index 1a69d108ae4cf..2b731ef82757a 100644 --- a/apps/meteor/app/cloud/server/functions/getWorkspaceAccessToken.ts +++ b/apps/meteor/app/cloud/server/functions/getWorkspaceAccessToken.ts @@ -11,9 +11,9 @@ import { retrieveRegistrationStatus } from './retrieveRegistrationStatus'; * @returns string */ export async function getWorkspaceAccessToken(forceNew = false, scope = '', save = true) { - const { connectToCloud, workspaceRegistered } = await retrieveRegistrationStatus(); + const { workspaceRegistered } = await retrieveRegistrationStatus(); - if (!connectToCloud || !workspaceRegistered) { + if (!workspaceRegistered) { return ''; } diff --git a/apps/meteor/app/cloud/server/functions/getWorkspaceAccessTokenWithScope.ts b/apps/meteor/app/cloud/server/functions/getWorkspaceAccessTokenWithScope.ts index 4a0c4b5fe394e..351b4cba20e5b 100644 --- a/apps/meteor/app/cloud/server/functions/getWorkspaceAccessTokenWithScope.ts +++ b/apps/meteor/app/cloud/server/functions/getWorkspaceAccessTokenWithScope.ts @@ -8,11 +8,11 @@ import { removeWorkspaceRegistrationInfo } from './removeWorkspaceRegistrationIn import { retrieveRegistrationStatus } from './retrieveRegistrationStatus'; export async function getWorkspaceAccessTokenWithScope(scope = '') { - const { connectToCloud, workspaceRegistered } = await retrieveRegistrationStatus(); + const { workspaceRegistered } = await retrieveRegistrationStatus(); const tokenResponse = { token: '', expiresAt: new Date() }; - if (!connectToCloud || !workspaceRegistered) { + if (!workspaceRegistered) { return tokenResponse; } diff --git a/apps/meteor/app/cloud/server/functions/getWorkspaceKey.ts b/apps/meteor/app/cloud/server/functions/getWorkspaceKey.ts index f3b6dfc4238aa..639f29402fe9d 100644 --- a/apps/meteor/app/cloud/server/functions/getWorkspaceKey.ts +++ b/apps/meteor/app/cloud/server/functions/getWorkspaceKey.ts @@ -2,9 +2,9 @@ import { settings } from '../../../settings/server'; import { retrieveRegistrationStatus } from './retrieveRegistrationStatus'; export async function getWorkspaceKey() { - const { connectToCloud, workspaceRegistered } = await retrieveRegistrationStatus(); + const { workspaceRegistered } = await retrieveRegistrationStatus(); - if (!connectToCloud || !workspaceRegistered) { + if (!workspaceRegistered) { return false; } diff --git a/apps/meteor/app/cloud/server/functions/retrieveRegistrationStatus.ts b/apps/meteor/app/cloud/server/functions/retrieveRegistrationStatus.ts index 55698f4d27af5..0291534ac6379 100644 --- a/apps/meteor/app/cloud/server/functions/retrieveRegistrationStatus.ts +++ b/apps/meteor/app/cloud/server/functions/retrieveRegistrationStatus.ts @@ -3,7 +3,6 @@ import { Users } from '@rocket.chat/models'; import { settings } from '../../../settings/server'; export async function retrieveRegistrationStatus(): Promise<{ - connectToCloud: boolean; workspaceRegistered: boolean; workspaceId: string; uniqueId: string; @@ -11,7 +10,6 @@ export async function retrieveRegistrationStatus(): Promise<{ email: string; }> { const info = { - connectToCloud: settings.get('Register_Server'), workspaceRegistered: !!settings.get('Cloud_Workspace_Client_Id') && !!settings.get('Cloud_Workspace_Client_Secret'), workspaceId: settings.get('Cloud_Workspace_Id'), uniqueId: settings.get('uniqueID'), diff --git a/apps/meteor/app/cloud/server/functions/startRegisterWorkspace.ts b/apps/meteor/app/cloud/server/functions/startRegisterWorkspace.ts index de9fafc990655..af74fcd7d2116 100644 --- a/apps/meteor/app/cloud/server/functions/startRegisterWorkspace.ts +++ b/apps/meteor/app/cloud/server/functions/startRegisterWorkspace.ts @@ -8,8 +8,8 @@ import { retrieveRegistrationStatus } from './retrieveRegistrationStatus'; import { syncWorkspace } from './syncWorkspace'; export async function startRegisterWorkspace(resend = false) { - const { workspaceRegistered, connectToCloud } = await retrieveRegistrationStatus(); - if ((workspaceRegistered && connectToCloud) || process.env.TEST_MODE) { + const { workspaceRegistered } = await retrieveRegistrationStatus(); + if (workspaceRegistered || process.env.TEST_MODE) { await syncWorkspace(true); return true; diff --git a/apps/meteor/app/cloud/server/functions/syncWorkspace.ts b/apps/meteor/app/cloud/server/functions/syncWorkspace.ts index 9337fd0a01726..c8a323e40f95a 100644 --- a/apps/meteor/app/cloud/server/functions/syncWorkspace.ts +++ b/apps/meteor/app/cloud/server/functions/syncWorkspace.ts @@ -10,9 +10,9 @@ import { getWorkspaceAccessToken } from './getWorkspaceAccessToken'; import { getWorkspaceLicense } from './getWorkspaceLicense'; import { retrieveRegistrationStatus } from './retrieveRegistrationStatus'; -export async function syncWorkspace(reconnectCheck = false) { - const { workspaceRegistered, connectToCloud } = await retrieveRegistrationStatus(); - if (!workspaceRegistered || (!connectToCloud && !reconnectCheck)) { +export async function syncWorkspace(_reconnectCheck = false) { + const { workspaceRegistered } = await retrieveRegistrationStatus(); + if (!workspaceRegistered) { return false; } diff --git a/apps/meteor/app/cloud/server/functions/userLogout.ts b/apps/meteor/app/cloud/server/functions/userLogout.ts index e03f96df679df..7dd4aa094535a 100644 --- a/apps/meteor/app/cloud/server/functions/userLogout.ts +++ b/apps/meteor/app/cloud/server/functions/userLogout.ts @@ -7,9 +7,9 @@ import { retrieveRegistrationStatus } from './retrieveRegistrationStatus'; import { userLoggedOut } from './userLoggedOut'; export async function userLogout(userId: string): Promise { - const { connectToCloud, workspaceRegistered } = await retrieveRegistrationStatus(); + const { workspaceRegistered } = await retrieveRegistrationStatus(); - if (!connectToCloud || !workspaceRegistered) { + if (!workspaceRegistered) { return ''; } diff --git a/apps/meteor/app/cloud/server/methods.ts b/apps/meteor/app/cloud/server/methods.ts index d2fbac1af8815..ba1432f1b9a73 100644 --- a/apps/meteor/app/cloud/server/methods.ts +++ b/apps/meteor/app/cloud/server/methods.ts @@ -19,7 +19,6 @@ declare module '@rocket.chat/ui-contexts' { // eslint-disable-next-line @typescript-eslint/naming-convention interface ServerMethods { 'cloud:checkRegisterStatus': () => { - connectToCloud: boolean; workspaceRegistered: boolean; workspaceId: string; uniqueId: string; @@ -151,7 +150,9 @@ Meteor.methods({ }); } - return disconnectWorkspace(); + await disconnectWorkspace(); + + return false; }, async 'cloud:reconnectWorkspace'() { const uid = Meteor.userId(); diff --git a/apps/meteor/client/startup/startup.ts b/apps/meteor/client/startup/startup.ts index 440b55ce5e6d2..6b2b66ec69d79 100644 --- a/apps/meteor/client/startup/startup.ts +++ b/apps/meteor/client/startup/startup.ts @@ -72,11 +72,11 @@ Meteor.startup(() => { } const { - registrationStatus: { connectToCloud, workspaceRegistered }, + registrationStatus: { workspaceRegistered }, } = await sdk.rest.get('/v1/cloud.registrationStatus'); c.stop(); - if (connectToCloud === true && workspaceRegistered !== true) { + if (workspaceRegistered !== true) { banners.open({ id: 'cloud-registration', title: () => t('Cloud_registration_pending_title'), diff --git a/apps/meteor/client/views/admin/cloud/RegisterWorkspace.tsx b/apps/meteor/client/views/admin/cloud/RegisterWorkspace.tsx index 694d437de8d30..e3e1f474cb912 100644 --- a/apps/meteor/client/views/admin/cloud/RegisterWorkspace.tsx +++ b/apps/meteor/client/views/admin/cloud/RegisterWorkspace.tsx @@ -16,7 +16,6 @@ const RegisterWorkspace = () => { const { data: registrationStatusData, isLoading, isError, refetch } = useRegistrationStatus(); const isWorkspaceRegistered = registrationStatusData?.registrationStatus?.workspaceRegistered ?? false; - const isConnectedToCloud = registrationStatusData?.registrationStatus?.connectToCloud ?? false; if (isLoading || isError) { return null; @@ -40,32 +39,11 @@ const RegisterWorkspace = () => { setModal(); }; - const handleRegistrationTag = () => { - if (!isWorkspaceRegistered && !isConnectedToCloud) { - return {t('RegisterWorkspace_NotRegistered_Title')}; - } - if (isWorkspaceRegistered && !isConnectedToCloud) { - return {t('RegisterWorkspace_NotConnected_Title')}; - } - return {t('Workspace_registered')}; - }; - - const handleCardsTitle = () => { - if (!isWorkspaceRegistered && !isConnectedToCloud) { - return t('RegisterWorkspace_NotRegistered_Subtitle'); - } - if (isWorkspaceRegistered && !isConnectedToCloud) { - return t('RegisterWorkspace_NotConnected_Subtitle'); - } - return t('RegisterWorkspace_Registered_Description'); - }; - return ( { - {handleRegistrationTag()} + + {!isWorkspaceRegistered && {t('RegisterWorkspace_NotRegistered_Title')}} + {isWorkspaceRegistered && {t('Workspace_registered')}} + - {handleCardsTitle()} + {isWorkspaceRegistered && t('RegisterWorkspace_NotRegistered_Subtitle')} + {!isWorkspaceRegistered && t('RegisterWorkspace_Registered_Description')} diff --git a/apps/meteor/client/views/admin/cloud/components/RegisterWorkspaceMenu.tsx b/apps/meteor/client/views/admin/cloud/components/RegisterWorkspaceMenu.tsx index d5b0ec7cf7711..9163e5e30af52 100644 --- a/apps/meteor/client/views/admin/cloud/components/RegisterWorkspaceMenu.tsx +++ b/apps/meteor/client/views/admin/cloud/components/RegisterWorkspaceMenu.tsx @@ -8,7 +8,6 @@ import RegisteredWorkspaceModal from '../modals/RegisteredWorkspaceModal'; type RegisterWorkspaceMenuProps = { isWorkspaceRegistered: boolean | string; - isConnectedToCloud: boolean | string; onClick: () => void; onClickOfflineRegistration: () => void; onStatusChange?: () => void; @@ -16,7 +15,6 @@ type RegisterWorkspaceMenuProps = { const RegisterWorkspaceMenu = ({ isWorkspaceRegistered, - isConnectedToCloud, onClick, onClickOfflineRegistration, onStatusChange, @@ -33,7 +31,7 @@ const RegisterWorkspaceMenu = ({ return ( - {isWorkspaceRegistered && isConnectedToCloud && ( + {isWorkspaceRegistered && ( <> - )} {!isWorkspaceRegistered && ( <> diff --git a/packages/core-typings/src/ICloud.ts b/packages/core-typings/src/ICloud.ts index ce6b97ce7d773..6710e7ced9d29 100644 --- a/packages/core-typings/src/ICloud.ts +++ b/packages/core-typings/src/ICloud.ts @@ -1,5 +1,4 @@ export type CloudRegistrationStatus = { - connectToCloud: boolean; email: string; token: string; uniqueId: string;