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

[FIX] Bug on entering token in connectivity services #18317

Merged
merged 3 commits into from
Jul 21, 2020
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
7 changes: 0 additions & 7 deletions app/cloud/server/functions/connectWorkspace.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { HTTP } from 'meteor/http';

import { getRedirectUri } from './getRedirectUri';
import { retrieveRegistrationStatus } from './retrieveRegistrationStatus';
import { getWorkspaceAccessToken } from './getWorkspaceAccessToken';
import { Settings } from '../../../models';
import { settings } from '../../../settings';
import { saveRegistrationData } from './saveRegistrationData';
Expand Down Expand Up @@ -49,11 +48,5 @@ export function connectWorkspace(token) {

Promise.await(saveRegistrationData(data));

// Now that we have the client id and secret, let's get the access token
const accessToken = getWorkspaceAccessToken(true);
if (!accessToken) {
return false;
}

return true;
}
20 changes: 2 additions & 18 deletions app/cloud/server/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { disconnectWorkspace } from './functions/disconnectWorkspace';
import { syncWorkspace } from './functions/syncWorkspace';
import { checkUserHasCloudLogin } from './functions/checkUserHasCloudLogin';
import { userLogout } from './functions/userLogout';
import { Settings } from '../../models';
import { hasPermission } from '../../authorization';
import { buildWorkspaceRegistrationData } from './functions/buildRegistrationData';

Expand Down Expand Up @@ -49,28 +48,13 @@ Meteor.methods({

return startRegisterWorkspace();
},
'cloud:updateEmail'(email, resend = false) {
check(email, String);

if (!Meteor.userId()) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'cloud:updateEmail' });
}

if (!hasPermission(Meteor.userId(), 'manage-cloud')) {
throw new Meteor.Error('error-not-authorized', 'Not authorized', { method: 'cloud:updateEmail' });
}

Settings.updateValueById('Organization_Email', email);

return startRegisterWorkspace(resend);
},
'cloud:syncWorkspace'() {
if (!Meteor.userId()) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'cloud:updateEmail' });
throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'cloud:syncWorkspace' });
}

if (!hasPermission(Meteor.userId(), 'manage-cloud')) {
throw new Meteor.Error('error-not-authorized', 'Not authorized', { method: 'cloud:updateEmail' });
throw new Meteor.Error('error-not-authorized', 'Not authorized', { method: 'cloud:syncWorkspace' });
}

return syncWorkspace();
Expand Down
13 changes: 7 additions & 6 deletions client/admin/cloud/CloudPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ function CloudPage() {
setModal(<ManualWorkspaceRegistrationModal onClose={handleModalClose} />);
};

const isConnectedToCloud = registerStatus?.connectToCloud;
const isConnectToCloudDesired = registerStatus?.connectToCloud;
const isWorkspaceRegistered = registerStatus?.workspaceRegistered;

