Skip to content

Commit

Permalink
Merge branch 'develop' into fix/fed-116
Browse files Browse the repository at this point in the history
  • Loading branch information
lmauromb committed Oct 25, 2023
2 parents 9893c27 + 747ec6c commit 97a0343
Show file tree
Hide file tree
Showing 48 changed files with 1,453 additions and 357 deletions.
6 changes: 6 additions & 0 deletions .changeset/late-pants-switch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@rocket.chat/meteor': minor
'@rocket.chat/i18n': patch
---

Updated slack bridge to add support for connecting using slack apps in addition to the slack legacy bot
5 changes: 5 additions & 0 deletions .changeset/serious-cats-fetch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/meteor': patch
---

Fixed a problem that would prevent private apps from being shown on air-gapped environments
5 changes: 5 additions & 0 deletions .changeset/six-pens-look.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/meteor': minor
---

feat: Setup wizard content updates and enforcing cloud connectivity
5 changes: 5 additions & 0 deletions .changeset/tall-moons-beam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": patch
---

Enable the option `Only allow verified users to login` to SaaS environment
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { serverFetch as fetch } from '@rocket.chat/server-fetch';

import { SystemLogger } from '../../../../../server/lib/logger/system';
import { settings } from '../../../../settings/server';
import { buildVersionUpdateMessage } from '../../../../version-check/server/functions/buildVersionUpdateMessage';
import { generateWorkspaceBearerHttpHeader } from '../getWorkspaceAccessToken';
import { supportedVersionsChooseLatest } from './supportedVersionsChooseLatest';

Expand Down Expand Up @@ -83,7 +84,9 @@ const cacheValueInSettings = <T extends SettingValue>(
);
};

/** CODE */
const releaseEndpoint = process.env.OVERWRITE_INTERNAL_RELEASE_URL?.trim()
? process.env.OVERWRITE_INTERNAL_RELEASE_URL.trim()
: 'https://releases.rocket.chat/v2/server/supportedVersions';

