Skip to content

Commit

Permalink
Merge branch 'develop' into fingerprint
Browse files Browse the repository at this point in the history
  • Loading branch information
ggazzo authored Oct 3, 2023
2 parents 98d1df5 + b14e159 commit 574d302
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 16 deletions.
5 changes: 5 additions & 0 deletions .changeset/quiet-phones-reply.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/meteor': patch
---

Search users using full name too on share message modal
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export async function getWorkspaceLicense(): Promise<{ updated: boolean; license
const fromCurrentLicense = async () => {
const license = currentLicense?.value as string | undefined;
if (license) {
callbacks.run('workspaceLicenseChanged', license);
await callbacks.run('workspaceLicenseChanged', license);
}

return { updated: false, license: license ?? '' };
Expand Down
9 changes: 8 additions & 1 deletion apps/meteor/app/livechat/imports/server/rest/triggers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { isGETLivechatTriggersParams, isPOSTLivechatTriggersParams } from '@rock

import { API } from '../../../../api/server';
import { getPaginationItems } from '../../../../api/server/helpers/getPaginationItems';
import { findTriggers, findTriggerById } from '../../../server/api/lib/triggers';
import { findTriggers, findTriggerById, deleteTrigger } from '../../../server/api/lib/triggers';

API.v1.addRoute(
'livechat/triggers',
Expand Down Expand Up @@ -57,5 +57,12 @@ API.v1.addRoute(
trigger,
});
},
async delete() {
await deleteTrigger({
triggerId: this.urlParams._id,
});

return API.v1.success();
},
},
);
4 changes: 4 additions & 0 deletions apps/meteor/app/livechat/server/api/lib/triggers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@ export async function findTriggers({
export async function findTriggerById({ triggerId }: { triggerId: string }): Promise<ILivechatTrigger | null> {
return LivechatTrigger.findOneById(triggerId);
}

export async function deleteTrigger({ triggerId }: { triggerId: string }): Promise<void> {
await LivechatTrigger.removeById(triggerId);
}
3 changes: 3 additions & 0 deletions apps/meteor/app/livechat/server/methods/removeTrigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { check } from 'meteor/check';
import { Meteor } from 'meteor/meteor';

import { hasPermissionAsync } from '../../../authorization/server/functions/hasPermission';
import { methodDeprecationLogger } from '../../../lib/server/lib/deprecationWarningLogger';

declare module '@rocket.chat/ui-contexts' {
// eslint-disable-next-line @typescript-eslint/naming-convention
Expand All @@ -14,6 +15,8 @@ declare module '@rocket.chat/ui-contexts' {

Meteor.methods<ServerMethods>({
async 'livechat:removeTrigger'(triggerId) {
methodDeprecationLogger.method('livechat:removeTrigger', '7.0.0');

const uid = Meteor.userId();
if (!uid || !(await hasPermissionAsync(uid, 'view-livechat-manager'))) {
throw new Meteor.Error('error-not-allowed', 'Not allowed', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,16 @@ const UserAndRoomAutoCompleteMultiple = ({ value, onChange, ...props }: UserAndR
const debouncedFilter = useDebouncedValue(filter, 1000);

const rooms = useUserSubscriptions(
useMemo(() => ({ open: { $ne: false }, lowerCaseName: new RegExp(escapeRegExp(debouncedFilter), 'i') }), [debouncedFilter]),
useMemo(
() => ({
open: { $ne: false },
$or: [
{ lowerCaseFName: new RegExp(escapeRegExp(debouncedFilter), 'i') },
{ lowerCaseName: new RegExp(escapeRegExp(debouncedFilter), 'i') },
],
}),
[debouncedFilter],
),
).filter((room) => {
if (!user) {
return;
Expand Down
6 changes: 3 additions & 3 deletions apps/meteor/client/views/omnichannel/triggers/TriggersRow.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { ILivechatTrigger } from '@rocket.chat/core-typings';
import { IconButton } from '@rocket.chat/fuselage';
import { useMutableCallback } from '@rocket.chat/fuselage-hooks';
import { useSetModal, useToastMessageDispatch, useRoute, useMethod, useTranslation } from '@rocket.chat/ui-contexts';
import { useSetModal, useToastMessageDispatch, useRoute, useTranslation, useEndpoint } from '@rocket.chat/ui-contexts';
import React, { memo } from 'react';

import GenericModal from '../../../components/GenericModal';
Expand All @@ -13,7 +13,7 @@ const TriggersRow = ({ _id, name, description, enabled, reload }: TriggersRowPro
const t = useTranslation();
const setModal = useSetModal();
const triggersRoute = useRoute('omnichannel-triggers');
const deleteTrigger = useMethod('livechat:removeTrigger');
const deleteTrigger = useEndpoint('DELETE', '/v1/livechat/triggers/:_id', { _id });
const dispatchToastMessage = useToastMessageDispatch();

const handleClick = useMutableCallback(() => {
Expand All @@ -35,7 +35,7 @@ const TriggersRow = ({ _id, name, description, enabled, reload }: TriggersRowPro
e.stopPropagation();
const onDeleteTrigger = async () => {
try {
await deleteTrigger(_id);
await deleteTrigger();
dispatchToastMessage({ type: 'success', message: t('Trigger_removed') });
reload();
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/lib/callbacks/callbacksBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export class Callbacks<
this.setCallbacks(hook, hooks);
}

run<Hook extends keyof TEventLikeCallbackSignatures>(hook: Hook, ...args: Parameters<TEventLikeCallbackSignatures[Hook]>): void;
run<Hook extends keyof TEventLikeCallbackSignatures>(hook: Hook, ...args: Parameters<TEventLikeCallbackSignatures[Hook]>): Promise<void>;

run<Hook extends keyof TChainedCallbackSignatures>(
hook: Hook,
Expand Down
8 changes: 8 additions & 0 deletions apps/meteor/tests/e2e/message-actions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,18 @@ test.describe.serial('message-actions', () => {
await page.locator('[data-qa-id="edit-message"]').click();
await page.locator('[name="msg"]').fill('this message was edited');
await page.keyboard.press('Enter');

await expect(poHomeChannel.content.lastUserMessageBody).toHaveText('this message was edited');
});

test('expect message is deleted', async ({ page }) => {
await poHomeChannel.content.sendMessage('Message to delete');
await poHomeChannel.content.openLastMessageMenu();
await page.locator('[data-qa-id="delete-message"]').click();
await page.locator('#modal-root .rcx-button-group--align-end .rcx-button--danger').click();
await expect(poHomeChannel.content.lastUserMessage.locator('[data-qa-type="message-body"]:has-text("Message to delete")')).toHaveCount(
0,
);
});

test('expect quote the message', async ({ page }) => {
Expand All @@ -64,6 +69,9 @@ test.describe.serial('message-actions', () => {
await poHomeChannel.content.sendMessage('Message to star');
await poHomeChannel.content.openLastMessageMenu();
await page.locator('[data-qa-id="star-message"]').click();
await page.getByRole('button').and(page.getByTitle('Options')).click();
await page.locator('[data-key="starred-messages"]').click();
await expect(poHomeChannel.content.lastUserMessageBody).toHaveText('Message to star');
});

test('expect copy the message', async ({ page }) => {
Expand Down
14 changes: 5 additions & 9 deletions ee/packages/license/src/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { verify, sign, getPairs } from '@rocket.chat/jwt';

import type { ILicenseV3 } from './definition/ILicenseV3';

const PUBLIC_KEY_V2 =
const PUBLIC_LICENSE_KEY_V2 =
'LS0tLS1CRUdJTiBQVUJMSUMgS0VZLS0tLS0KTUlJQ0lqQU5CZ2txaGtpRzl3MEJBUUVGQUFPQ0FnOEFNSUlDQ2dLQ0FnRUFxV1Nza2Q5LzZ6Ung4a3lQY2ljcwpiMzJ3Mnd4VnV3N3lCVDk2clEvOEQreU1lQ01POXdTU3BIYS85bkZ5d293RXRpZ3B0L3dyb1BOK1ZHU3didHdQCkZYQmVxRWxCbmRHRkFsODZlNStFbGlIOEt6L2hHbkNtSk5tWHB4RUsyUkUwM1g0SXhzWVg3RERCN010eC9pcXMKY2pCL091dlNCa2ppU2xlUzdibE5JVC9kQTdLNC9DSjNvaXUwMmJMNEV4Y2xDSGVwenFOTWVQM3dVWmdweE9uZgpOT3VkOElYWUs3M3pTY3VFOEUxNTdZd3B6Q0twVmFIWDdaSmY4UXVOc09PNVcvYUlqS2wzTDYyNjkrZUlPRXJHCndPTm1hSG56Zmc5RkxwSmh6Z3BPMzhhVm43NnZENUtLakJhaldza1krNGEyZ1NRbUtOZUZxYXFPb3p5RUZNMGUKY0ZXWlZWWjNMZWg0dkVNb1lWUHlJeng5Nng4ZjIveW1QbmhJdXZRdjV3TjRmeWVwYTdFWTVVQ2NwNzF6OGtmUAo0RmNVelBBMElEV3lNaWhYUi9HNlhnUVFaNEdiL3FCQmh2cnZpSkNGemZZRGNKZ0w3RmVnRllIUDNQR0wwN1FnCnZMZXZNSytpUVpQcnhyYnh5U3FkUE9rZ3VyS2pWclhUVXI0QTlUZ2lMeUlYNVVsSnEzRS9SVjdtZk9xWm5MVGEKU0NWWEhCaHVQbG5DR1pSMDFUb1RDZktoTUcxdTBDRm5MMisxNWhDOWZxT21XdjlRa2U0M3FsSjBQZ0YzVkovWAp1eC9tVHBuazlnbmJHOUpIK21mSDM5Um9GdlROaW5Zd1NNdll6dXRWT242OXNPemR3aERsYTkwbDNBQ2g0eENWCks3Sk9YK3VIa29OdTNnMmlWeGlaVU0wQ0F3RUFBUT09Ci0tLS0tRU5EIFBVQkxJQyBLRVktLS0tLQo=';

const PUBLIC_KEY_V3 = '';
const PUBLIC_LICENSE_KEY_V3 = process.env.PUBLIC_LICENSE_KEY_V3 || PUBLIC_LICENSE_KEY_V2;

let TEST_KEYS: [string, string] | undefined = undefined;

Expand All @@ -19,7 +19,7 @@ export async function decrypt(encrypted: string): Promise<string> {
TEST_KEYS = TEST_KEYS ?? (await getPairs());

if (!TEST_KEYS) {
throw new Error('Missing LICENSE_PUBLIC_KEY_V3');
throw new Error('Missing PUBLIC_LICENSE_KEY_V3');
}

const [spki] = TEST_KEYS;
Expand All @@ -32,12 +32,12 @@ export async function decrypt(encrypted: string): Promise<string> {
// handle V3
if (encrypted.startsWith('RCV3_')) {
const jwt = encrypted.substring(5);
const [payload] = await verify(jwt, PUBLIC_KEY_V3);
const [payload] = await verify(jwt, PUBLIC_LICENSE_KEY_V3);

return JSON.stringify(payload);
}

const decrypted = crypto.publicDecrypt(Buffer.from(PUBLIC_KEY_V2, 'base64').toString('utf-8'), Buffer.from(encrypted, 'base64'));
const decrypted = crypto.publicDecrypt(Buffer.from(PUBLIC_LICENSE_KEY_V2, 'base64').toString('utf-8'), Buffer.from(encrypted, 'base64'));

return decrypted.toString('utf-8');
}
Expand All @@ -49,10 +49,6 @@ export async function encrypt(license: ILicenseV3): Promise<string> {

TEST_KEYS = TEST_KEYS ?? (await getPairs());

if (!TEST_KEYS) {
throw new Error('Missing LICENSE_PUBLIC_KEY_V3');
}

const [, pkcs8] = TEST_KEYS;

return `RCV3_${await sign(license, pkcs8)}`;
Expand Down
1 change: 1 addition & 0 deletions packages/rest-typings/src/v1/omnichannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3596,6 +3596,7 @@ export type OmnichannelEndpoints = {
};
'/v1/livechat/triggers/:_id': {
GET: () => { trigger: ILivechatTrigger | null };
DELETE: () => void;
};
'/v1/livechat/rooms': {
GET: (params: GETLivechatRoomsParams) => PaginatedResult<{ rooms: IOmnichannelRoom[] }>;
Expand Down

0 comments on commit 574d302

Please sign in to comment.