Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove connectToCloud option #30430

Merged
merged 2 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: 0 additions & 17 deletions apps/meteor/app/cloud/server/functions/disconnectWorkspace.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';
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
18 changes: 0 additions & 18 deletions apps/meteor/app/cloud/server/methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { hasPermissionAsync } from '../../authorization/server/functions/hasPerm
import { buildWorkspaceRegistrationData } from './functions/buildRegistrationData';
import { checkUserHasCloudLogin } from './functions/checkUserHasCloudLogin';
import { connectWorkspace } from './functions/connectWorkspace';
import { disconnectWorkspace } from './functions/disconnectWorkspace';
import { finishOAuthAuthorization } from './functions/finishOAuthAuthorization';
import { getOAuthAuthorizationUrl } from './functions/getOAuthAuthorizationUrl';
import { reconnectWorkspace } from './functions/reconnectWorkspace';
Expand All @@ -19,7 +18,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 @@ -137,22 +135,6 @@ Meteor.methods<ServerMethods>({

return connectWorkspace(token);
},
async 'cloud:disconnectWorkspace'() {
const uid = Meteor.userId();
if (!uid) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', {
method: 'cloud:connectServer',
});
}

if (!(await hasPermissionAsync(uid, 'manage-cloud'))) {
throw new Meteor.Error('error-not-authorized', 'Not authorized', {
method: 'cloud:connectServer',
});
}

return disconnectWorkspace();
},
async 'cloud:reconnectWorkspace'() {
const uid = Meteor.userId();
if (!uid) {
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

This file was deleted.

Loading
Loading