const getSupportedVersionsFromCloud = async () => {
if (process.env.CLOUD_SUPPORTED_VERSIONS_TOKEN) {
Expand All @@ -97,15 +100,15 @@ const getSupportedVersionsFromCloud = async () => {
const headers = await generateWorkspaceBearerHttpHeader();

const response = await handleResponse<SupportedVersions>(
fetch('https://releases.rocket.chat/v2/server/supportedVersions', {
fetch(releaseEndpoint, {
headers,
}),
);

if (!response.success) {
SystemLogger.error({
msg: 'Failed to communicate with Rocket.Chat Cloud',
url: 'https://releases.rocket.chat/v2/server/supportedVersions',
url: releaseEndpoint,
err: response.error,
});
}
Expand All @@ -123,8 +126,14 @@ const getSupportedVersionsToken = async () => {

const [versionsFromLicense, response] = await Promise.all([License.getLicense(), getSupportedVersionsFromCloud()]);

return (await supportedVersionsChooseLatest(versionsFromLicense?.supportedVersions, (response.success && response.result) || undefined))
?.signed;
const supportedVersions = await supportedVersionsChooseLatest(
versionsFromLicense?.supportedVersions,
(response.success && response.result) || undefined,
);

await buildVersionUpdateMessage(supportedVersions?.versions);

return supportedVersions?.signed;
};

export const getCachedSupportedVersionsToken = cacheValueInSettings('Cloud_Workspace_Supported_Versions_Token', getSupportedVersionsToken);
77 changes: 64 additions & 13 deletions apps/meteor/app/slackbridge/server/SlackAPI.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { serverFetch as fetch } from '@rocket.chat/server-fetch';

export class SlackAPI {
constructor(apiToken) {
this.apiToken = apiToken;
constructor(apiOrBotToken) {
this.token = apiOrBotToken;
}

async getChannels(cursor = null) {
let channels = [];
const request = await fetch('https://slack.com/api/conversations.list', {
headers: {
Authorization: `Bearer ${this.token}`,
},
params: {
token: this.apiToken,
types: 'public_channel',
exclude_archived: true,
limit: 1000,
Expand All @@ -32,8 +34,10 @@ export class SlackAPI {
async getGroups(cursor = null) {
let groups = [];
const request = await fetch('https://slack.com/api/conversations.list', {
headers: {
Authorization: `Bearer ${this.token}`,
},
params: {
token: this.apiToken,
types: 'private_channel',
exclude_archived: true,
limit: 1000,
Expand All @@ -55,8 +59,10 @@ export class SlackAPI {

async getRoomInfo(roomId) {
const request = await fetch(`https://slack.com/api/conversations.info`, {
headers: {
Authorization: `Bearer ${this.token}`,
},
params: {
token: this.apiToken,
channel: roomId,
include_num_members: true,
},
Expand All @@ -73,8 +79,10 @@ export class SlackAPI {
for (let index = 0; index < num_members; index += MAX_MEMBERS_PER_CALL) {
// eslint-disable-next-line no-await-in-loop
const request = await fetch('https://slack.com/api/conversations.members', {
headers: {
Authorization: `Bearer ${this.token}`,
},
params: {
token: this.apiToken,
channel: channelId,
limit: MAX_MEMBERS_PER_CALL,
...(currentCursor && { cursor: currentCursor }),
Expand All @@ -95,6 +103,9 @@ export class SlackAPI {

async react(data) {
const request = await fetch('https://slack.com/api/reactions.add', {
headers: {
Authorization: `Bearer ${this.token}`,
},
method: 'POST',
params: data,
});
Expand All @@ -104,6 +115,9 @@ export class SlackAPI {

async removeReaction(data) {
const request = await fetch('https://slack.com/api/reactions.remove', {
headers: {
Authorization: `Bearer ${this.token}`,
},
method: 'POST',
params: data,
});
Expand All @@ -113,6 +127,9 @@ export class SlackAPI {

async removeMessage(data) {
const request = await fetch('https://slack.com/api/chat.delete', {
headers: {
Authorization: `Bearer ${this.token}`,
},
method: 'POST',
params: data,
});
Expand All @@ -122,6 +139,9 @@ export class SlackAPI {

async sendMessage(data) {
const request = await fetch('https://slack.com/api/chat.postMessage', {
headers: {
Authorization: `Bearer ${this.token}`,
},
method: 'POST',
params: data,
});
Expand All @@ -130,28 +150,33 @@ export class SlackAPI {

async updateMessage(data) {
const request = await fetch('https://slack.com/api/chat.update', {
headers: {
Authorization: `Bearer ${this.token}`,
},
method: 'POST',
params: data,
});
const response = await request.json();
return response && request.status === 200 && response && request.ok;
}

async getHistory(family, options) {
const request = await fetch(`https://slack.com/api/${family}.history`, {
params: {
token: this.apiToken,
...options,
async getHistory(options) {
const request = await fetch(`https://slack.com/api/conversations.history`, {
headers: {
Authorization: `Bearer ${this.token}`,
},
params: options,
});
const response = await request.json();
return response;
}

async getPins(channelId) {
const request = await fetch('https://slack.com/api/pins.list', {
headers: {
Authorization: `Bearer ${this.token}`,
},
params: {
token: this.apiToken,
channel: channelId,
},
});
Expand All @@ -161,12 +186,38 @@ export class SlackAPI {

async getUser(userId) {
const request = await fetch('https://slack.com/api/users.info', {
headers: {
Authorization: `Bearer ${this.token}`,
},
params: {
token: this.apiToken,
user: userId,
},
});
const response = await request.json();
return response && response && request.status === 200 && request.ok && response.user;
}

static async verifyToken(token) {
const request = await fetch('https://slack.com/api/auth.test', {
headers: {
Authorization: `Bearer ${token}`,
},
method: 'POST',
});
const response = await request.json();
return response && response && request.status === 200 && request.ok && response.ok;
}

static async verifyAppCredentials({ botToken, appToken }) {
const request = await fetch('https://slack.com/api/apps.connections.open', {
headers: {
Authorization: `Bearer ${appToken}`,
},
method: 'POST',
});
const response = await request.json();
const isAppTokenOk = response && response && request.status === 200 && request.ok && response.ok;
const isBotTokenOk = await this.verifyToken(botToken);
return isAppTokenOk && isBotTokenOk;
}
}
Loading

0 comments on commit 97a0343

Please sign in to comment.