Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/shy-moles-boil.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": patch
---

fixes an issue where removing the permissions of an app would cause it to never be enabled.
Comment thread
kody-ai[bot] marked this conversation as resolved.
Outdated
Comment thread
d-gubert marked this conversation as resolved.
Outdated
15 changes: 13 additions & 2 deletions apps/meteor/ee/server/apps/storage/AppRealStorage.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { IAppStorageItem } from '@rocket.chat/apps-engine/server/storage';
import { AppMetadataStorage } from '@rocket.chat/apps-engine/server/storage';
import type { Apps } from '@rocket.chat/models';
import type { UpdateFilter } from 'mongodb';

export class AppRealStorage extends AppMetadataStorage {
constructor(private db: typeof Apps) {
Expand Down Expand Up @@ -46,8 +47,18 @@ export class AppRealStorage extends AppMetadataStorage {
}

public async update(item: IAppStorageItem): Promise<IAppStorageItem> {
await this.db.updateOne({ id: item.id, _id: item._id }, { $set: item });
return this.retrieveOne(item.id);
const updateQuery: UpdateFilter<IAppStorageItem> = {
$set: item,
};

// Note: This is really important, since we currently store the permissionsGranted as null if none are present
// in the App's manifest. So, if there was a permissionGranted and it was removed, we must see the app as having
// no permissionsGranted at all (which means default permissions). So we must actively unset the field.
if (!item.permissionsGranted) {
updateQuery.$unset = { permissionsGranted: 1 };
}

return this.db.findOneAndUpdate({ id: item.id, _id: item._id }, updateQuery);
}

public async remove(id: string): Promise<{ success: boolean }> {
Expand Down