Skip to content

Commit

Permalink
Merge branch 'develop' into fix/e2ee-file-upload
Browse files Browse the repository at this point in the history
  • Loading branch information
yash-rajpal committed Aug 21, 2024
2 parents 3269ed3 + 94518af commit 9d755af
Show file tree
Hide file tree
Showing 17 changed files with 132 additions and 71 deletions.
5 changes: 5 additions & 0 deletions .changeset/nasty-windows-smile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": patch
---

Allow apps to react/unreact to messages via bridge
7 changes: 7 additions & 0 deletions .changeset/two-bikes-crash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@rocket.chat/meteor': patch
---

Fixed an issue related to setting Accounts_ForgetUserSessionOnWindowClose, this setting was not working as expected.

The new meteor 2.16 release introduced a new option to configure the Accounts package and choose between the local storage or session storage. They also changed how Meteor.\_localstorage works internally. Due to these changes in Meteor, our setting to use session storage wasn't working as expected. This PR fixes this issue and configures the Accounts package according to the workspace settings.
22 changes: 22 additions & 0 deletions apps/meteor/app/apps/server/bridges/messages.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { IAppServerOrchestrator, IAppsMessage, IAppsUser } from '@rocket.chat/apps';
import type { Reaction } from '@rocket.chat/apps-engine/definition/messages';
import type { IRoom } from '@rocket.chat/apps-engine/definition/rooms';
import type { ITypingDescriptor } from '@rocket.chat/apps-engine/server/bridges/MessageBridge';
import { MessageBridge } from '@rocket.chat/apps-engine/server/bridges/MessageBridge';
Expand All @@ -10,6 +11,7 @@ import { deleteMessage } from '../../../lib/server/functions/deleteMessage';
import { updateMessage } from '../../../lib/server/functions/updateMessage';
import { executeSendMessage } from '../../../lib/server/methods/sendMessage';
import notifications from '../../../notifications/server/lib/Notifications';
import { executeSetReaction } from '../../../reactions/server/setReaction';

export class AppMessageBridge extends MessageBridge {
constructor(private readonly orch: IAppServerOrchestrator) {
Expand Down Expand Up @@ -118,4 +120,24 @@ export class AppMessageBridge extends MessageBridge {
throw new Error('Unrecognized typing scope provided');
}
}

private isValidReaction(reaction: Reaction): boolean {
return reaction.startsWith(':') && reaction.endsWith(':');
}

protected async addReaction(messageId: string, userId: string, reaction: Reaction): Promise<void> {
if (!this.isValidReaction(reaction)) {
throw new Error('Invalid reaction');
}

return executeSetReaction(messageId, userId, reaction, true);
}

protected async removeReaction(messageId: string, userId: string, reaction: Reaction): Promise<void> {
if (!this.isValidReaction(reaction)) {
throw new Error('Invalid reaction');
}

return executeSetReaction(messageId, userId, reaction, false);
}
}
13 changes: 13 additions & 0 deletions apps/meteor/client/startup/accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Accounts } from 'meteor/accounts-base';
import { Meteor } from 'meteor/meteor';
import { Tracker } from 'meteor/tracker';

import { settings } from '../../app/settings/client';
import { mainReady } from '../../app/ui-utils/client';
import { sdk } from '../../app/utils/client/lib/SDKClient';
import { t } from '../../app/utils/lib/i18n';
Expand All @@ -24,3 +25,15 @@ Accounts.onEmailVerificationLink((token: string) => {
});
});
});