return <Page>
Expand All @@ -122,21 +122,22 @@ function CloudPage() {
<Margins block='x24'>
<WhatIsItSection />

{isConnectedToCloud && <>
{isConnectToCloudDesired && <>
{isWorkspaceRegistered
? <WorkspaceLoginSection onRegisterStatusChange={fetchRegisterStatus} />
? <>
<WorkspaceLoginSection onRegisterStatusChange={fetchRegisterStatus} />
<TroubleshootingSection onRegisterStatusChange={fetchRegisterStatus} />
</>
: <WorkspaceRegistrationSection
email={registerStatus?.email}
token={registerStatus?.token}
workspaceId={registerStatus?.workspaceId}
uniqueId={registerStatus?.uniqueId}
onRegisterStatusChange={fetchRegisterStatus}
/>}

<TroubleshootingSection onRegisterStatusChange={fetchRegisterStatus} />
</>}

{!isConnectedToCloud && <ConnectToCloudSection onRegisterStatusChange={fetchRegisterStatus} />}
{!isConnectToCloudDesired && <ConnectToCloudSection onRegisterStatusChange={fetchRegisterStatus} />}
</Margins>
</Box>
</Page.ScrollableContentWithShadow>
Expand Down
1 change: 0 additions & 1 deletion client/admin/cloud/ConnectToCloudSection.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ function ConnectToCloudSection({
throw Error(t('An error occured'));
}

// TODO: sync on register?
const isSynced = await syncWorkspace();

if (!isSynced) {
Expand Down
75 changes: 12 additions & 63 deletions client/admin/cloud/WorkspaceRegistrationSection.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { Box, Button, ButtonGroup, EmailInput, Field, Margins, TextInput } from '@rocket.chat/fuselage';
import { Box, Button, ButtonGroup, Field, Margins, TextInput } from '@rocket.chat/fuselage';
import { useSafely, useUniqueId } from '@rocket.chat/fuselage-hooks';
import React, { useState, useMemo } from 'react';
import React, { useState } from 'react';

import { useTranslation } from '../../contexts/TranslationContext';
import { useToastMessageDispatch } from '../../contexts/ToastMessagesContext';
import { useMethod } from '../../contexts/ServerContext';
import { supportEmailAddress } from './constants';

function WorkspaceRegistrationSection({
email: initialEmail,
token: initialToken,
workspaceId,
uniqueId,
Expand All @@ -18,57 +16,16 @@ function WorkspaceRegistrationSection({
const t = useTranslation();
const dispatchToastMessage = useToastMessageDispatch();

const updateEmail = useMethod('cloud:updateEmail');
const connectWorkspace = useMethod('cloud:connectWorkspace');
const syncWorkspace = useMethod('cloud:syncWorkspace');

const [isProcessing, setProcessing] = useSafely(useState(false));
const [email, setEmail] = useState(initialEmail);
const [token, setToken] = useState(initialToken);

const supportMailtoUrl = useMemo(() => {
const subject = encodeURIComponent('Self Hosted Registration');
const body = encodeURIComponent([
`WorkspaceId: ${ workspaceId }`,
`Deployment Id: ${ uniqueId }`,
'Issue: <please describe your issue here>',
].join('\r\n'));
return `mailto:${ supportEmailAddress }?subject=${ subject }&body=${ body }`;
}, [workspaceId, uniqueId]);

const handleEmailChange = ({ currentTarget: { value } }) => {
setEmail(value);
};

const handleTokenChange = ({ currentTarget: { value } }) => {
setToken(value);
};

const handleUpdateEmailButtonClick = async () => {
setProcessing(true);

try {
await updateEmail(email, false);
dispatchToastMessage({ type: 'success', message: t('Saved') });
} catch (error) {
dispatchToastMessage({ type: 'error', message: error });
} finally {
setProcessing(false);
}
};

const handleResendEmailButtonClick = async () => {
setProcessing(true);

try {
await updateEmail(email, true);
dispatchToastMessage({ type: 'success', message: t('Requested') });
} catch (error) {
dispatchToastMessage({ type: 'error', message: error });
} finally {
setProcessing(false);
}
};

const handleConnectButtonClick = async () => {
setProcessing(true);

Expand All @@ -80,6 +37,12 @@ function WorkspaceRegistrationSection({
}

dispatchToastMessage({ type: 'success', message: t('Connected') });

const isSynced = await syncWorkspace();

if (!isSynced) {
throw Error(t('An error occured syncing'));
}
} catch (error) {
dispatchToastMessage({ type: 'error', message: error });
} finally {
Expand All @@ -88,23 +51,13 @@ function WorkspaceRegistrationSection({
}
};

const emailInputId = useUniqueId();
const tokenInputId = useUniqueId();

return <Box marginBlock='neg-x24' {...props}>
<Margins block='x24'>
<Field>
<Field.Label htmlFor={emailInputId}>{t('Email')}</Field.Label>
<Field.Row>
<EmailInput id={emailInputId} disabled={isProcessing} value={email} onChange={handleEmailChange} />
</Field.Row>
<Field.Hint>{t('Cloud_address_to_send_registration_to')}</Field.Hint>
</Field>

<ButtonGroup>
<Button disabled={isProcessing} onClick={handleUpdateEmailButtonClick}>{t('Cloud_update_email')}</Button>
<Button disabled={isProcessing} onClick={handleResendEmailButtonClick}>{t('Cloud_resend_email')}</Button>
</ButtonGroup>
<Box withRichContent color='neutral-800'>
<p>{t('Cloud_token_instructions')}</p>
</Box>

<Field>
<Field.Label htmlFor={tokenInputId}>{t('Token')}</Field.Label>
Expand All @@ -117,10 +70,6 @@ function WorkspaceRegistrationSection({
<ButtonGroup>
<Button primary disabled={isProcessing} onClick={handleConnectButtonClick}>{t('Connect')}</Button>
</ButtonGroup>

<Box withRichContent color='neutral-800'>
<p>{t('Cloud_connect_support')}: <a href={supportMailtoUrl} target='_blank' rel='noopener noreferrer'>{supportEmailAddress}</a></p>
</Box>
</Margins>
</Box>;
}
Expand Down
1 change: 0 additions & 1 deletion packages/rocketchat-i18n/i18n/ca.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,6 @@
"Closed_by_visitor": "Tancat pel visitant",
"Closing_chat": "Tancant xat",
"Cloud": "Cloud",
"Cloud_connect_support": "Si encara no heu rebut cap correu electrònic de registre, assegureu-vos que el vostre correu electrònic s’ha actualitzat anteriorment. Si encara teniu problemes, podeu posar-vos en contacte amb l’assistència a",
"Cloud_console": "Cloud Console",
"Cloud_what_is_it": "Què és això?",
"Cloud_what_is_it_description": "Rocket.Chat Cloud Connect us permet connectar el vostre espai de treball Rocket.Chat amb els vostres serveis en el nostre Cloud.",
Expand Down
1 change: 0 additions & 1 deletion packages/rocketchat-i18n/i18n/cs.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,6 @@
"Cloud_register_offline_helper": "Pracovní prostory lze ručně zaregistrovat, pokud je k nim omezen síťový přístup. Zkopírujte níže uvedený text a dokončete proces pomocí naší cloudové konzole.",
"Cloud_register_success": "Váš pracovní prostor byl úspěšně zaregistrován!",
"Cloud_register_error": "Při zpracování vašeho požadavku došlo k chybě. Prosím zkuste to znovu později.",
"Cloud_connect_support": "Pokud jste ještě neobdrželi registrační e-mail, ujistěte se, že váš e-mail výše je aktuální. Pokud problémy přetrvávají, můžete kontaktovat podporu na adrese",
"Cloud_console": "Cloud přehled",
"Cloud_Info": "Informace o Cloudu",
"Cloud_what_is_it": "Co je to?",
Expand Down
1 change: 0 additions & 1 deletion packages/rocketchat-i18n/i18n/da.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,6 @@
"Cloud_register_offline_helper": "Arbejdsområder kan registreres manuelt, hvis der ikke er netværksadgang eller den er begrænset. Kopier teksten nedenfor og gå til vores Cloud Console for at afslutte processen.",
"Cloud_register_success": "Dit arbejdsområde er blevet registreret!",
"Cloud_register_error": "Der har været en fejl ved forsøg på at behandle din anmodning. Prøv igen senere.",
"Cloud_connect_support": "Hvis du stadig ikke har modtaget en registrerings-e-mail, skal du sørge for, at din e-mail er opdateret ovenfor. Hvis du stadig har problemer, kan du kontakte support på",
"Cloud_console": "Cloud Console",
"Cloud_Info": "Cloud Info",
"Cloud_what_is_it": "Hvad er dette?",
Expand Down
1 change: 0 additions & 1 deletion packages/rocketchat-i18n/i18n/de-IN.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,6 @@
"Closed_by_visitor": "Durch Besucher geschlossen",
"Closing_chat": "Schließe Chat",
"Cloud": "Cloud",
"Cloud_connect_support": "Wenn Du noch immer keine Registrierungs-E-Mail erhalten haben, überprüfe bitte die o. g. Adresse. Wenn es dann immer noch Probleme gibt, erreichst Du unseren Support unter",
"Cloud_console": "Cloud Console",
"Cloud_what_is_it": "Was ist das?",
"Cloud_what_is_it_description": "Mit Rocket.Chat Cloud Connect kannst Du Deinen selbst gehosteten Rocket.Chat Workspace mit unserer Cloud verbinden. Auf diese Weise kannst Du Deine Lizenzen, Abrechnung und Support in der Rocket.Chat Cloud verwalten. ",
Expand Down
1 change: 0 additions & 1 deletion packages/rocketchat-i18n/i18n/de.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,6 @@
"Cloud_register_offline_helper": "Arbeitsbereiche können manuell registriert werden, wenn ein Airgap besteht oder der Netzwerkzugriff eingeschränkt ist. Kopieren Sie den folgenden Text und rufen Sie unsere Cloud-Konsole auf, um den Vorgang abzuschließen.",
"Cloud_register_success": "Ihr Arbeitsbereich wurde erfolgreich registriert!",
"Cloud_register_error": "Beim Verarbeiten Ihrer Anfrage ist ein Fehler aufgetreten. Bitte versuchen Sie es später noch einmal.",
"Cloud_connect_support": "Wenn Sie noch immer keine Registrierungs-E-Mail erhalten haben, überprüfen Sie bitte die o. g. Adresse. Wenn es dann immer noch Probleme gibt, erreichen Sie unseren Support unter",
"Cloud_console": "Cloud Console",
"Cloud_Info": "Cloud-Informationen",
"Cloud_what_is_it": "Was ist das?",
Expand Down
8 changes: 4 additions & 4 deletions packages/rocketchat-i18n/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -762,13 +762,12 @@
"Closing_chat": "Closing chat",
"Closing_chat_message": "Closing chat message",
"Cloud": "Cloud",
"Cloud_Register_manually": "Register Manually",
"Cloud_Register_manually": "Register Offline",
"Cloud_click_here": "After copy the text, go to [cloud console (click here)](__cloudConsoleUrl__).",
"Cloud_register_offline_finish_helper": "After completing the registration process in the Cloud Console you should be presented with some text. Please paste it here to finish the registration.",
"Cloud_register_offline_helper": "Workspaces can be manually registered if airgapped or network access is restricted. Copy the text below and go to our Cloud Console to complete the process.",
"Cloud_register_success": "Your workspace has been successfully registered!",
"Cloud_register_error": "There has been an error trying to process your request. Please try again later.",
"Cloud_connect_support": "If you still haven't received a registration email please make sure your email is updated above. If you still have issues you can contact support at",
"Cloud_console": "Cloud Console",
"Cloud_Info": "Cloud Info",
"Cloud_what_is_it": "What is this?",
Expand All @@ -783,14 +782,15 @@
"Cloud_address_to_send_registration_to": "The address to send your Cloud registration email to.",
"Cloud_update_email": "Update Email",
"Cloud_resend_email": "Resend Email",
"Cloud_manually_input_token": "Manually enter the token received from the Cloud Registration Email.",
"Cloud_manually_input_token": "Enter the token received from the Cloud Console.",
"Cloud_registration_required": "Registration Required",
"Cloud_registration_required_description": "Looks like during setup you didn't chose to register your workspace.",
"Cloud_registration_required_link_text": "Click here to register your workspace.",
"Cloud_error_in_authenticating": "Error received while authenticating",
"Cloud_error_code": "Code: __errorCode__",
"Cloud_status_page_description": "If a particular Cloud Service is having issues you can check for known issues on our status page at",
"Cloud_Service_Agree_PrivacyTerms": "Cloud Service Agree PrivacyTerms",
"Cloud_token_instructions": "To Register your workspace go to Cloud Console. Login or Create an account and click register self-managed. Paste the token provided below",
"Cloud_troubleshooting": "Troubleshooting",
"Collaborative": "Collaborative",
"Collapse_Embedded_Media_By_Default": "Collapse Embedded Media by Default",
Expand Down Expand Up @@ -3957,4 +3957,4 @@
"Your_server_link": "Your server link",
"Your_temporary_password_is_password": "Your temporary password is <strong>[password]</strong>.",
"Your_workspace_is_ready": "Your workspace is ready to use 🎉"
}
}
1 change: 0 additions & 1 deletion packages/rocketchat-i18n/i18n/es.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,6 @@
"Cloud_register_offline_helper": "Los espacios de trabajo pueden registrarse manualmente si el acceso a la red está restringido. Copia el texto de abajo y ve a nuestra Cloud Console para completar el proceso.",
"Cloud_register_success": "¡Su espacio de trabajo ha sido registrado correctamente!",
"Cloud_register_error": "Ha habido un error al tratar de procesar su solicitud. Por favor, inténtelo de nuevo más tarde.",
"Cloud_connect_support": "Si todavía no has recibido un correo electrónico de registro, por favor asegúrate de que tu correo electrónico esté actualizado. Si todavía tienes problemas, puedes contactar con el soporte en",
"Cloud_what_is_it": "¿Que es esto?",
"Cloud_what_is_it_description": "Rocket.Chat Cloud Connect le permite conectar su espacio de trabajo Rocket.Chat con los servicios que ofrecemos en nuestra nube.",
"Cloud_what_is_it_services_like": "Servicios como:",
Expand Down
1 change: 0 additions & 1 deletion packages/rocketchat-i18n/i18n/fa.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,6 @@
"Cloud_register_offline_helper": "در صورت محدود بودن دسترسی به شبکه ، می توان مکان های کاری را به صورت دستی ثبت کرد. متن را کپی کنید و برای تکمیل مراحل به کنسول Cloud ما بروید.",
"Cloud_register_success": "فضای کاری شما با موفقیت ثبت شده است!",
"Cloud_register_error": "هنگام پردازش درخواست شما خطایی رخ داده است. لطفا بعدا دوباره امتحان کنید.",
"Cloud_connect_support": "اگر هنوز ایمیل ثبت نام دریافت نکردید ، لطفاً اطمینان حاصل کنید که ایمیل شما در بالا به روز شده است. اگر هنوز مشکل دارید می توانید با پشتیبانی تماس بگیرید",
"Cloud_console": "کنسول Cloud",
"Cloud_Info": "اطلاعات Cloud",
"Cloud_what_is_it": "این چیه؟",
Expand Down
1 change: 0 additions & 1 deletion packages/rocketchat-i18n/i18n/ja.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,6 @@
"Cloud_register_offline_helper": "エアギャップまたはネットワークアクセスが制限されている場合、ワークスペースを手動で登録できます。以下のテキストをコピーし、クラウドコンソールに移動してプロセスを完了します。",
"Cloud_register_success": "ワークスペースが正常に登録されました!",
"Cloud_register_error": "リクエストの処理中にエラーが発生しました。後でもう一度やり直してください。",
"Cloud_connect_support": "まだ登録メールが届いていない場合は、上記のメールアドレスを必ず更新してください。それでも問題が解決しない場合は、サポートに連絡することができます。",
"Cloud_console": "クラウドコンソール",
"Cloud_Info": "クラウド情報",
"Cloud_what_is_it": "これは何?",
Expand Down
1 change: 0 additions & 1 deletion packages/rocketchat-i18n/i18n/ka-GE.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,6 @@
"Cloud_register_offline_helper": "სამუშაო ადგილების ხელით რეგისტრაცია შესაძლებელია, თუ ქსელზე წვდომა შეზღუდულია. დააკოპირეთ ქვემოთ მოყვანილი ტექსტი და გადადით ჩვენს Cloud Console- ში პროცესის დასრულების მიზნით.",
"Cloud_register_success": "თქვენი სამუშაო ადგილი წარმატებით დარეგისტრირდა!",
"Cloud_register_error": "მოხდა შეცდომა თქვენი მოთხოვნის დამუშავებისას. გთხოვთ სცადოთ მოგვიანებით.",
"Cloud_connect_support": "თუ თქვენ ჯერ კიდევ არ მიგიღიათ რეგისტრაციის ელექტრონული ფოსტა, დარწმუნდით, რომ თქვენი ელ.ფოსტა სწორად გაქვთ მითითებული. თუ მაინც გაქვთ პრობლემები, შეგიძლიათ დაუკავშირდეთ დახმარებას",
"Cloud_console": "Cloud კონსოლი",
"Cloud_Info": "Cloud ინფორმაცია",
"Cloud_what_is_it": "რა არის ეს?",
Expand Down
1 change: 0 additions & 1 deletion packages/rocketchat-i18n/i18n/km.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,6 @@
"Cloud_Register_manually": "ចុះឈ្មោះដោយដៃ",
"Cloud_click_here": "បន្ទាប់ពីចម្លងអត្ថបទសូមចូលទៅកាន់កុងសូលក្លោដ។ [ចុច​ទីនេះ](__cloudConsoleUrl__)",
"Cloud_register_success": "កន្លែងការងាររបស់អ្នកត្រូវបានចុះឈ្មោះដោយជោគជ័យ!",
"Cloud_connect_support": "ប្រសិនបើអ្នកនៅតែមិនទាន់បានទទួលអ៊ីមែលចុះឈ្មោះសូមប្រាកដថាអ៊ីមែលរបស់អ្នកត្រូវបានធ្វើបច្ចុប្បន្នភាពខាងលើ។ ប្រសិនបើអ្នកនៅតែមានបញ្ហាអ្នកអាចទាក់ទងការគាំទ្រ។",
"Cloud_console": "Cloud Console",
"Cloud_Info": "ព័ត៌មានពពក",
"Cloud_what_is_it": "តើ​នេះ​ជា​អ្វី?",
Expand Down
Loading