Skip to content

Commit

Permalink
remove connectToCloud option
Browse files Browse the repository at this point in the history
  • Loading branch information
ggazzo committed Sep 18, 2023
1 parent b1c2a4c commit f134dad
Show file tree
Hide file tree
Showing 16 changed files with 31 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
7 changes: 0 additions & 7 deletions apps/meteor/app/cloud/server/functions/connectWorkspace.ts
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
17 changes: 2 additions & 15 deletions apps/meteor/app/cloud/server/functions/disconnectWorkspace.ts
Original file line number Diff line number Diff line change
@@ -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');
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 '';
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 '';
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions apps/meteor/app/cloud/server/functions/getWorkspaceKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@ import { Users } from '@rocket.chat/models';
import { settings } from '../../../settings/server';

export async function retrieveRegistrationStatus(): Promise<{
connectToCloud: boolean;
workspaceRegistered: boolean;
workspaceId: string;
uniqueId: string;
token: string;
email: string;
}> {
const info = {
connectToCloud: settings.get<boolean>('Register_Server'),
workspaceRegistered: !!settings.get('Cloud_Workspace_Client_Id') && !!settings.get('Cloud_Workspace_Client_Secret'),
workspaceId: settings.get<string>('Cloud_Workspace_Id'),
uniqueId: settings.get<string>('uniqueID'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions apps/meteor/app/cloud/server/functions/syncWorkspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions apps/meteor/app/cloud/server/functions/userLogout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import { retrieveRegistrationStatus } from './retrieveRegistrationStatus';
import { userLoggedOut } from './userLoggedOut';

export async function userLogout(userId: string): Promise<string | boolean> {
const { connectToCloud, workspaceRegistered } = await retrieveRegistrationStatus();
const { workspaceRegistered } = await retrieveRegistrationStatus();

if (!connectToCloud || !workspaceRegistered) {
if (!workspaceRegistered) {
return '';
}

Expand Down
5 changes: 3 additions & 2 deletions apps/meteor/app/cloud/server/methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -151,7 +150,9 @@ Meteor.methods<ServerMethods>({
});
}

return disconnectWorkspace();
await disconnectWorkspace();

return false;
},
async 'cloud:reconnectWorkspace'() {
const uid = Meteor.userId();
Expand Down
4 changes: 2 additions & 2 deletions apps/meteor/client/startup/startup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
30 changes: 6 additions & 24 deletions apps/meteor/client/views/admin/cloud/RegisterWorkspace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -40,44 +39,27 @@ const RegisterWorkspace = () => {
setModal(<ManualWorkspaceRegistrationModal onClose={handleModalClose} />);
};

const handleRegistrationTag = () => {
if (!isWorkspaceRegistered && !isConnectedToCloud) {
return <Tag variant='secondary-danger'>{t('RegisterWorkspace_NotRegistered_Title')}</Tag>;
}
if (isWorkspaceRegistered && !isConnectedToCloud) {
return <Tag variant='secondary-danger'>{t('RegisterWorkspace_NotConnected_Title')}</Tag>;
}
return <Tag variant='primary'>{t('Workspace_registered')}</Tag>;
};

const handleCardsTitle = () => {
if (!isWorkspaceRegistered && !isConnectedToCloud) {
return t('RegisterWorkspace_NotRegistered_Subtitle');
}
if (isWorkspaceRegistered && !isConnectedToCloud) {
return t('RegisterWorkspace_NotConnected_Subtitle');
}
return t('RegisterWorkspace_Registered_Description');
};

return (
<Page background='tint'>
<Page.Header title={t('Registration')}>
<RegisterWorkspaceMenu
isWorkspaceRegistered={isWorkspaceRegistered}
isConnectedToCloud={isConnectedToCloud}
onClick={handleRegisterWorkspaceClick}
onStatusChange={refetch}
onClickOfflineRegistration={handleManualWorkspaceRegistrationButton}
/>
</Page.Header>

<Page.ScrollableContentWithShadow>
<Box display='flex'>{handleRegistrationTag()}</Box>
<Box display='flex'>
{!isWorkspaceRegistered && <Tag variant='secondary-danger'>{t('RegisterWorkspace_NotRegistered_Title')}</Tag>}
{isWorkspaceRegistered && <Tag variant='primary'>{t('Workspace_registered')}</Tag>}
</Box>

<Box pb={8}>
<Box fontSize='h3' fontWeight={700}>
{handleCardsTitle()}
{isWorkspaceRegistered && t('RegisterWorkspace_NotRegistered_Subtitle')}
{!isWorkspaceRegistered && t('RegisterWorkspace_Registered_Description')}
</Box>
<RegisterWorkspaceCards />
</Box>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@ import RegisteredWorkspaceModal from '../modals/RegisteredWorkspaceModal';

type RegisterWorkspaceMenuProps = {
isWorkspaceRegistered: boolean | string;
isConnectedToCloud: boolean | string;
onClick: () => void;
onClickOfflineRegistration: () => void;
onStatusChange?: () => void;
};

const RegisterWorkspaceMenu = ({
isWorkspaceRegistered,
isConnectedToCloud,
onClick,
onClickOfflineRegistration,
onStatusChange,
Expand All @@ -33,7 +31,7 @@ const RegisterWorkspaceMenu = ({

return (
<ButtonGroup>
{isWorkspaceRegistered && isConnectedToCloud && (
{isWorkspaceRegistered && (
<>
<Button icon='new-window' role='link' onClick={() => handleLinkClick(CLOUD_CONSOLE_URL)}>
{t('Cloud')}
Expand All @@ -44,11 +42,6 @@ const RegisterWorkspaceMenu = ({
</>
)}

{isWorkspaceRegistered && !isConnectedToCloud && (
<Button primary onClick={onClick}>
{t('ConnectWorkspace_Button')}
</Button>
)}
{!isWorkspaceRegistered && (
<>
<Button onClick={onClickOfflineRegistration}>{t('Cloud_Register_manually')}</Button>
Expand Down
1 change: 0 additions & 1 deletion packages/core-typings/src/ICloud.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export type CloudRegistrationStatus = {
connectToCloud: boolean;
email: string;
token: string;
uniqueId: string;
Expand Down

0 comments on commit f134dad

Please sign in to comment.