Review fixes

This commit is contained in:
Roman Zabaluev 2023-08-17 17:22:35 +08:00
parent 361b03eb15
commit befee78ce7

View file

@ -47,6 +47,12 @@ interface IsPermittedConfig {
rbacFlag: boolean;
}
const valueMatches = (regexp: string | undefined, val: string | undefined) => {
if (!val) return false;
if (!regexp) return true;
return new RegExp(regexp).test(val);
};
/**
* @description it the logic behind depending on the roles whether a certain action
* is permitted or not the philosophy is inspired from Headless UI libraries where
@ -94,15 +100,6 @@ export function isPermitted({
const resourcePermissions = clusterMap.get(resource);
if (!resourcePermissions) return false;
const valueMatches = (
regexp: string | undefined,
val: string | undefined
) => {
if (!val) return false;
if (!regexp) return true;
return new RegExp(regexp).test(val);
};
const actions = Array.isArray(action) ? action : [action];
return actions.every((a) => {