|
| 1 | +import type { AppStatus } from '@rocket.chat/apps-engine/definition/AppStatus'; |
| 2 | +import type { IAppInfo } from '@rocket.chat/apps-engine/definition/metadata'; |
| 3 | +import type { ISetting } from '@rocket.chat/apps-engine/definition/settings'; |
| 4 | +import type { IMarketplaceInfo } from '@rocket.chat/apps-engine/server/marketplace'; |
1 | 5 | import type { IAppStorageItem } from '@rocket.chat/apps-engine/server/storage'; |
2 | 6 | import { AppMetadataStorage } from '@rocket.chat/apps-engine/server/storage'; |
3 | 7 | import type { Apps } from '@rocket.chat/models'; |
@@ -48,20 +52,49 @@ export class AppRealStorage extends AppMetadataStorage { |
48 | 52 | return items; |
49 | 53 | } |
50 | 54 |
|
51 | | - public async update({ permissionsGranted, ...item }: IAppStorageItem): Promise<IAppStorageItem> { |
| 55 | + public async remove(id: string): Promise<{ success: boolean }> { |
| 56 | + await this.db.deleteOne({ id }); |
| 57 | + return { success: true }; |
| 58 | + } |
| 59 | + |
| 60 | + public async updatePartialAndReturnDocument( |
| 61 | + { _id, ...item }: IAppStorageItem, |
| 62 | + { unsetPermissionsGranted = false } = {}, |
| 63 | + ): Promise<IAppStorageItem> { |
| 64 | + if (!_id) { |
| 65 | + throw new Error('Property _id is required to update an app storage item'); |
| 66 | + } |
| 67 | + |
52 | 68 | const updateQuery: UpdateFilter<IAppStorageItem> = { |
53 | | - $set: { ...item, ...(permissionsGranted && { permissionsGranted }) }, |
54 | | - // Note: This is really important, since we currently store the permissionsGranted as null if none are present |
55 | | - // in the App's manifest. So, if there was a permissionGranted and it was removed, we must see the app as having |
56 | | - // no permissionsGranted at all (which means default permissions). So we must actively unset the field. |
57 | | - ...(!permissionsGranted && { $unset: { permissionsGranted: 1 } }), |
| 69 | + $set: item, |
58 | 70 | }; |
59 | 71 |
|
60 | | - return this.db.findOneAndUpdate({ id: item.id, _id: item._id }, updateQuery, { returnDocument: 'after' }); |
| 72 | + if (unsetPermissionsGranted) { |
| 73 | + delete item.permissionsGranted; |
| 74 | + updateQuery.$unset = { permissionsGranted: 1 }; |
| 75 | + } |
| 76 | + |
| 77 | + return this.db.findOneAndUpdate({ _id }, updateQuery, { returnDocument: 'after' }); |
61 | 78 | } |
62 | 79 |
|
63 | | - public async remove(id: string): Promise<{ success: boolean }> { |
64 | | - await this.db.deleteOne({ id }); |
65 | | - return { success: true }; |
| 80 | + public async updateStatus(_id: string, status: AppStatus): Promise<boolean> { |
| 81 | + const result = await this.db.updateOne({ _id }, { $set: { status } }); |
| 82 | + return result.modifiedCount > 0; |
| 83 | + } |
| 84 | + |
| 85 | + public async updateSetting(_id: string, setting: ISetting): Promise<boolean> { |
| 86 | + const result = await this.db.updateOne({ _id }, { $set: { [`settings.${setting.id}`]: setting } }); |
| 87 | + |
| 88 | + return result.modifiedCount > 0; |
| 89 | + } |
| 90 | + |
| 91 | + public async updateAppInfo(_id: string, info: IAppInfo): Promise<boolean> { |
| 92 | + const result = await this.db.updateOne({ _id }, { $set: { info } }); |
| 93 | + return result.modifiedCount > 0; |
| 94 | + } |
| 95 | + |
| 96 | + public async updateMarketplaceInfo(_id: string, marketplaceInfo: IMarketplaceInfo[]): Promise<boolean> { |
| 97 | + const result = await this.db.updateOne({ _id }, { $set: { marketplaceInfo } }); |
| 98 | + return result.modifiedCount > 0; |
66 | 99 | } |
67 | 100 | } |
0 commit comments