Skip to content

Commit

Permalink
Merge branch 'develop' into feat/implement-adr-0061
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] authored Oct 17, 2024
2 parents f464772 + f63d8e2 commit 15f9f51
Show file tree
Hide file tree
Showing 16 changed files with 283 additions and 27 deletions.
1 change: 1 addition & 0 deletions apps/meteor/app/api/server/helpers/parseJsonQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export async function parseJsonQuery(api: PartialThis): Promise<{
'/api/v1/integrations.list',
'/api/v1/custom-user-status.list',
'/api/v1/custom-sounds.list',
'/api/v1/channels.list',
].includes(route);

const isUnsafeQueryParamsAllowed = process.env.ALLOW_UNSAFE_QUERY_AND_FIELDS_API_PARAMS?.toUpperCase() === 'TRUE';
Expand Down
10 changes: 9 additions & 1 deletion apps/meteor/app/api/server/v1/channels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
isChannelsConvertToTeamProps,
isChannelsSetReadOnlyProps,
isChannelsDeleteProps,
isChannelsListProps,
isChannelsFilesListProps,
} from '@rocket.chat/rest-typings';
import { Meteor } from 'meteor/meteor';
Expand Down Expand Up @@ -929,14 +930,21 @@ API.v1.addRoute(
permissionsRequired: {
GET: { permissions: ['view-c-room', 'view-joined-room'], operation: 'hasAny' },
},
validateParams: isChannelsListProps,
},
{
async get() {
const { offset, count } = await getPaginationItems(this.queryParams);
const { sort, fields, query } = await this.parseJsonQuery();
const hasPermissionToSeeAllPublicChannels = await hasPermissionAsync(this.userId, 'view-c-room');

const ourQuery: Record<string, any> = { ...query, t: 'c' };
const { _id } = this.queryParams;

const ourQuery = {
...query,
...(_id ? { _id } : {}),
t: 'c',
};

if (!hasPermissionToSeeAllPublicChannels) {
const roomIds = (
Expand Down
6 changes: 3 additions & 3 deletions apps/meteor/app/e2e/server/functions/resetRoomKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export async function resetRoomKey(roomId: string, userId: string, newRoomKey: s
}
}

function pushToLimit(
export function pushToLimit(
arr: NonNullable<IRoom['usersWaitingForE2EKeys']>,
item: NonNullable<IRoom['usersWaitingForE2EKeys']>[number],
limit = 50,
Expand All @@ -99,15 +99,15 @@ function pushToLimit(
}

async function writeAndNotify(updateOps: AnyBulkWriteOperation<ISubscription>[], notifySubs: ISubscription[]) {
await Subscriptions.col.bulkWrite(updateOps);
await Subscriptions.col.bulkWrite([...updateOps]);
notifySubs.forEach((sub) => {
void notifyOnSubscriptionChanged(sub);
});
notifySubs.length = 0;
updateOps.length = 0;
}

function replicateMongoSlice(keyId: string, sub: ISubscription) {
export function replicateMongoSlice(keyId: string, sub: ISubscription) {
if (!sub.E2EKey) {
return;
}
Expand Down
13 changes: 7 additions & 6 deletions apps/meteor/client/providers/AppsProvider/AppsProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useDebouncedCallback } from '@rocket.chat/fuselage-hooks';
import { usePermission, useStream } from '@rocket.chat/ui-contexts';
import { useQuery, useQueryClient } from '@tanstack/react-query';
import type { ReactNode } from 'react';
import React, { useEffect, useState } from 'react';
import React, { useEffect } from 'react';

import { AppClientOrchestratorInstance } from '../../apps/orchestrator';
import { AppsContext } from '../../contexts/AppsContext';
Expand Down Expand Up @@ -47,8 +47,6 @@ const AppsProvider = ({ children }: AppsProviderProps) => {
const { isLoading: isLicenseInformationLoading, data: { license, limits } = {} } = useLicense({ loadValues: true });
const isEnterprise = isLicenseInformationLoading ? undefined : !!license;

const [marketplaceError, setMarketplaceError] = useState<Error>();

const invalidateAppsCountQuery = useInvalidateAppsCountQueryCallback();
const invalidateLicenseQuery = useInvalidateLicense();

Expand Down Expand Up @@ -80,8 +78,7 @@ const AppsProvider = ({ children }: AppsProviderProps) => {
const result = await AppClientOrchestratorInstance.getAppsFromMarketplace(isAdminUser);
queryClient.invalidateQueries(['marketplace', 'apps-stored']);
if (result.error && typeof result.error === 'string') {
setMarketplaceError(new Error(result.error));
return [];
throw new Error(result.error);
}
return result.apps;
},
Expand Down Expand Up @@ -125,7 +122,11 @@ const AppsProvider = ({ children }: AppsProviderProps) => {
children={children}
value={{
installedApps: getAppState(isMarketplaceDataLoading, installedAppsData),
marketplaceApps: getAppState(isMarketplaceDataLoading, marketplaceAppsData, marketplaceError),
marketplaceApps: getAppState(
isMarketplaceDataLoading,
marketplaceAppsData,
marketplace.error instanceof Error ? marketplace.error : undefined,
),
privateApps: getAppState(isMarketplaceDataLoading, privateAppsData),

reload: async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const MarketplaceHeader = ({ title, unsupportedVersion }: { title: string; unsup
<PageHeader title={title}>
{result.isLoading && <GenericResourceUsageSkeleton mi={16} />}

{result.isSuccess && !result.data.hasUnlimitedApps && (
{!unsupportedVersion && result.isSuccess && !result.data.hasUnlimitedApps && (
<Margins inline={16}>
<EnabledAppsCount
{...result.data}
Expand All @@ -56,10 +56,6 @@ const MarketplaceHeader = ({ title, unsupportedVersion }: { title: string; unsup
)}

<ButtonGroup wrap align='end'>
{!unsupportedVersion && result.isSuccess && !result.data.hasUnlimitedApps && (
<EnabledAppsCount {...result.data} context={context} />
)}

{!unsupportedVersion && isAdmin && result.isSuccess && !result.data.hasUnlimitedApps && context !== 'private' && (
<Button
onClick={() => {
Expand All @@ -71,7 +67,7 @@ const MarketplaceHeader = ({ title, unsupportedVersion }: { title: string; unsup
)}

{isAdmin && context === 'private' && <Button onClick={handleClickPrivate}>{t('Upload_private_app')}</Button>}
{isAdmin && result.isSuccess && !privateAppsEnabled && context === 'private' && <UpdateRocketChatButton />}
{unsupportedVersion && isAdmin && context !== 'private' && <UpdateRocketChatButton />}
</ButtonGroup>
</PageHeader>
);
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/ee/server/apps/orchestrator.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ export class AppServerOrchestrator {
continue;
}

await this.getManager().loadOne(app.getID());
await this.getManager().loadOne(app.getID(), true);
}
/* eslint-enable no-await-in-loop */

Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/ee/server/apps/storage/AppRealStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class AppRealStorage extends AppMetadataStorage {
}

public async update(item: IAppStorageItem): Promise<IAppStorageItem> {
await this.db.updateOne({ id: item.id }, { $set: item });
await this.db.updateOne({ id: item.id, _id: item._id }, { $set: item });
return this.retrieveOne(item.id);
}

Expand Down
4 changes: 1 addition & 3 deletions apps/meteor/tests/end-to-end/api/channels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,9 +373,7 @@ describe('[Channels]', () => {
.get(api('channels.list'))
.set(credentials)
.query({
query: JSON.stringify({
_id: testChannel._id,
}),
_id: testChannel._id,
})
.expect('Content-Type', 'application/json')
.expect(200)
Expand Down
40 changes: 40 additions & 0 deletions apps/meteor/tests/mocks/data/subscriptions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { faker } from '@faker-js/faker';

export function mockSubscription() {
const data: Record<string, any> = {
_id: faker.string.uuid(),
rid: faker.string.uuid(),
name: faker.person.firstName(),
t: 'd',
alert: true,
E2EKey: faker.datatype.boolean() ? faker.string.uuid() : undefined,
E2ESuggestedKey: faker.datatype.boolean() ? faker.string.uuid() : undefined,
oldRoomKeys: faker.datatype.boolean() ? generateOldKeys() : undefined,
u: {
_id: faker.person.firstName(),
},
};

return data;
}

function generateOldKeys() {
const amount = faker.number.int({ min: 1, max: 10 });
const oldRoomKeys = [];
for (let i = 0; i < amount; i++) {
oldRoomKeys.push({
E2EKey: faker.string.uuid(),
ts: new Date(),
e2eKeyId: faker.string.uuid().slice(12),
});
}
return oldRoomKeys;
}

export function generateMultipleSubs(amount: number) {
const subs = [];
for (let i = 0; i < amount; i++) {
subs.push(mockSubscription());
}
return subs;
}
Loading

0 comments on commit 15f9f51

Please sign in to comment.