Skip to content

Commit 0d3180f

Browse files
committed
fix: fix wrong marketplaceInfo value being stored in the database
1 parent c8c8eaa commit 0d3180f

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

apps/meteor/ee/server/apps/communication/rest.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,18 @@ export class AppsRestApi {
357357
}
358358

359359
buff = Buffer.from(await downloadResponse.arrayBuffer());
360-
marketplaceInfo = (await marketplaceResponse.json()) as any;
360+
const parsedMarketplaceResponse = await marketplaceResponse.json();
361+
362+
// Note: marketplace responds with an array of the marketplace info on the app, but it is expected
363+
// to always have one element since we are fetching a specific app version.
364+
if (parsedMarketplaceResponse.length !== 1) {
365+
orchestrator
366+
.getRocketChatLogger()
367+
.error('Error getting the App information from the Marketplace:', parsedMarketplaceResponse);
368+
throw new Error('Invalid response from the Marketplace');
369+
}
370+
371+
marketplaceInfo = parsedMarketplaceResponse[0];
361372
permissionsGranted = this.bodyParams.permissionsGranted;
362373
} catch (err: any) {
363374
return API.v1.failure(err.message);
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { Apps } from '@rocket.chat/models';
2+
import { Meteor } from 'meteor/meteor';
3+
4+
/**
5+
* This migration is to fix the marketplaceInfo field in the Apps collection.
6+
* This is being done, since our whole codebase expects marketplaceInfo to be an object and not an array.
7+
* This bug can make so that apps that need a subscription were not correctly validated and could be enabled
8+
* even after the subscription was expired.
9+
*
10+
* Also, apps that were enterprise-only could be enabled even if the server didn't have a subscription.
11+
*/
12+
Meteor.startup(async () => {
13+
// Find all the apps where marketplaceInfo is an array
14+
const apps = await Apps.find(
15+
{ marketplaceInfo: { $type: 'array' } },
16+
{
17+
projection: {
18+
marketplaceInfo: 1,
19+
},
20+
},
21+
).toArray();
22+
23+
// For each app set the marketplaceInfo to be the first element of the array
24+
for await (const app of apps) {
25+
await Apps.update({ _id: app._id }, { $set: { marketplaceInfo: app.marketplaceInfo[0] } });
26+
}
27+
});

apps/meteor/server/startup/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import './presenceTroubleshoot';
88
import '../hooks';
99
import '../lib/rooms/roomTypes';
1010
import '../lib/settingsRegenerator';
11+
import './appsMigration';
1112
import { performMigrationProcedure } from './migrations';
1213
import { isRunningMs } from '../lib/isRunningMs';
1314

0 commit comments

Comments
 (0)