Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Code scanning - action / CodeQL-Build (push) Failing after 2s
215 lines
6.4 KiB
TypeScript
215 lines
6.4 KiB
TypeScript
import type { ServerMethods } from '@rocket.chat/ddp-client';
|
|
import { check } from 'meteor/check';
|
|
import { Meteor } from 'meteor/meteor';
|
|
|
|
import { hasPermissionAsync } from '../../lib/authorization/hasPermission';
|
|
import { buildWorkspaceRegistrationData } from '../../lib/cloud/buildRegistrationData';
|
|
import { checkUserHasCloudLogin } from '../../lib/cloud/checkUserHasCloudLogin';
|
|
import { connectWorkspace } from '../../lib/cloud/connectWorkspace';
|
|
import { finishOAuthAuthorization } from '../../lib/cloud/finishOAuthAuthorization';
|
|
import { getOAuthAuthorizationUrl } from '../../lib/cloud/getOAuthAuthorizationUrl';
|
|
import { retrieveRegistrationStatus } from '../../lib/cloud/retrieveRegistrationStatus';
|
|
import { startRegisterWorkspace } from '../../lib/cloud/startRegisterWorkspace';
|
|
import { syncWorkspace } from '../../lib/cloud/syncWorkspace';
|
|
import { userLogout } from '../../lib/cloud/userLogout';
|
|
import { methodDeprecationLogger } from '../../lib/deprecationWarningLogger';
|
|
|
|
declare module '@rocket.chat/ddp-client' {
|
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
interface ServerMethods {
|
|
'cloud:checkRegisterStatus': () => {
|
|
workspaceRegistered: boolean;
|
|
workspaceId: string;
|
|
uniqueId: string;
|
|
token: string;
|
|
email: string;
|
|
};
|
|
'cloud:getWorkspaceRegisterData': () => string;
|
|
'cloud:registerWorkspace': () => boolean;
|
|
'cloud:syncWorkspace': () => boolean;
|
|
'cloud:connectWorkspace': (token: string) => boolean | Error;
|
|
'cloud:getOAuthAuthorizationUrl': () => string;
|
|
'cloud:finishOAuthAuthorization': (code: string, state: string) => boolean;
|
|
'cloud:checkUserLoggedIn': () => boolean;
|
|
'cloud:logout': () => Promise<boolean | string>;
|
|
}
|
|
}
|
|
|
|
Meteor.methods<ServerMethods>({
|
|
/**
|
|
* @deprecated this method is deprecated and will be removed soon.
|
|
* Prefer using cloud.registrationStatus rest api.
|
|
*/
|
|
async 'cloud:checkRegisterStatus'() {
|
|
methodDeprecationLogger.method('cloud:checkRegisterStatus', '9.0.0', '/v1/cloud.registrationStatus');
|
|
const uid = Meteor.userId();
|
|
|
|
if (!uid) {
|
|
throw new Meteor.Error('error-invalid-user', 'Invalid user', {
|
|
method: 'cloud:checkRegisterStatus',
|
|
});
|
|
}
|
|
|
|
if (!(await hasPermissionAsync(uid, 'manage-cloud'))) {
|
|
throw new Meteor.Error('error-not-authorized', 'Not authorized', {
|
|
method: 'cloud:checkRegisterStatus',
|
|
});
|
|
}
|
|
|
|
return retrieveRegistrationStatus();
|
|
},
|
|
/**
|
|
* @deprecated this method is deprecated and will be removed soon.
|
|
* Prefer using cloud.workspaceRegisterData rest api.
|
|
*/
|
|
async 'cloud:getWorkspaceRegisterData'() {
|
|
methodDeprecationLogger.method('cloud:getWorkspaceRegisterData', '9.0.0', '/v1/cloud.workspaceRegisterData');
|
|
const uid = Meteor.userId();
|
|
|
|
if (!uid) {
|
|
throw new Meteor.Error('error-invalid-user', 'Invalid user', {
|
|
method: 'cloud:getWorkspaceRegisterData',
|
|
});
|
|
}
|
|
|
|
if (!(await hasPermissionAsync(uid, 'manage-cloud'))) {
|
|
throw new Meteor.Error('error-not-authorized', 'Not authorized', {
|
|
method: 'cloud:getWorkspaceRegisterData',
|
|
});
|
|
}
|
|
|
|
return Buffer.from(JSON.stringify(await buildWorkspaceRegistrationData(undefined))).toString('base64');
|
|
},
|
|
async 'cloud:registerWorkspace'() {
|
|
const uid = Meteor.userId();
|
|
|
|
if (!uid) {
|
|
throw new Meteor.Error('error-invalid-user', 'Invalid user', {
|
|
method: 'cloud:registerWorkspace',
|
|
});
|
|
}
|
|
|
|
if (!(await hasPermissionAsync(uid, 'manage-cloud'))) {
|
|
throw new Meteor.Error('error-not-authorized', 'Not authorized', {
|
|
method: 'cloud:registerWorkspace',
|
|
});
|
|
}
|
|
|
|
return startRegisterWorkspace();
|
|
},
|
|
async 'cloud:syncWorkspace'() {
|
|
const uid = Meteor.userId();
|
|
|
|
if (!uid) {
|
|
throw new Meteor.Error('error-invalid-user', 'Invalid user', {
|
|
method: 'cloud:syncWorkspace',
|
|
});
|
|
}
|
|
|
|
if (!(await hasPermissionAsync(uid, 'manage-cloud'))) {
|
|
throw new Meteor.Error('error-not-authorized', 'Not authorized', {
|
|
method: 'cloud:syncWorkspace',
|
|
});
|
|
}
|
|
|
|
await syncWorkspace();
|
|
|
|
return true;
|
|
},
|
|
async 'cloud:connectWorkspace'(token) {
|
|
methodDeprecationLogger.method('cloud:connectWorkspace', '9.0.0', '/v1/cloud.connectWorkspace');
|
|
check(token, String);
|
|
|
|
const uid = Meteor.userId();
|
|
|
|
if (!uid) {
|
|
throw new Meteor.Error('error-invalid-user', 'Invalid user', {
|
|
method: 'cloud:connectWorkspace',
|
|
});
|
|
}
|
|
|
|
if (!(await hasPermissionAsync(uid, 'manage-cloud'))) {
|
|
throw new Meteor.Error('error-not-authorized', 'Not authorized', {
|
|
method: 'cloud:connectWorkspace',
|
|
});
|
|
}
|
|
|
|
if (!token) {
|
|
throw new Meteor.Error('error-invalid-payload', 'Token is required.', {
|
|
method: 'cloud:connectWorkspace',
|
|
});
|
|
}
|
|
|
|
return connectWorkspace(token);
|
|
},
|
|
// Currently unused but will link local account to Rocket.Chat Cloud account.
|
|
async 'cloud:getOAuthAuthorizationUrl'() {
|
|
const uid = Meteor.userId();
|
|
if (!uid) {
|
|
throw new Meteor.Error('error-invalid-user', 'Invalid user', {
|
|
method: 'cloud:getOAuthAuthorizationUrl',
|
|
});
|
|
}
|
|
|
|
if (!(await hasPermissionAsync(uid, 'manage-cloud'))) {
|
|
throw new Meteor.Error('error-not-authorized', 'Not authorized', {
|
|
method: 'cloud:getOAuthAuthorizationUrl',
|
|
});
|
|
}
|
|
|
|
return getOAuthAuthorizationUrl();
|
|
},
|
|
async 'cloud:finishOAuthAuthorization'(code, state) {
|
|
check(code, String);
|
|
check(state, String);
|
|
|
|
const uid = Meteor.userId();
|
|
|
|
if (!uid) {
|
|
throw new Meteor.Error('error-invalid-user', 'Invalid user', {
|
|
method: 'cloud:finishOAuthAuthorization',
|
|
});
|
|
}
|
|
|
|
if (!(await hasPermissionAsync(uid, 'manage-cloud'))) {
|
|
throw new Meteor.Error('error-not-authorized', 'Not authorized', {
|
|
method: 'cloud:finishOAuthAuthorization',
|
|
});
|
|
}
|
|
|
|
return finishOAuthAuthorization(code, state);
|
|
},
|
|
async 'cloud:checkUserLoggedIn'() {
|
|
const uid = Meteor.userId();
|
|
if (!uid) {
|
|
throw new Meteor.Error('error-invalid-user', 'Invalid user', {
|
|
method: 'cloud:checkUserLoggedIn',
|
|
});
|
|
}
|
|
|
|
if (!(await hasPermissionAsync(uid, 'manage-cloud'))) {
|
|
throw new Meteor.Error('error-not-authorized', 'Not authorized', {
|
|
method: 'cloud:checkUserLoggedIn',
|
|
});
|
|
}
|
|
|
|
return checkUserHasCloudLogin(uid);
|
|
},
|
|
async 'cloud:logout'() {
|
|
const uid = Meteor.userId();
|
|
if (!uid) {
|
|
throw new Meteor.Error('error-invalid-user', 'Invalid user', {
|
|
method: 'cloud:logout',
|
|
});
|
|
}
|
|
|
|
if (!(await hasPermissionAsync(uid, 'manage-cloud'))) {
|
|
throw new Meteor.Error('error-not-authorized', 'Not authorized', {
|
|
method: 'cloud:logout',
|
|
});
|
|
}
|
|
|
|
return userLogout(uid);
|
|
},
|
|
});
|