Skip to content

Commit

Permalink
chore!: Tag private apps as migrated (exempt from CE limitations) whe…
Browse files Browse the repository at this point in the history
…n moving to the next major (#33420)

* feat: Add migration to grandfather enabled private apps
  • Loading branch information
matheusbsilva137 authored and sampaiodiego committed Oct 9, 2024
1 parent 06a1214 commit c92cfe5
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 1 deletion.
9 changes: 9 additions & 0 deletions apps/meteor/ee/server/apps/storage/AppRealStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ export class AppRealStorage extends AppMetadataStorage {
return items;
}

public async retrieveAllPrivate(): Promise<Map<string, IAppStorageItem>> {
const docs = await this.db.find({ installationSource: 'private' }).toArray();
const items = new Map();

docs.forEach((i) => items.set(i.id, i));

return items;
}

public async update(item: IAppStorageItem): Promise<IAppStorageItem> {
await this.db.updateOne({ id: item.id }, { $set: item });
return this.retrieveOne(item.id);
Expand Down
4 changes: 3 additions & 1 deletion apps/meteor/server/models/raw/AppLogsModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ export class AppsLogsModel extends BaseRaw<any> implements IAppLogsModel {
}

async resetTTLIndex(expireAfterSeconds: number): Promise<void> {
await this.col.dropIndex('_updatedAt_1');
if (await this.col.indexExists('_updatedAt_1')) {
await this.col.dropIndex('_updatedAt_1');
}
await this.col.createIndex({ _updatedAt: 1 }, { expireAfterSeconds });
}
}
1 change: 1 addition & 0 deletions apps/meteor/server/startup/migrations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@ import './v303';
import './v304';
import './v305';
import './v306';
import './v307';

export * from './xrun';
40 changes: 40 additions & 0 deletions apps/meteor/server/startup/migrations/v307.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { Apps } from '@rocket.chat/apps';
import type { AppSignatureManager } from '@rocket.chat/apps-engine/server/managers/AppSignatureManager';
import type { IAppStorageItem } from '@rocket.chat/apps-engine/server/storage';
import { License } from '@rocket.chat/license';

import type { AppRealStorage } from '../../../ee/server/apps/storage';
import { addMigration } from '../../lib/migrations';

addMigration({
version: 307,
name: "Mark all installed private apps as 'migrated'",
async up() {
const isEE = License.hasValidLicense();
if (isEE) {
return;
}

if (!Apps.self) {
throw new Error('Apps Orchestrator not registered.');
}

Apps.initialize();

const sigMan = Apps.getManager()?.getSignatureManager() as AppSignatureManager;
const appsStorage = Apps.getStorage() as AppRealStorage;
const apps = await appsStorage.retrieveAllPrivate();

for await (const app of apps.values()) {
const updatedApp = {
...app,
migrated: true,
} as IAppStorageItem;

await appsStorage.update({
...updatedApp,
signature: await sigMan.signApp(updatedApp),
});
}
},
});
2 changes: 2 additions & 0 deletions packages/apps-engine/src/server/storage/AppMetadataStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export abstract class AppMetadataStorage {

public abstract retrieveAll(): Promise<Map<string, IAppStorageItem>>;

public abstract retrieveAllPrivate(): Promise<Map<string, IAppStorageItem>>;

public abstract update(item: IAppStorageItem): Promise<IAppStorageItem>;

public abstract remove(id: string): Promise<{ success: boolean }>;
Expand Down
16 changes: 16 additions & 0 deletions packages/apps-engine/tests/test-data/storage/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,22 @@ export class TestsAppStorage extends AppMetadataStorage {
});
}

public retrieveAllPrivate(): Promise<Map<string, IAppStorageItem>> {
return new Promise((resolve, reject) => {
this.db.find({ installationSource: 'private' }, (err: Error, docs: Array<IAppStorageItem>) => {
if (err) {
reject(err);
} else {
const items = new Map<string, IAppStorageItem>();

docs.forEach((i) => items.set(i.id, i));

resolve(items);
}
});
});
}

public update(item: IAppStorageItem): Promise<IAppStorageItem> {
return new Promise((resolve, reject) => {
this.db.update({ id: item.id }, item, {}, (err: Error, numOfUpdated: number) => {
Expand Down

0 comments on commit c92cfe5

Please sign in to comment.