Skip to content

Commit

Permalink
remove connectToCloud
Browse files Browse the repository at this point in the history
  • Loading branch information
ggazzo committed Sep 13, 2023
1 parent fb1bbf7 commit efc9e84
Show file tree
Hide file tree
Showing 13 changed files with 17 additions and 161 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
13 changes: 0 additions & 13 deletions apps/meteor/app/cloud/server/functions/connectWorkspace.ts
Original file line number Diff line number Diff line change
@@ -1,24 +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) {
return new Error('Invalid token; the registration token is required.');
}

const redirectUri = getRedirectUri();

const regInfo = {
Expand Down
6 changes: 0 additions & 6 deletions apps/meteor/app/cloud/server/functions/disconnectWorkspace.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
import { Settings } from '@rocket.chat/models';

import { retrieveRegistrationStatus } from './retrieveRegistrationStatus';
import { syncWorkspace } from './syncWorkspace';

export async function disconnectWorkspace() {
const { connectToCloud } = await retrieveRegistrationStatus();
if (!connectToCloud) {
return true;
}

await Settings.updateValueById('Register_Server', false);

await syncWorkspace();
Expand Down
113 changes: 0 additions & 113 deletions apps/meteor/app/cloud/server/functions/getUserCloudAccessToken.ts

This file was deleted.

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): Promise<string> {
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: true || 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();

return true;
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
1 change: 0 additions & 1 deletion 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
10 changes: 4 additions & 6 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 @@ -41,20 +40,20 @@ const RegisterWorkspace = () => {
};

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

const handleCardsTitle = () => {
if (!isWorkspaceRegistered && !isConnectedToCloud) {
if (!isWorkspaceRegistered) {
return t('RegisterWorkspace_NotRegistered_Subtitle');
}
if (isWorkspaceRegistered && !isConnectedToCloud) {
if (isWorkspaceRegistered) {
return t('RegisterWorkspace_NotConnected_Subtitle');
}
return t('RegisterWorkspace_Registered_Description');
Expand All @@ -65,7 +64,6 @@ const RegisterWorkspace = () => {
<Page.Header title={t('Registration')}>
<RegisterWorkspaceMenu
isWorkspaceRegistered={isWorkspaceRegistered}
isConnectedToCloud={isConnectedToCloud}
onClick={handleRegisterWorkspaceClick}
onStatusChange={refetch}
onClickOfflineRegistration={handleManualWorkspaceRegistrationButton}
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

0 comments on commit efc9e84

Please sign in to comment.