React 18 and Vite (#4510)
This commit is contained in:
parent
1bb1b13f6d
commit
21613fa602
244 changed files with 4547 additions and 8933 deletions
|
@ -2,7 +2,7 @@ import { ServerContext } from '@/state/server';
|
|||
import { useDeepCompareMemo } from '@/plugins/useDeepCompareMemo';
|
||||
|
||||
export const usePermissions = (action: string | string[]): boolean[] => {
|
||||
const userPermissions = ServerContext.useStoreState((state) => state.server.permissions);
|
||||
const userPermissions = ServerContext.useStoreState(state => state.server.permissions);
|
||||
|
||||
return useDeepCompareMemo(() => {
|
||||
if (userPermissions[0] === '*') {
|
||||
|
@ -10,13 +10,13 @@ export const usePermissions = (action: string | string[]): boolean[] => {
|
|||
}
|
||||
|
||||
return (Array.isArray(action) ? action : [action]).map(
|
||||
(permission) =>
|
||||
permission =>
|
||||
// Allows checking for any permission matching a name, for example files.*
|
||||
// will return if the user has any permission under the file.XYZ namespace.
|
||||
(permission.endsWith('.*') &&
|
||||
userPermissions.filter((p) => p.startsWith(permission.split('.')[0])).length > 0) ||
|
||||
userPermissions.filter(p => p.startsWith(permission.split('.')?.[0] ?? '')).length > 0) ||
|
||||
// Otherwise just check if the entire permission exists in the array or not.
|
||||
userPermissions.indexOf(permission) >= 0
|
||||
userPermissions.indexOf(permission) >= 0,
|
||||
);
|
||||
}, [action, userPermissions]);
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue