From 9347ee8d78cb1c2080edb987b76d8ddf42361e5e Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sun, 29 Mar 2020 21:30:33 -0700 Subject: [PATCH] Fix permissions handling logic for admins/owners --- resources/scripts/plugins/usePermissions.ts | 27 ++++++++++++--------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/resources/scripts/plugins/usePermissions.ts b/resources/scripts/plugins/usePermissions.ts index 02f57ebde..974e09434 100644 --- a/resources/scripts/plugins/usePermissions.ts +++ b/resources/scripts/plugins/usePermissions.ts @@ -5,18 +5,23 @@ export const usePermissions = (action: string | string[]): boolean[] => { const userPermissions = ServerContext.useStoreState(state => state.server.permissions); return useDeepMemo(() => { + if (userPermissions[0] === '*') { + return ([] as boolean[]).fill( + true, 0, Array.isArray(action) ? action.length : 1, + ); + } + 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('.*') && - permission !== 'websocket.*' && - 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 - ), - ); + // 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('.*') && + permission !== 'websocket.*' && + 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 ]); };