mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-14 19:44:52 +00:00
feature: add access requests to single env view, with general UI improvements
This commit is contained in:
@@ -17,8 +17,8 @@ export type SubscriptionPlan = {
|
||||
rbac: boolean;
|
||||
secretVersioning: boolean;
|
||||
slug: string;
|
||||
secretApproval: string;
|
||||
secretRotation: string;
|
||||
secretApproval: boolean;
|
||||
secretRotation: boolean;
|
||||
tier: number;
|
||||
workspaceLimit: number;
|
||||
workspacesUsed: number;
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
import { useMemo } from "react";
|
||||
|
||||
import { useSubscription, useWorkspace } from "@app/context";
|
||||
import { useGetAccessApprovalPolicies } from "@app/hooks/api";
|
||||
|
||||
const matchesPath = (folderPath: string, pattern: string) => {
|
||||
const normalizedPath = folderPath === "/" ? "/" : folderPath.replace(/\/$/, "");
|
||||
const normalizedPattern = pattern === "/" ? "/" : pattern.replace(/\/$/, "");
|
||||
|
||||
console.log(normalizedPath, normalizedPattern);
|
||||
|
||||
if (normalizedPath === normalizedPattern) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (normalizedPattern.endsWith("/**")) {
|
||||
const basePattern = normalizedPattern.slice(0, -3); // Remove "/**"
|
||||
|
||||
// Handle root wildcard "/**"
|
||||
if (basePattern === "") {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check if path starts with the base pattern
|
||||
if (normalizedPath === basePattern) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check if path is a subdirectory of the base pattern
|
||||
return normalizedPath.startsWith(`${basePattern}/`);
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
type Params = {
|
||||
secretPath: string;
|
||||
environment: string;
|
||||
};
|
||||
|
||||
export const usePathAccessPolicies = ({ secretPath, environment }: Params) => {
|
||||
const { currentWorkspace } = useWorkspace();
|
||||
const { subscription } = useSubscription();
|
||||
const { data: policies } = useGetAccessApprovalPolicies({
|
||||
projectSlug: currentWorkspace.slug,
|
||||
options: {
|
||||
enabled: subscription.secretApproval
|
||||
}
|
||||
});
|
||||
|
||||
return useMemo(() => {
|
||||
const pathPolicies = policies?.filter(
|
||||
(policy) =>
|
||||
policy.environment.slug === environment && matchesPath(secretPath, policy.secretPath)
|
||||
);
|
||||
|
||||
return {
|
||||
hasPathPolicies: subscription.secretApproval && Boolean(pathPolicies?.length),
|
||||
pathPolicies
|
||||
};
|
||||
}, [secretPath, environment, policies, subscription.secretApproval]);
|
||||
};
|
||||
Reference in New Issue
Block a user