Apply new eslint rules; default to prettier for styling
This commit is contained in:
parent
f22cce8881
commit
dc84af9937
218 changed files with 3876 additions and 3564 deletions
|
@ -2,23 +2,21 @@ 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] === '*') {
|
||||
return Array(Array.isArray(action) ? action.length : 1).fill(true);
|
||||
}
|
||||
|
||||
return (Array.isArray(action) ? action : [ action ])
|
||||
.map(permission => (
|
||||
return (Array.isArray(action) ? action : [action]).map(
|
||||
(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
|
||||
) ||
|
||||
(permission.endsWith('.*') &&
|
||||
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
|
||||
));
|
||||
}, [ action, userPermissions ]);
|
||||
);
|
||||
}, [action, userPermissions]);
|
||||
};
|
||||
|
|
Reference in a new issue