Skip to content

Commit 15baefa

Browse files
chore: Permissions store (#36264)
1 parent af26263 commit 15baefa

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

apps/meteor/app/authorization/client/hasPermission.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ const createPermissionValidator =
2626
}
2727
}
2828

29-
const permission = Models.Permissions.findOne(permissionId, {
30-
fields: { roles: 1 },
31-
});
29+
const permission = Models.Permissions.state.get(permissionId);
3230
const roles = permission?.roles ?? [];
3331

3432
return roles.some((roleId) => {
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
import type { IPermission } from '@rocket.chat/core-typings';
2+
import type { StoreApi, UseBoundStore } from 'zustand';
23

34
import { PrivateCachedCollection } from '../../../../client/lib/cachedCollections';
5+
import type { IDocumentMapStore } from '../../../../client/lib/cachedCollections/DocumentMapStore';
6+
7+
type PermissionsStore = {
8+
use: UseBoundStore<StoreApi<IDocumentMapStore<IPermission>>>;
9+
readonly state: IDocumentMapStore<IPermission>;
10+
};
411

512
export const AuthzCachedCollection = new PrivateCachedCollection<IPermission>({
613
name: 'permissions',
714
eventType: 'notify-logged',
815
});
916

10-
export const Permissions = AuthzCachedCollection.collection;
17+
// We are restricting the type of the collection, removing Minimongo methods to avoid further usage, until full conversion to zustand store
18+
export const Permissions = AuthzCachedCollection.collection as PermissionsStore;

apps/meteor/client/views/admin/permissions/hooks/useFilteredPermissions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export const useFilteredPermissions = ({ filter }: { filter: string }) => {
99
const { t } = useTranslation();
1010

1111
const mappedPermissionKeys = useMemo(() => {
12-
const permissions = Permissions.find().fetch();
12+
const permissions = Array.from(Permissions.state.records.values());
1313
return mapPermissionKeys({ t, permissions });
1414
}, [t]);
1515

0 commit comments

Comments
 (0)