Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 1 addition & 3 deletions apps/meteor/app/authorization/client/hasPermission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ const createPermissionValidator =
}
}

const permission = Models.Permissions.findOne(permissionId, {
fields: { roles: 1 },
});
const permission = Models.Permissions.state.get(permissionId);
const roles = permission?.roles ?? [];

return roles.some((roleId) => {
Expand Down
10 changes: 9 additions & 1 deletion apps/meteor/app/models/client/models/Permissions.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
import type { IPermission } from '@rocket.chat/core-typings';
import type { StoreApi, UseBoundStore } from 'zustand';

import { PrivateCachedCollection } from '../../../../client/lib/cachedCollections';
import type { IDocumentMapStore } from '../../../../client/lib/cachedCollections/DocumentMapStore';

type PermissionsStore = {
use: UseBoundStore<StoreApi<IDocumentMapStore<IPermission>>>;
readonly state: IDocumentMapStore<IPermission>;
};

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

export const Permissions = AuthzCachedCollection.collection;
// We are restricting the type of the collection, removing Minimongo methods to avoid further usage, until full conversion to zustand store
export const Permissions = AuthzCachedCollection.collection as PermissionsStore;
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const useFilteredPermissions = ({ filter }: { filter: string }) => {
const { t } = useTranslation();

const mappedPermissionKeys = useMemo(() => {
const permissions = Permissions.find().fetch();
const permissions = Array.from(Permissions.state.records.values());
return mapPermissionKeys({ t, permissions });
}, [t]);

Expand Down
Loading