Skip to content

Commit ab5bf99

Browse files
authored
fix: can not enable apps without permissions (RocketChat#36672)
1 parent 1d8fa0b commit ab5bf99

2 files changed

Lines changed: 11 additions & 9 deletions

File tree

.changeset/proud-drinks-crash.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@rocket.chat/meteor": patch
3+
---
4+
5+
fixes an issue where some apps that don't need permission would have grantedPermissions as null making it impossible to activate the app

apps/meteor/ee/server/apps/storage/AppRealStorage.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,15 @@ export class AppRealStorage extends AppMetadataStorage {
4848
return items;
4949
}
5050

51-
public async update(item: IAppStorageItem): Promise<IAppStorageItem> {
51+
public async update({ permissionsGranted, ...item }: IAppStorageItem): Promise<IAppStorageItem> {
5252
const updateQuery: UpdateFilter<IAppStorageItem> = {
53-
$set: item,
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 } }),
5458
};
5559

56-
// Note: This is really important, since we currently store the permissionsGranted as null if none are present
57-
// in the App's manifest. So, if there was a permissionGranted and it was removed, we must see the app as having
58-
// no permissionsGranted at all (which means default permissions). So we must actively unset the field.
59-
if (!item.permissionsGranted) {
60-
updateQuery.$unset = { permissionsGranted: 1 };
61-
}
62-
6360
return this.db.findOneAndUpdate({ id: item.id, _id: item._id }, updateQuery, { returnDocument: 'after' });
6461
}
6562

0 commit comments

Comments
 (0)