File tree Expand file tree Collapse file tree 3 files changed +40
-1
lines changed
ee/server/apps/communication Expand file tree Collapse file tree 3 files changed +40
-1
lines changed Original file line number Diff line number Diff line change @@ -357,7 +357,18 @@ export class AppsRestApi {
357
357
}
358
358
359
359
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 ] ;
361
372
permissionsGranted = this . bodyParams . permissionsGranted ;
362
373
} catch ( err : any ) {
363
374
return API . v1 . failure ( err . message ) ;
Original file line number Diff line number Diff line change
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
+ } ) ;
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ import './presenceTroubleshoot';
8
8
import '../hooks' ;
9
9
import '../lib/rooms/roomTypes' ;
10
10
import '../lib/settingsRegenerator' ;
11
+ import './appsMigration' ;
11
12
import { performMigrationProcedure } from './migrations' ;
12
13
import { isRunningMs } from '../lib/isRunningMs' ;
13
14
You can’t perform that action at this time.
0 commit comments