@@ -5,18 +5,23 @@ export const usePermissions = (action: string | string[]): boolean[] => {
55 const userPermissions = ServerContext . useStoreState ( state => state . server . permissions ) ;
66
77 return useDeepMemo ( ( ) => {
8+ if ( userPermissions [ 0 ] === '*' ) {
9+ return ( [ ] as boolean [ ] ) . fill (
10+ true , 0 , Array . isArray ( action ) ? action . length : 1 ,
11+ ) ;
12+ }
13+
814 return ( Array . isArray ( action ) ? action : [ action ] )
915 . map ( permission => (
10- // Allows checking for any permission matching a name, for example files.*
11- // will return if the user has any permission under the file.XYZ namespace.
12- (
13- permission . endsWith ( '.*' ) &&
14- permission !== 'websocket.*' &&
15- userPermissions . filter ( p => p . startsWith ( permission . split ( '.' ) [ 0 ] ) ) . length > 0
16- ) ||
17- // Otherwise just check if the entire permission exists in the array or not.
18- userPermissions . indexOf ( permission ) >= 0
19- ) ,
20- ) ;
16+ // Allows checking for any permission matching a name, for example files.*
17+ // will return if the user has any permission under the file.XYZ namespace.
18+ (
19+ permission . endsWith ( '.*' ) &&
20+ permission !== 'websocket.*' &&
21+ userPermissions . filter ( p => p . startsWith ( permission . split ( '.' ) [ 0 ] ) ) . length > 0
22+ ) ||
23+ // Otherwise just check if the entire permission exists in the array or not.
24+ userPermissions . indexOf ( permission ) >= 0
25+ ) ) ;
2126 } , [ action , userPermissions ] ) ;
2227} ;
0 commit comments