Meteor.startup(() => {
Tracker.autorun(() => {
const forgetUserSessionOnWindowClose = settings.get('Accounts_ForgetUserSessionOnWindowClose');

if (forgetUserSessionOnWindowClose === undefined) {
return;
}

Accounts.config({ clientStorage: forgetUserSessionOnWindowClose ? 'session' : 'local' });
});
});
2 changes: 2 additions & 0 deletions apps/meteor/definition/externals/meteor/accounts-base.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ declare module 'meteor/accounts-base' {

function _clearAllLoginTokens(userId: string | null): void;

function config(options: { clientStorage: 'session' | 'local' }): void;

class ConfigError extends Error {}

class LoginCancelledError extends Error {
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/ee/server/services/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"author": "Rocket.Chat",
"license": "MIT",
"dependencies": {
"@rocket.chat/apps-engine": "1.44.0",
"@rocket.chat/apps-engine": "1.45.0-alpha.864",
"@rocket.chat/core-services": "workspace:^",
"@rocket.chat/core-typings": "workspace:^",
"@rocket.chat/emitter": "~0.31.25",
Expand Down
3 changes: 1 addition & 2 deletions apps/meteor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@
"@rocket.chat/agenda": "workspace:^",
"@rocket.chat/api-client": "workspace:^",
"@rocket.chat/apps": "workspace:^",
"@rocket.chat/apps-engine": "1.44.0",
"@rocket.chat/apps-engine": "1.45.0-alpha.864",
"@rocket.chat/base64": "workspace:^",
"@rocket.chat/cas-validate": "workspace:^",
"@rocket.chat/core-services": "workspace:^",
Expand Down Expand Up @@ -343,7 +343,6 @@
"filesize": "9.0.11",
"generate-password": "^1.7.1",
"google-libphonenumber": "^3.2.33",
"googleapis": "^104.0.0",
"gravatar": "^1.8.2",
"he": "^1.2.0",
"highlight.js": "^11.6.0",
Expand Down
55 changes: 55 additions & 0 deletions apps/meteor/tests/e2e/account-forgetSessionOnWindowClose.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { DEFAULT_USER_CREDENTIALS } from './config/constants';
import { Registration } from './page-objects';
import { test, expect } from './utils/test';

test.describe.serial('Forget session on window close setting', () => {
let poRegistration: Registration;

test.beforeEach(async ({ page }) => {
poRegistration = new Registration(page);

await page.goto('/home');
});

test.describe('Setting off', async () => {
test.beforeAll(async ({ api }) => {
await api.post('/settings/Accounts_ForgetUserSessionOnWindowClose', { value: false });
});

test('Login using credentials and reload to stay logged in', async ({ page, context }) => {
await poRegistration.username.type('user1');
await poRegistration.inputPassword.type(DEFAULT_USER_CREDENTIALS.password);
await poRegistration.btnLogin.click();

await expect(page.locator('role=heading[name="Welcome to Rocket.Chat"]')).toBeVisible();

const newPage = await context.newPage();
await newPage.goto('/home');

await expect(newPage.locator('role=heading[name="Welcome to Rocket.Chat"]')).toBeVisible();
});
});

test.describe('Setting on', async () => {
test.beforeAll(async ({ api }) => {
await api.post('/settings/Accounts_ForgetUserSessionOnWindowClose', { value: true });
});

test.afterAll(async ({ api }) => {
await api.post('/settings/Accounts_ForgetUserSessionOnWindowClose', { value: false });
});

test('Login using credentials and reload to get logged out', async ({ page, context }) => {
await poRegistration.username.type('user1');
await poRegistration.inputPassword.type(DEFAULT_USER_CREDENTIALS.password);
await poRegistration.btnLogin.click();

await expect(page.locator('role=heading[name="Welcome to Rocket.Chat"]')).toBeVisible();

const newPage = await context.newPage();
await newPage.goto('/home');

await expect(newPage.locator('role=button[name="Login"]')).toBeVisible();
});
});
});
2 changes: 1 addition & 1 deletion ee/apps/ddp-streamer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
],
"author": "Rocket.Chat",
"dependencies": {
"@rocket.chat/apps-engine": "1.44.0",
"@rocket.chat/apps-engine": "1.45.0-alpha.864",
"@rocket.chat/core-services": "workspace:^",
"@rocket.chat/core-typings": "workspace:^",
"@rocket.chat/emitter": "~0.31.25",
Expand Down
2 changes: 1 addition & 1 deletion ee/packages/presence/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"@babel/core": "~7.22.20",
"@babel/preset-env": "~7.22.20",
"@babel/preset-typescript": "~7.22.15",
"@rocket.chat/apps-engine": "1.44.0",
"@rocket.chat/apps-engine": "1.45.0-alpha.864",
"@rocket.chat/eslint-config": "workspace:^",
"@rocket.chat/rest-typings": "workspace:^",
"@types/node": "^14.18.63",
Expand Down
2 changes: 1 addition & 1 deletion packages/apps/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"/dist"
],
"dependencies": {
"@rocket.chat/apps-engine": "1.44.0",
"@rocket.chat/apps-engine": "1.45.0-alpha.864",
"@rocket.chat/core-typings": "workspace:^",
"@rocket.chat/model-typings": "workspace:^"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core-services/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"extends": "../../package.json"
},
"dependencies": {
"@rocket.chat/apps-engine": "1.44.0",
"@rocket.chat/apps-engine": "1.45.0-alpha.864",
"@rocket.chat/core-typings": "workspace:^",
"@rocket.chat/icons": "^0.36.0",
"@rocket.chat/message-parser": "workspace:^",
Expand Down
5 changes: 4 additions & 1 deletion packages/core-services/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,11 @@ export {
IUserService,
};

const disabledEnvVar = String(process.env.DISABLE_DB_WATCHERS).toLowerCase();

export const dbWatchersDisabled =
['yes', 'true'].includes(String(process.env.DISABLE_DB_WATCHERS).toLowerCase()) || process.env.NODE_ENV !== 'production';
(process.env.NODE_ENV === 'production' && ['yes', 'true'].includes(disabledEnvVar)) ||
(process.env.NODE_ENV !== 'production' && !['no', 'false'].includes(disabledEnvVar));

// TODO think in a way to not have to pass the service name to proxify here as well
export const Authorization = proxifyWithWait<IAuthorization>('authorization');
Expand Down
2 changes: 1 addition & 1 deletion packages/core-typings/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"/dist"
],
"dependencies": {
"@rocket.chat/apps-engine": "1.44.0",
"@rocket.chat/apps-engine": "1.45.0-alpha.864",
"@rocket.chat/icons": "^0.36.0",
"@rocket.chat/message-parser": "workspace:^",
"@rocket.chat/ui-kit": "workspace:~"
Expand Down
2 changes: 1 addition & 1 deletion packages/fuselage-ui-kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"@babel/preset-env": "~7.22.20",
"@babel/preset-react": "~7.22.15",
"@babel/preset-typescript": "~7.22.15",
"@rocket.chat/apps-engine": "1.44.0",
"@rocket.chat/apps-engine": "1.45.0-alpha.864",
"@rocket.chat/core-typings": "workspace:^",
"@rocket.chat/eslint-config": "workspace:^",
"@rocket.chat/fuselage": "^0.57.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/rest-typings/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"/dist"
],
"dependencies": {
"@rocket.chat/apps-engine": "1.44.0",
"@rocket.chat/apps-engine": "1.45.0-alpha.864",
"@rocket.chat/core-typings": "workspace:^",
"@rocket.chat/message-parser": "workspace:^",
"@rocket.chat/ui-kit": "workspace:~",
Expand Down
Loading

0 comments on commit 9d755af

Please sign in to comment.