Fix permissions handling logic for admins/owners
This commit is contained in:
parent
8bc81c8c4b
commit
9347ee8d78
|
@ -5,18 +5,23 @@ export const usePermissions = (action: string | string[]): boolean[] => {
|
||||||
const userPermissions = ServerContext.useStoreState(state => state.server.permissions);
|
const userPermissions = ServerContext.useStoreState(state => state.server.permissions);
|
||||||
|
|
||||||
return useDeepMemo(() => {
|
return useDeepMemo(() => {
|
||||||
|
if (userPermissions[0] === '*') {
|
||||||
|
return ([] as boolean[]).fill(
|
||||||
|
true, 0, Array.isArray(action) ? action.length : 1,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return (Array.isArray(action) ? action : [ action ])
|
return (Array.isArray(action) ? action : [ action ])
|
||||||
.map(permission => (
|
.map(permission => (
|
||||||
// Allows checking for any permission matching a name, for example files.*
|
// Allows checking for any permission matching a name, for example files.*
|
||||||
// will return if the user has any permission under the file.XYZ namespace.
|
// will return if the user has any permission under the file.XYZ namespace.
|
||||||
(
|
(
|
||||||
permission.endsWith('.*') &&
|
permission.endsWith('.*') &&
|
||||||
permission !== 'websocket.*' &&
|
permission !== 'websocket.*' &&
|
||||||
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.
|
// Otherwise just check if the entire permission exists in the array or not.
|
||||||
userPermissions.indexOf(permission) >= 0
|
userPermissions.indexOf(permission) >= 0
|
||||||
),
|
));
|
||||||
);
|
|
||||||
}, [ action, userPermissions ]);
|
}, [ action, userPermissions ]);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue