Skip to content

Commit

Permalink
Merge branch 'develop' into fix/usersInRoleList
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] authored May 31, 2024
2 parents 3b06b2b + 3fc12f6 commit e077ec0
Show file tree
Hide file tree
Showing 82 changed files with 1,882 additions and 537 deletions.
6 changes: 6 additions & 0 deletions .changeset/cuddly-cycles-nail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@rocket.chat/fuselage-ui-kit": minor
"@rocket.chat/ui-kit": minor
---

Introduced new elements for apps to select users
5 changes: 5 additions & 0 deletions .changeset/cuddly-maps-peel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": patch
---

Fixed streams being called when the user is not logged in
5 changes: 5 additions & 0 deletions .changeset/four-onions-camp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/meteor': patch
---

When using `DISABLE_DB_WATCHERS=true` this fixes message updates with URLs that were missing the link preview.
8 changes: 8 additions & 0 deletions .changeset/slow-cars-press.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@rocket.chat/i18n': minor
'@rocket.chat/meteor': minor
---

Introduced a new setting which doesn't allow users to access encrypted rooms until E2EE is configured and also doesn't allow users to send un-encrypted messages in encrypted rooms.

New room setup for E2EE feature which helps users to setup their E2EE keys and introduced states to E2EE feature.
7 changes: 7 additions & 0 deletions .changeset/smooth-knives-turn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@rocket.chat/meteor": patch
---

Executing a logout and login action in the same "tab/instance", some streams were not being recreated, causing countless types of bugs.

PS: as a workaround reloading after logout or login in also solves the problem.
5 changes: 5 additions & 0 deletions .changeset/sweet-kiwis-scream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": minor
---

Clicking on a message attachment link in the Desktop App will now initiate a direct download of the attachment only when the attachment is not a PDF file
4 changes: 2 additions & 2 deletions .github/workflows/stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ jobs:
steps:
- uses: actions/stale@v5
with:
days-before-issue-stale: 10
days-before-issue-close: 4
days-before-issue-stale: 14
days-before-issue-close: 14
any-of-labels: 'stat: need more info,stat: waiting response'
stale-issue-label: "stat: no response"
stale-issue-message: "This issue has been marked as stale because there has been no further activity in the last 10 days. If the issue remains stale for the next 4 days (a total of 14 days with no activity), then it will be assumed that the question has been resolved and the issue will be automatically closed."
Expand Down
52 changes: 38 additions & 14 deletions apps/meteor/app/api/server/lib/emailInbox.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type { IEmailInbox } from '@rocket.chat/core-typings';
import { EmailInbox, Users } from '@rocket.chat/models';
import type { Filter, InsertOneResult, Sort, UpdateResult, WithId } from 'mongodb';
import type { DeleteResult, Filter, InsertOneResult, Sort } from 'mongodb';

import { notifyOnEmailInboxChanged } from '../../../lib/server/lib/notifyListener';

export const findEmailInboxes = async ({
query = {},
Expand Down Expand Up @@ -34,33 +36,31 @@ export const findEmailInboxes = async ({
};
};

export const findOneEmailInbox = async ({ _id }: { _id: string }): Promise<IEmailInbox | null> => {
return EmailInbox.findOneById(_id);
};
export const insertOneEmailInbox = async (
userId: string,
emailInboxParams: Pick<IEmailInbox, 'active' | 'name' | 'email' | 'description' | 'senderInfo' | 'department' | 'smtp' | 'imap'>,
): Promise<InsertOneResult<WithId<IEmailInbox>>> => {
): Promise<InsertOneResult<IEmailInbox>> => {
const obj = {
...emailInboxParams,
_createdAt: new Date(),
_updatedAt: new Date(),
_createdBy: await Users.findOneById(userId, { projection: { username: 1 } }),
};
return EmailInbox.insertOne(obj);

const response = await EmailInbox.create(obj);

if (response.insertedId) {
void notifyOnEmailInboxChanged({ _id: response.insertedId, ...obj }, 'inserted');
}

return response;
};

export const updateEmailInbox = async (
emailInboxParams: Pick<IEmailInbox, '_id' | 'active' | 'name' | 'email' | 'description' | 'senderInfo' | 'department' | 'smtp' | 'imap'>,
): Promise<InsertOneResult<WithId<IEmailInbox>> | UpdateResult> => {
): Promise<Pick<IEmailInbox, '_id'> | null> => {
const { _id, active, name, email, description, senderInfo, department, smtp, imap } = emailInboxParams;

const emailInbox = await findOneEmailInbox({ _id });

if (!emailInbox) {
throw new Error('error-invalid-email-inbox');
}

const updateEmailInbox = {
$set: {
active,
Expand All @@ -76,5 +76,29 @@ export const updateEmailInbox = async (
...(department === 'All' && { $unset: { department: 1 as const } }),
};

return EmailInbox.updateOne({ _id }, updateEmailInbox);
const updatedResponse = await EmailInbox.updateById(_id, updateEmailInbox);

if (!updatedResponse.value) {
throw new Error('error-invalid-email-inbox');
}

void notifyOnEmailInboxChanged(
{
...updatedResponse.value,
...(department === 'All' && { department: undefined }),
},
'updated',
);

return updatedResponse.value;
};

export const removeEmailInbox = async (emailInboxId: IEmailInbox['_id']): Promise<DeleteResult> => {
const removeResponse = await EmailInbox.removeById(emailInboxId);

if (removeResponse.deletedCount) {
void notifyOnEmailInboxChanged({ _id: emailInboxId }, 'removed');
}

return removeResponse;
};
34 changes: 23 additions & 11 deletions apps/meteor/app/api/server/v1/email-inbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { check, Match } from 'meteor/check';
import { sendTestEmailToInbox } from '../../../../server/features/EmailInbox/EmailInbox_Outgoing';
import { API } from '../api';
import { getPaginationItems } from '../helpers/getPaginationItems';
import { insertOneEmailInbox, findEmailInboxes, findOneEmailInbox, updateEmailInbox } from '../lib/emailInbox';
import { insertOneEmailInbox, findEmailInboxes, updateEmailInbox, removeEmailInbox } from '../lib/emailInbox';

API.v1.addRoute(
'email-inbox.list',
Expand Down Expand Up @@ -55,12 +55,23 @@ API.v1.addRoute(
let _id: string;

if (!emailInboxParams?._id) {
const emailInbox = await insertOneEmailInbox(this.userId, emailInboxParams);
_id = emailInbox.insertedId.toString();
const { insertedId } = await insertOneEmailInbox(this.userId, emailInboxParams);

if (!insertedId) {
return API.v1.failure('Failed to create email inbox');
}

_id = insertedId;
} else {
_id = emailInboxParams._id;
await updateEmailInbox({ ...emailInboxParams, _id });
const emailInbox = await updateEmailInbox({ ...emailInboxParams, _id: emailInboxParams._id });

if (!emailInbox?._id) {
return API.v1.failure('Failed to update email inbox');
}

_id = emailInbox._id;
}

return API.v1.success({ _id });
},
},
Expand All @@ -79,7 +90,7 @@ API.v1.addRoute(
if (!_id) {
throw new Error('error-invalid-param');
}
const emailInbox = await findOneEmailInbox({ _id });
const emailInbox = await EmailInbox.findOneById(_id);

if (!emailInbox) {
return API.v1.notFound();
Expand All @@ -97,11 +108,12 @@ API.v1.addRoute(
throw new Error('error-invalid-param');
}

const emailInboxes = await EmailInbox.findOneById(_id);
if (!emailInboxes) {
const { deletedCount } = await removeEmailInbox(_id);

if (!deletedCount) {
return API.v1.notFound();
}
await EmailInbox.removeById(_id);

return API.v1.success({ _id });
},
},
Expand All @@ -120,7 +132,7 @@ API.v1.addRoute(

// TODO: Chapter day backend - check if user has permission to view this email inbox instead of null values
// TODO: Chapter day: Remove this endpoint and move search to GET /email-inbox
const emailInbox = await EmailInbox.findOne({ email });
const emailInbox = await EmailInbox.findByEmail(email);

return API.v1.success({ emailInbox });
},
Expand All @@ -140,7 +152,7 @@ API.v1.addRoute(
if (!_id) {
throw new Error('error-invalid-param');
}
const emailInbox = await findOneEmailInbox({ _id });
const emailInbox = await EmailInbox.findOneById(_id);

if (!emailInbox) {
return API.v1.notFound();
Expand Down
9 changes: 9 additions & 0 deletions apps/meteor/app/e2e/client/E2EEState.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export enum E2EEState {
NOT_STARTED = 'NOT_STARTED',
DISABLED = 'DISABLED',
LOADING_KEYS = 'LOADING_KEYS',
READY = 'READY',
SAVE_PASSWORD = 'SAVE_PASSWORD',
ENTER_PASSWORD = 'ENTER_PASSWORD',
ERROR = 'ERROR',
}
15 changes: 15 additions & 0 deletions apps/meteor/app/e2e/client/rocketchat.e2e.room.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const permitedMutations = {
E2ERoomState.ERROR,
E2ERoomState.DISABLED,
E2ERoomState.WAITING_KEYS,
E2ERoomState.CREATING_KEYS,
],
};

Expand Down Expand Up @@ -92,6 +93,10 @@ export class E2ERoom extends Emitter {
logError(`E2E ROOM { state: ${this.state}, rid: ${this.roomId} }`, ...msg);
}

getState() {
return this.state;
}

setState(requestedState) {
const currentState = this.state;
const nextState = filterMutation(currentState, requestedState);
Expand Down Expand Up @@ -208,6 +213,10 @@ export class E2ERoom extends Emitter {

// Initiates E2E Encryption
async handshake() {
if (!e2e.isReady()) {
return;
}

if (this.state !== E2ERoomState.KEYS_RECEIVED && this.state !== E2ERoomState.NOT_STARTED) {
return;
}
Expand Down Expand Up @@ -459,5 +468,11 @@ export class E2ERoom extends Emitter {
}

this.encryptKeyForOtherParticipants();
this.setState(E2ERoomState.READY);
}

onStateChange(cb) {
this.on('STATE_CHANGED', cb);
return () => this.off('STATE_CHANGED', cb);
}
}
Loading

0 comments on commit e077ec0

Please sign in to comment.