Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:RocketChat/Rocket.Chat into chor…
Browse files Browse the repository at this point in the history
…e/wizard

* 'develop' of github.com:RocketChat/Rocket.Chat:
  [BREAK] Unify monolith and microservices intercommunication on same technology and limit to Enterprise only (#27969)
  [NEW] Emojis rendering properly on quote message previews (#27972)
  Chore: Wait message to not be Busy (#28000)
  Chore: e2e changes tests (#27987)
  [IMPROVE] Audit (#27994)
  [IMPROVE] Registration Experience (#27820)
  [BREAK][ENTERPRISE] Limit presence statuses to 200 concurrent users when running monolith to keep performance (#27854)
  [BREAK] Removed deprecated settings for Legacy Messages, Marked, Snippet Messages, Autolinker and IssueLinks (#27902)
  [NEW] Permission to bypass message editing and removing limits (#27644)
  [FIX] Video Conf Message Blocks not always updating when running on micro services (#27764)
  Chore: Set missing colors (#27817)
  Fix CI
  Chore: undo busy selector
  [BREAK] Remove message view mode from User Preferences (#27867)
  Chore: Aria busy indicators (#27978)
  Chore: Refactor Composer Dropdown (#27931)
  Chore: Added Enterprise Options to Login customization (#27855)
  [FIX] Ignored messages reactivity (#27279)
  [BREAK] [NEW] Custom roles upsell modal (#27707)
  • Loading branch information
gabriellsh committed Feb 13, 2023
2 parents c2104e5 + b08adc9 commit af95926
Show file tree
Hide file tree
Showing 414 changed files with 5,604 additions and 4,912 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -454,9 +454,6 @@ jobs:
- name: yarn build
run: yarn build

- name: Unit Test
run: yarn testunit --api="http://127.0.0.1:9080" --token="${{ secrets.TURBO_SERVER_TOKEN }}" --team='rc'

- name: Restore build
uses: actions/download-artifact@v2
with:
Expand Down
12 changes: 11 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,15 @@
}
],
"typescript.tsdk": "./node_modules/typescript/lib",
"cSpell.words": ["katex", "livechat", "omnichannel", "photoswipe", "tmid"]
"cSpell.words": [
"autotranslate",
"katex",
"listbox",
"livechat",
"oauthapps",
"omnichannel",
"photoswipe",
"searchbox",
"tmid"
]
}
1 change: 0 additions & 1 deletion apps/meteor/.meteor/packages
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ rocketchat:livechat
rocketchat:streamer
rocketchat:version

konecty:multiple-instances-status
konecty:user-presence

dispatch:run-as-user
Expand Down
1 change: 0 additions & 1 deletion apps/meteor/.meteor/versions
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ jparker:crypto-md5@0.1.1
jparker:gravatar@0.5.1
jquery@3.0.0
kadira:flow-router@2.12.1
konecty:multiple-instances-status@1.1.0
konecty:user-presence@2.6.3
launch-screen@1.3.0
littledata:synced-cron@1.5.1
Expand Down
1 change: 1 addition & 0 deletions apps/meteor/app/api/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import './v1/import';
import './v1/ldap';
import './v1/misc';
import './v1/permissions';
import './v1/presence';
import './v1/push';
import './v1/roles';
import './v1/rooms.js';
Expand Down
68 changes: 0 additions & 68 deletions apps/meteor/app/api/server/lib/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import type { IMessage, IUser } from '@rocket.chat/core-typings';
import { Rooms, Messages, Users } from '@rocket.chat/models';

import { canAccessRoomAsync } from '../../../authorization/server/functions/canAccessRoom';
import { getValue } from '../../../settings/server/raw';

export async function findMentionedMessages({
uid,
Expand Down Expand Up @@ -83,73 +82,6 @@ export async function findStarredMessages({
};
}

export async function findSnippetedMessageById({ uid, messageId }: { uid: string; messageId: string }): Promise<IMessage> {
if (!(await getValue('Message_AllowSnippeting'))) {
throw new Error('error-not-allowed');
}

if (!uid) {
throw new Error('invalid-user');
}

const snippet = await Messages.findOne({ _id: messageId, snippeted: true });

if (!snippet) {
throw new Error('invalid-message');
}

const room = await Rooms.findOneById(snippet.rid);

if (!room) {
throw new Error('invalid-message');
}

if (!(await canAccessRoomAsync(room, { _id: uid }))) {
throw new Error('error-not-allowed');
}

return snippet;
}

export async function findSnippetedMessages({
uid,
roomId,
pagination: { offset, count, sort },
}: {
uid: string;
roomId: string;
pagination: { offset: number; count: number; sort: FindOptions<IMessage>['sort'] };
}): Promise<{
messages: IMessage[];
count: number;
offset: number;
total: number;
}> {
if (!(await getValue('Message_AllowSnippeting'))) {
throw new Error('error-not-allowed');
}
const room = await Rooms.findOneById(roomId);

if (!room || !(await canAccessRoomAsync(room, { _id: uid }))) {
throw new Error('error-not-allowed');
}

const { cursor, totalCount } = Messages.findSnippetedByRoom(roomId, {
sort: sort || { ts: -1 },
skip: offset,
limit: count,
});

const [messages, total] = await Promise.all([cursor.toArray(), totalCount]);

return {
messages,
count: messages.length,
offset,
total,
};
}

export async function findDiscussionsFromRoom({
uid,
roomId,
Expand Down
57 changes: 1 addition & 56 deletions apps/meteor/app/api/server/v1/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,7 @@ import Rooms from '../../../models/server/models/Rooms';
import Users from '../../../models/server/models/Users';
import Subscriptions from '../../../models/server/models/Subscriptions';
import { settings } from '../../../settings/server';
import {
findMentionedMessages,
findStarredMessages,
findSnippetedMessageById,
findSnippetedMessages,
findDiscussionsFromRoom,
} from '../lib/messages';
import { findMentionedMessages, findStarredMessages, findDiscussionsFromRoom } from '../lib/messages';

API.v1.addRoute(
'chat.delete',
Expand Down Expand Up @@ -786,55 +780,6 @@ API.v1.addRoute(
},
);

API.v1.addRoute(
'chat.getSnippetedMessageById',
{ authRequired: true },
{
get() {
const { messageId } = this.queryParams;

if (!messageId) {
throw new Meteor.Error('error-invalid-params', 'The required "messageId" query param is missing.');
}
const message = Promise.await(
findSnippetedMessageById({
uid: this.userId,
messageId,
}),
);
return API.v1.success(message);
},
},
);

API.v1.addRoute(
'chat.getSnippetedMessages',
{ authRequired: true },
{
get() {
const { roomId } = this.queryParams;
const { sort } = this.parseJsonQuery();
const { offset, count } = this.getPaginationItems();

if (!roomId) {
throw new Meteor.Error('error-invalid-params', 'The required "roomId" query param is missing.');
}
const messages = Promise.await(
findSnippetedMessages({
uid: this.userId,
roomId,
pagination: {
offset,
count,
sort,
},
}),
);
return API.v1.success(messages);
},
},
);

API.v1.addRoute(
'chat.getDiscussions',
{ authRequired: true },
Expand Down
43 changes: 29 additions & 14 deletions apps/meteor/app/api/server/v1/instances.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
import type { IInstanceStatus } from '@rocket.chat/core-typings';
import { InstanceStatus } from '@rocket.chat/models';

import { getInstanceConnection } from '../../../../server/stream/streamBroadcast';
import { Instance as InstanceService } from '../../../../ee/server/sdk';
import { hasPermission } from '../../../authorization/server';
import { API } from '../api';
import { isRunningMs } from '../../../../server/lib/isRunningMs';

const getMatrixInstances = (() => {
if (isRunningMs()) {
return () => [];
}

return () => InstanceService.getInstances();
})();

API.v1.addRoute(
'instances.get',
Expand All @@ -14,20 +22,27 @@ API.v1.addRoute(
return API.v1.unauthorized();
}

const instances = await InstanceStatus.find().toArray();
const instanceRecords = await InstanceStatus.find().toArray();

const connections = await getMatrixInstances();

const result = instanceRecords.map((instanceRecord) => {
const connection = connections.find((c) => c.id === instanceRecord._id);

return {
address: connection?.ipList[0],
currentStatus: {
connected: connection?.available || false,
lastHeartbeatTime: connection?.lastHeartbeatTime,
local: connection?.local,
},
instanceRecord,
broadcastAuth: true,
};
});

return API.v1.success({
instances: instances.map((instance: IInstanceStatus) => {
const connection = getInstanceConnection(instance);

if (connection) {
delete connection.instanceRecord;
}
return {
...instance,
connection,
};
}),
instances: result,
});
},
},
Expand Down
27 changes: 27 additions & 0 deletions apps/meteor/app/api/server/v1/presence.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Presence } from '@rocket.chat/core-services';

import { API } from '../api';

API.v1.addRoute(
'presence.getConnections',
{ authRequired: true, permissionsRequired: ['manage-user-status'] },
{
async get() {
const result = await Presence.getConnectionCount();

return API.v1.success(result);
},
},
);

API.v1.addRoute(
'presence.enableBroadcast',
{ authRequired: true, permissionsRequired: ['manage-user-status'], twoFactorRequired: true },
{
async post() {
await Presence.toggleBroadcast(true);

return API.v1.success();
},
},
);
8 changes: 8 additions & 0 deletions apps/meteor/app/api/server/v1/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,14 @@ API.v1.addRoute(
{ authRequired: true },
{
get() {
// if presence broadcast is disabled, return an empty array (all users are "offline")
if (settings.get('Presence_broadcast_disabled')) {
return API.v1.success({
users: [],
full: true,
});
}

const { from, ids } = this.queryParams;

const options = {
Expand Down
6 changes: 3 additions & 3 deletions apps/meteor/app/apps/server/communication/rest.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Settings } from '@rocket.chat/models';

import { API } from '../../../api/server';
import { getUploadFormData } from '../../../api/server/lib/getUploadFormData';
import { getWorkspaceAccessToken, getUserCloudAccessToken } from '../../../cloud/server';
import { getWorkspaceAccessToken, getWorkspaceAccessTokenWithScope } from '../../../cloud/server';
import { settings } from '../../../settings/server';
import { Info } from '../../../utils';
import { Users } from '../../../models/server';
Expand Down Expand Up @@ -148,7 +148,7 @@ export class AppsRestApi {
return API.v1.failure({ error: 'Invalid purchase type' });
}

const token = await getUserCloudAccessToken(this.getLoggedInUser()._id, true, 'marketplace:purchase', false);
const token = await getWorkspaceAccessTokenWithScope('marketplace:purchase');
if (!token) {
return API.v1.failure({ error: 'Unauthorized' });
}
Expand All @@ -160,7 +160,7 @@ export class AppsRestApi {
return API.v1.success({
url: `${baseUrl}/apps/${this.queryParams.appId}/${
this.queryParams.purchaseType === 'buy' ? this.queryParams.purchaseType : subscribeRoute
}?workspaceId=${workspaceId}&token=${token}&seats=${seats}`,
}?workspaceId=${workspaceId}&token=${token.token}&seats=${seats}`,
});
}

Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/apps/server/storage/logs-storage.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AppConsole } from '@rocket.chat/apps-engine/server/logging';
import { AppLogStorage } from '@rocket.chat/apps-engine/server/storage';
import { InstanceStatus } from 'meteor/konecty:multiple-instances-status';
import { InstanceStatus } from '@rocket.chat/instance-status';

export class AppRealLogsStorage extends AppLogStorage {
constructor(model) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,15 @@ export const canDeleteMessageAsync = async (uid: string, { u, rid, ts }: { u: IU
if (!allowed) {
return false;
}
const blockDeleteInMinutes = await getValue('Message_AllowDeleting_BlockDeleteInMinutes');
const bypassBlockTimeLimit = await hasPermissionAsync(uid, 'bypass-time-limit-edit-and-delete');

if (blockDeleteInMinutes) {
const timeElapsedForMessage = elapsedTime(ts);
return timeElapsedForMessage <= blockDeleteInMinutes;
if (!bypassBlockTimeLimit) {
const blockDeleteInMinutes = await getValue('Message_AllowDeleting_BlockDeleteInMinutes');

if (blockDeleteInMinutes) {
const timeElapsedForMessage = elapsedTime(ts);
return timeElapsedForMessage <= blockDeleteInMinutes;
}
}

const room = await Rooms.findOneById(rid, { fields: { ro: 1, unmuted: 1 } });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@ export const upsertPermissions = async (): Promise<void> => {
{ _id: 'manage-sounds', roles: ['admin'] },
{ _id: 'access-mailer', roles: ['admin'] },
{ _id: 'pin-message', roles: ['owner', 'moderator', 'admin'] },
{ _id: 'snippet-message', roles: ['owner', 'moderator', 'admin'] },
{ _id: 'mobile-upload-file', roles: ['user', 'admin'] },
{ _id: 'send-mail', roles: ['admin'] },
{ _id: 'view-federation-data', roles: ['admin'] },
Expand All @@ -224,6 +223,7 @@ export const upsertPermissions = async (): Promise<void> => {
{ _id: 'view-import-operations', roles: ['admin'] },
{ _id: 'clear-oembed-cache', roles: ['admin'] },
{ _id: 'videoconf-ring-users', roles: ['admin', 'owner', 'moderator', 'user'] },
{ _id: 'bypass-time-limit-edit-and-delete', roles: ['bot', 'app'] },
];

for await (const permission of permissions) {
Expand Down
Loading

0 comments on commit af95926

Please sign in to comment.