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 27a98ab
Show file tree
Hide file tree
Showing 13 changed files with 18 additions and 151 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
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export async function syncWorkspace() {
await syncCloudData();
await getWorkspaceLicense();
} catch (error) {
console.error(error);
if (error instanceof CloudWorkspaceAccessTokenError) {
// TODO: Remove License if there is no access token
}
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
9 changes: 5 additions & 4 deletions apps/meteor/client/views/admin/cloud/RegisterWorkspace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const RegisterWorkspace = () => {

const { data: registrationStatusData, isLoading, isError, refetch } = useRegistrationStatus();
const isWorkspaceRegistered = registrationStatusData?.registrationStatus?.workspaceRegistered ?? false;
const isConnectedToCloud = registrationStatusData?.registrationStatus?.connectToCloud ?? false;
const isConnectedToCloud = true;

if (isLoading || isError) {
return null;
Expand All @@ -27,9 +27,10 @@ const RegisterWorkspace = () => {
setModal(null);
refetch();
};
if (isWorkspaceRegistered) {
setModal(<ConnectWorkspaceModal onClose={handleModalClose} onStatusChange={refetch} />);
} else setModal(<RegisterWorkspaceModal onClose={handleModalClose} onStatusChange={refetch} />);
// if (isWorkspaceRegistered) {
// setModal(<ConnectWorkspaceModal onClose={handleModalClose} onStatusChange={refetch} />);
// } else
setModal(<RegisterWorkspaceModal onClose={handleModalClose} onStatusChange={refetch} />);
};

const handleManualWorkspaceRegistrationButton = (): void => {
Expand Down

0 comments on commit 27a98ab

Please sign in to comment.