Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

ui: check destination path when the environment or oath is changed on the UI

adilsona2f224490ac0
diff --git a/backend/src/ee/services/audit-log/audit-log-types.ts b/backend/src/ee/services/audit-log/audit-log-types.ts
index 91111e889b..4aedb24401 100644
--- a/backend/src/ee/services/audit-log/audit-log-types.ts
+++ b/backend/src/ee/services/audit-log/audit-log-types.ts
@@ -2502,7 +2502,6 @@ interface MoveFolderEvent {
sourcePath: string;
destinationEnvironment: string;
destinationPath: string;
- hasApprovalRequests: boolean;
};
}
diff --git a/backend/src/server/routes/v1/dashboard-router.ts b/backend/src/server/routes/v1/dashboard-router.ts
index d8195907f0..6250b09252 100644
--- a/backend/src/server/routes/v1/dashboard-router.ts
+++ b/backend/src/server/routes/v1/dashboard-router.ts
@@ -8,7 +8,7 @@ import { ProjectPermissionSecretActions } from "@app/ee/services/permission/proj
import { SecretRotationV2Schema } from "@app/ee/services/secret-rotation-v2/secret-rotation-v2-union-schema";
import { DASHBOARD } from "@app/lib/api-docs";
import { BadRequestError, NotFoundError } from "@app/lib/errors";
-import { removeTrailingSlash } from "@app/lib/fn";
+import { prefixWithSlash, removeTrailingSlash } from "@app/lib/fn";
import { OrderByDirection } from "@app/lib/types";
import { readLimit, secretsLimit } from "@app/server/config/rateLimiter";
import { getTelemetryDistinctId } from "@app/server/lib/telemetry";
@@ -1889,6 +1889,10 @@ export const registerDashboardRouter = async (server: FastifyZodProvider) => {
params: z.object({
folderId: z.string().trim().uuid()
}),
+ querystring: z.object({
+ destinationEnvironment: z.string().trim().optional(),
+ destinationPath: z.string().trim().transform(prefixWithSlash).transform(removeTrailingSlash).optional()
+ }),
response: {
200: z.object({
canMove: z.boolean(),
@@ -1896,7 +1900,10 @@ export const registerDashboardRouter = async (server: FastifyZodProvider) => {
blockingType: z
.enum(["dynamic_secret", "secret_rotation", "honey_token", "secret_import", "secret_approval_policy"])
.optional(),
- blockingPath: z.string().optional()
+ blockingPath: z.string().optional(),
+ destinationBlocked: z.boolean().optional(),
+ destinationBlockingPath: z.string().optional(),
+ destinationPolicyName: z.string().optional()
})
}
},
@@ -1907,7 +1914,9 @@ export const registerDashboardRouter = async (server: FastifyZodProvider) => {
actorId: req.permission.id,
actorAuthMethod: req.permission.authMethod,
actorOrgId: req.permission.orgId,
- id: req.params.folderId
+ id: req.params.folderId,
+ destinationEnvironment: req.query.destinationEnvironment,
+ destinationPath: req.query.destinationPath
})
});
};
diff --git a/backend/src/server/routes/v2/secret-folder-router.ts b/backend/src/server/routes/v2/secret-folder-router.ts
index b50a76dfda..ea8b6637fe 100644
--- a/backend/src/server/routes/v2/secret-folder-router.ts
+++ b/backend/src/server/routes/v2/secret-folder-router.ts
@@ -500,8 +500,7 @@ export const registerSecretFolderRouter = async (server: FastifyZodProvider) =>
sourceEnvironment: result.sourceEnvironment,
sourcePath: result.sourcePath,
destinationEnvironment: result.destinationEnvironment,
- destinationPath: result.destinationPath,
- hasApprovalRequests: result.hasApprovalRequests
+ destinationPath: result.destinationPath
}
}
});
diff --git a/backend/src/services/secret-folder/secret-folder-service.ts b/backend/src/services/secret-folder/secret-folder-service.ts
index a3f4d17f2e..3d4a1de735 100644
--- a/backend/src/services/secret-folder/secret-folder-service.ts
+++ b/backend/src/services/secret-folder/secret-folder-service.ts
@@ -25,6 +25,7 @@ import { SecretsOrderBy } from "@app/services/secret/secret-types";
import {
assertFolderMoveAllowed,
buildFolderPath,
+ canActorReadBlock,
checkFolderMoveBlock,
checkFolderMovePolicyBlock,
TFolderMoveAccessScope
@@ -57,6 +58,7 @@ import {
TGetFolderByIdDTO,
TGetFolderByPathDTO,
TGetFolderDTO,
+ TGetFolderMoveEligibilityDTO,
TGetFoldersDeepByEnvsDTO,
TMoveFolderDTO,
TMoveFolderResult,
@@ -1568,14 +1570,18 @@ export const secretFolderServiceFactory = ({
return { sourceBlock, destinationBlock };
};
- // checks whether a folder (and its entire recursive subtree) can be moved.
+ // checks whether a folder (and its entire recursive subtree) can be moved. when a destination is supplied, it
+ // also reports whether the destination is governed by a secret approval policy (a move into such a path is
+ // rejected by moveFolder), so the caller can block the move before attempting it.
const getFolderMoveEligibility = async ({
actor,
actorId,
actorOrgId,
actorAuthMethod,
- id
- }: TGetFolderByIdDTO): Promise<TFolderMoveEligibility> => {
+ id,
+ destinationEnvironment,
+ destinationPath
+ }: TGetFolderMoveEligibilityDTO): Promise<TFolderMoveEligibility> => {
const folder = await getFolderById({ actor, actorId, actorOrgId, actorAuthMethod, id });
// resolve the actor's ability so subtree disclosure is gated by per-path read permission. this is
@@ -1595,28 +1601,45 @@ export const secretFolderServiceFactory = ({
};
// run every read inside a transaction so it hits the primary database rather than a read replica
- const block = await folderDAL.transaction(async (tx) => {
+ const { sourceBlock, destinationBlock } = await folderDAL.transaction(async (tx) => {
// parent folder + full recursive subtree (with paths); reserved folders are already excluded.
const subtree = await folderDAL.findByEnvsDeep({ parentIds: [folder.id] }, tx);
- const { sourceBlock } = await $getFolderMoveBlocks(
+ return $getFolderMoveBlocks(
{
subtree,
projectId: folder.projectId,
sourceEnvironment: folder.environment.envSlug,
sourceFolderPath: folder.path,
+ // the destination scan runs without an access scope so it always detects a governing policy. the
+ // subtree is re-rooted at the moved folder's final location (parent + name), matching the path
+ // moveFolder uses (destinationFolderRoot), so the pre-check and the move evaluate the same paths.
+ destination: destinationEnvironment
+ ? { environment: destinationEnvironment, path: path.join(destinationPath ?? "/", folder.name) }
+ : undefined,
accessScope
},
tx
);
- return sourceBlock;
});
+ // the destination block is always detected (so the modal can block the move in every case); the policy's
+ // path/name are disclosed only when the actor may read that path, matching assertFolderMoveAllowed's gating.
+ const readableDestinationBlock =
+ destinationBlock &&
+ destinationEnvironment &&
+ canActorReadBlock(permission, destinationEnvironment, "secret_approval_policy", destinationBlock.blockingAbsPath)
+ ? destinationBlock
+ : undefined;
+
return {
- canMove: !block,
+ canMove: !sourceBlock,
folderName: folder.name,
- blockingType: block?.blockingType,
- blockingPath: block?.blockingPath
+ blockingType: sourceBlock?.blockingType,
+ blockingPath: sourceBlock?.blockingPath,
+ destinationBlocked: destinationEnvironment ? Boolean(destinationBlock) : undefined,
+ destinationBlockingPath: readableDestinationBlock?.blockingPath,
+ destinationPolicyName: readableDestinationBlock?.policyName
};
};
@@ -1743,7 +1766,7 @@ export const secretFolderServiceFactory = ({
projectId,
sourceEnvironment,
sourceFolderPath,
- destination: { environment: destinationEnvironment, path: destinationPath }
+ destination: { environment: destinationEnvironment, path: destinationFolderRoot }
},
tx
);
@@ -1925,9 +1948,6 @@ export const secretFolderServiceFactory = ({
};
});
- // a missing direct update on either side means that batch was routed through an approval request
- const hasApprovalRequests = moveResults.some((result) => !result.isDestinationUpdated || !result.isSourceUpdated);
-
// now that the move has committed, dispatch side effects once: snapshot + sync each affected source/destination
// secret folder, then snapshot the destination parent (the new subtree); finally invalidate the project secret
// cache. the source root was deleted above, so its source snapshot is always skipped (the sync still runs so
@@ -1955,8 +1975,7 @@ export const secretFolderServiceFactory = ({
sourceEnvironment,
sourcePath: sourceFolderPath,
destinationEnvironment,
- destinationPath,
- hasApprovalRequests
+ destinationPath
};
};
diff --git a/backend/src/services/secret-folder/secret-folder-types.ts b/backend/src/services/secret-folder/secret-folder-types.ts
index cee3be6c3a..d2b89110c8 100644
--- a/backend/src/services/secret-folder/secret-folder-types.ts
+++ b/backend/src/services/secret-folder/secret-folder-types.ts
@@ -56,6 +56,13 @@ export type TGetFolderByIdDTO = {
id: string;
} & Omit<TProjectPermission, "projectId">;
+// eligibility can optionally be checked against a destination; when provided, the result also reports whether the
+// destination is governed by a secret approval policy (a move into such a path is rejected by moveFolder).
+export type TGetFolderMoveEligibilityDTO = TGetFolderByIdDTO & {
+ destinationEnvironment?: string;
+ destinationPath?: string;
+};
+
export type TFolderMoveBlockingType =
| "dynamic_secret"
| "secret_rotation"
@@ -68,6 +75,11 @@ export type TFolderMoveEligibility = {
folderName: string;
blockingType?: TFolderMoveBlockingType;
blockingPath?: string;
+ // present only when a destination was supplied to the eligibility check
+ destinationBlocked?: boolean;
+ // the destination policy's path/name are disclosed only when the actor may read that path
+ destinationBlockingPath?: string;
+ destinationPolicyName?: string;
};
export type TMoveFolderDTO = {
@@ -83,8 +95,6 @@ export type TMoveFolderResult = {
sourcePath: string;
destinationEnvironment: string;
destinationPath: string;
- // true when a secret approval policy turned part of the move into an approval request instead of a direct move
- hasApprovalRequests: boolean;
};
export type TGetFoldersDeepByEnvsDTO = {
diff --git a/frontend/src/hooks/api/dashboard/index.ts b/frontend/src/hooks/api/dashboard/index.ts
index 0ccf04b00d..6da2c80418 100644
--- a/frontend/src/hooks/api/dashboard/index.ts
+++ b/frontend/src/hooks/api/dashboard/index.ts
@@ -1,5 +1,6 @@
export {
useGetAccessibleSecrets,
+ useGetFoldersMoveDestinationEligibility,
useGetFoldersMoveEligibility,
useGetProjectSecretsDetails,
useGetProjectSecretsOverview,
diff --git a/frontend/src/hooks/api/dashboard/queries.tsx b/frontend/src/hooks/api/dashboard/queries.tsx
index 1564f30ba7..c20c780d2d 100644
--- a/frontend/src/hooks/api/dashboard/queries.tsx
+++ b/frontend/src/hooks/api/dashboard/queries.tsx
@@ -15,6 +15,7 @@ import {
FolderMoveEligibilityResponse,
TDashboardProjectSecretsQuickSearch,
TDashboardProjectSecretsQuickSearchResponse,
+ TFolderMoveDestinationCheck,
TGetAccessibleSecretsDTO,
TGetDashboardProjectSecretsByKeys,
TGetDashboardProjectSecretsDetailsDTO,
@@ -88,7 +89,19 @@ export const dashboardKeys = {
isOverride
] as const,
getFolderMoveEligibility: (folderId: string) =>
- [...dashboardKeys.all(), "folder-move-eligibility", folderId] as const
+ [...dashboardKeys.all(), "folder-move-eligibility", folderId] as const,
+ getFolderMoveDestinationEligibility: ({
+ folderId,
+ destinationEnvironment,
+ destinationPath
+ }: TFolderMoveDestinationCheck) =>
+ [
+ ...dashboardKeys.all(),
+ "folder-move-destination-eligibility",
+ folderId,
+ destinationEnvironment,
+ destinationPath
+ ] as const
};
export const fetchProjectSecretsOverview = async ({
@@ -550,9 +563,20 @@ export const useGetSecretValue = (
});
};
-export const fetchFolderMoveEligibility = async (folderId: string) => {
+export const fetchFolderMoveEligibility = async (
+ folderId: string,
+ destination?: { destinationEnvironment: string; destinationPath: string }
+) => {
const { data } = await apiRequest.get<FolderMoveEligibilityResponse>(
- `/api/v1/dashboard/folder/move-check/${folderId}`
+ `/api/v1/dashboard/folder/move-check/${folderId}`,
+ {
+ params: destination
+ ? {
+ destinationEnvironment: destination.destinationEnvironment,
+ destinationPath: destination.destinationPath
+ }
+ : undefined
+ }
);
return data;
@@ -596,3 +620,56 @@ export const useGetFoldersMoveEligibility = (folderIds: string[]) =>
return { isChecking, canMove, blockedFolders };
}
});
+
+export type FolderMoveBlockedDestination = {
+ folderName: string;
+ destinationEnvironment: string;
+ blockingPath?: string;
+ policyName?: string;
+};
+
+// fans out a per-(folder, destination) check to see whether the chosen destination is governed by a secret
+// approval policy. the move is blocked when any check reports destinationBlocked, and fail-closed on error (the
+// backend move would reject it anyway), so the modal never enables a move it cannot complete.
+export const useGetFoldersMoveDestinationEligibility = (checks: TFolderMoveDestinationCheck[]) =>
+ useQueries({
+ queries: checks.map((check) => ({
+ queryKey: dashboardKeys.getFolderMoveDestinationEligibility(check),
+ queryFn: () =>
+ fetchFolderMoveEligibility(check.folderId, {
+ destinationEnvironment: check.destinationEnvironment,
+ destinationPath: check.destinationPath
+ }),
+ enabled: Boolean(check.folderId && check.destinationEnvironment)
+ })),
+ combine: (results) => {
+ const isChecking = results.some((result) => result.isLoading);
+ const hasError = results.some((result) => result.isError);
+
+ // dedupe by folder + destination environment, since the same folder name can be blocked in one
+ // environment but not another (relevant for the multi-environment move).
+ const seen = new Set<string>();
+ const blockedDestinations: FolderMoveBlockedDestination[] = [];
+ results.forEach((result, index) => {
+ const check = checks[index];
+ if (!check) return;
+ const { data } = result;
+ if (result.isSuccess && data?.destinationBlocked) {
+ const key = `${check.folderName}:${check.destinationEnvironment}`;
+ if (!seen.has(key)) {
+ seen.add(key);
+ blockedDestinations.push({
+ folderName: check.folderName,
+ destinationEnvironment: check.destinationEnvironment,
+ blockingPath: data.destinationBlockingPath,
+ policyName: data.destinationPolicyName
+ });
+ }
+ }
+ });
+
+ const isDestinationBlocked = hasError || blockedDestinations.length > 0;
+
+ return { isChecking, isDestinationBlocked, blockedDestinations, hasError };
+ }
+ });
diff --git a/frontend/src/hooks/api/dashboard/types.ts b/frontend/src/hooks/api/dashboard/types.ts
index a53554b24e..f6aa986d96 100644
--- a/frontend/src/hooks/api/dashboard/types.ts
+++ b/frontend/src/hooks/api/dashboard/types.ts
@@ -195,4 +195,16 @@ export type FolderMoveEligibilityResponse = {
folderName: string;
blockingType?: FolderMoveBlockingType;
blockingPath?: string;
+ // present only when the eligibility check was given a destination
+ destinationBlocked?: boolean;
+ // the destination policy's path/name are disclosed only when the actor may read that path
+ destinationBlockingPath?: string;
+ destinationPolicyName?: string;
+};
+
+export type TFolderMoveDestinationCheck = {
+ folderId: string;
+ folderName: string;
+ destinationEnvironment: string;
+ destinationPath: string;
};
diff --git a/frontend/src/pages/secret-manager/OverviewPage/components/SelectionPanel/components/MoveSecretsDialog/MoveSecretsDialog.tsx b/frontend/src/pages/secret-manager/OverviewPage/components/SelectionPanel/components/MoveSecretsDialog/MoveSecretsDialog.tsx
index e42c329837..4f7df576d2 100644
--- a/frontend/src/pages/secret-manager/OverviewPage/components/SelectionPanel/components/MoveSecretsDialog/MoveSecretsDialog.tsx
+++ b/frontend/src/pages/secret-manager/OverviewPage/components/SelectionPanel/components/MoveSecretsDialog/MoveSecretsDialog.tsx
@@ -38,11 +38,19 @@ import {
ProjectPermissionSecretActions,
ProjectPermissionSecretRotationActions
} from "@app/context/ProjectPermissionContext/types";
+import { removeTrailingSlash } from "@app/helpers/string";
import { useDebounce } from "@app/hooks";
import { useMoveSecrets } from "@app/hooks/api";
import { useGetProjectSecretsQuickSearch } from "@app/hooks/api/dashboard";
-import { useGetFoldersMoveEligibility } from "@app/hooks/api/dashboard/queries";
-import { FolderMoveBlockingType } from "@app/hooks/api/dashboard/types";
+import {
+ FolderMoveBlockedDestination,
+ useGetFoldersMoveDestinationEligibility,
+ useGetFoldersMoveEligibility
+} from "@app/hooks/api/dashboard/queries";
+import {
+ FolderMoveBlockingType,
+ TFolderMoveDestinationCheck
+} from "@app/hooks/api/dashboard/types";
import { ProjectEnv } from "@app/hooks/api/projects/types";
import { useMoveFolder } from "@app/hooks/api/secretFolders";
import { TSecretFolder } from "@app/hooks/api/secretFolders/types";
@@ -69,6 +77,80 @@ type ContentProps = Omit<Props, "isOpen" | "onOpenChange"> & {
type OptionValue = { secretPath: string };
+const joinSecretPath = (basePath: string, name: string) =>
+ basePath === "/" ? `/${name}` : `${basePath}/${name}`;
+
+// mirrors the backend cyclic-move rule: a folder cannot be moved into itself or one of its own subfolders.
+const isPathInsideFolder = (destinationPath: string, folderPath: string) =>
+ destinationPath === folderPath || destinationPath.startsWith(`${folderPath}/`);
+
+type MovedFolder = {
+ folderId: string;
+ folderName: string;
+ sourceEnv: string;
+ destinationEnvironment: string;
+};
+
+// builds the per-folder destination checks and flags a self/cyclic move. a self-move is only possible within the
+// same environment, and is detected purely client-side; when detected we drop the checks so no server call fires
+// (the backend would reject the move outright).
+const buildDestinationTargets = ({
+ movedFolders,
+ sourceSecretPath,
+ destinationPath
+}: {
+ movedFolders: MovedFolder[];
+ sourceSecretPath: string;
+ destinationPath?: string;
+}): { checks: TFolderMoveDestinationCheck[]; isSelfMove: boolean } => {
+ if (!destinationPath) return { checks: [], isSelfMove: false };
+
+ const destination = removeTrailingSlash(destinationPath);
+ const base = removeTrailingSlash(sourceSecretPath);
+ let isSelfMove = false;
+ const checks: TFolderMoveDestinationCheck[] = [];
+
+ movedFolders.forEach(({ folderId, folderName, sourceEnv, destinationEnvironment }) => {
+ if (
+ destinationEnvironment === sourceEnv &&
+ isPathInsideFolder(destination, joinSecretPath(base, folderName))
+ ) {
+ isSelfMove = true;
+ }
+ checks.push({ folderId, folderName, destinationEnvironment, destinationPath: destination });
+ });
+
+ return { checks: isSelfMove ? [] : checks, isSelfMove };
+};
+
+// memoizes the destination checks for the moved folders and runs the destination approval-policy eligibility
+// query, returning what the move form needs to gate submit. shared by the single- and multi-environment content
+// so the wiring lives in one place.
+const useDestinationMoveGuard = ({
+ movedFolders,
+ sourceSecretPath,
+ destinationPath
+}: {
+ movedFolders: MovedFolder[];
+ sourceSecretPath: string;
+ destinationPath?: string;
+}) => {
+ const { checks, isSelfMove } = useMemo(
+ () => buildDestinationTargets({ movedFolders, sourceSecretPath, destinationPath }),
+ [movedFolders, sourceSecretPath, destinationPath]
+ );
+
+ const { isChecking, isDestinationBlocked, blockedDestinations } =
+ useGetFoldersMoveDestinationEligibility(checks);
+
+ return {
+ isSelfMove,
+ isCheckingDestination: isChecking,
+ isDestinationBlocked,
+ blockedDestinations
+ };
+};
+
const FolderPathSelect = ({
environments,
projectId,
@@ -215,6 +297,76 @@ const MoveResultsView = ({
);
};
+const formatBlockedDestination = (
+ blocked: FolderMoveBlockedDestination,
+ envNameBySlug: Map<string, string>
+) => {
+ const envName =
+ envNameBySlug.get(blocked.destinationEnvironment) ?? blocked.destinationEnvironment;
+ if (blocked.policyName && blocked.blockingPath) {
+ return `${envName}: the path "${blocked.blockingPath}" is governed by the secret approval policy "${blocked.policyName}", so "${blocked.folderName}" cannot be moved there.`;
+ }
+ return `${envName}: the destination is governed by a secret approval policy, so "${blocked.folderName}" cannot be moved there.`;
+};
+
+// surfaces the two destination-side reasons a move is blocked: a cyclic/self move (client-side) and a destination
+// governed by a secret approval policy (server-side, with a fail-closed "could not verify" fallback).
+const MoveBlockAlerts = ({
+ isSelfMove,
+ isDestinationBlocked,
+ blockedDestinations,
+ environments
+}: {
+ isSelfMove: boolean;
+ isDestinationBlocked: boolean;
+ blockedDestinations: FolderMoveBlockedDestination[];
+ environments: ProjectEnv[];
+}) => {
+ if (!isSelfMove && !isDestinationBlocked) return null;
+
+ const envNameBySlug = new Map(environments.map((env) => [env.slug, env.name]));
+
+ if (isSelfMove) {
+ return (
+ <Alert variant="danger" className="mt-4">
+ <CircleAlertIcon />
+ <AlertTitle>This move is not allowed</AlertTitle>
+ <AlertDescription>
+ You cannot move a folder into itself or one of its own subfolders.
+ </AlertDescription>
+ </Alert>
+ );
+ }
+
+ if (blockedDestinations.length === 0) {
+ return (
+ <Alert variant="danger" className="mt-4">
+ <CircleAlertIcon />
+ <AlertTitle>Could not verify the destination</AlertTitle>
+ <AlertDescription>
+ We could not verify whether the destination allows this move. Please try again.
+ </AlertDescription>
+ </Alert>
+ );
+ }
+
+ return (
+ <Alert variant="danger" className="mt-4">
+ <CircleAlertIcon />
+ <AlertTitle>The destination is protected by a secret approval policy</AlertTitle>
+ <AlertDescription>
+ <ul className="list-disc pl-4">
+ {blockedDestinations.map((blocked) => (
+ <li key={`${blocked.folderName}:${blocked.destinationEnvironment}`}>
+ {formatBlockedDestination(blocked, envNameBySlug)}
+ </li>
+ ))}
+ </ul>
+ </AlertDescription>
+ </Alert>
+ );
+};
+
const SingleEnvContent = ({
onComplete,
onClose,
@@ -260,6 +412,29 @@ const SingleEnvContent = ({
Boolean(selectedPath?.secretPath) &&
(sourceSecretPath !== selectedPath?.secretPath || selectedEnvironment !== sourceEnv.slug);
+ // a single-env move relocates every selected folder (taken from the source environment) to the chosen
+ // destination environment.
+ const movedFolders = useMemo<MovedFolder[]>(
+ () =>
+ Object.values(folders)
+ .map((folderRecord) => folderRecord[sourceEnv.slug])
+ .filter((folder): folder is TSecretFolder => Boolean(folder))
+ .map((folder) => ({
+ folderId: folder.id,
+ folderName: folder.name,
+ sourceEnv: sourceEnv.slug,
+ destinationEnvironment: selectedEnvironment
+ })),
+ [folders, sourceEnv.slug, selectedEnvironment]
+ );
+
+ const { isSelfMove, isCheckingDestination, isDestinationBlocked, blockedDestinations } =
+ useDestinationMoveGuard({
+ movedFolders,
+ sourceSecretPath,
+ destinationPath: destinationSelected ? selectedPath?.secretPath : undefined
+ });
+
const handleFormSubmit = async (data: TSingleEnvFormSchema) => {
if (!selectedPath) {
createNotification({
@@ -466,6 +641,12 @@ const SingleEnvContent = ({
</FieldDescription>
</FieldContent>
</Field>
+ <MoveBlockAlerts
+ isSelfMove={isSelfMove}
+ isDestinationBlocked={isDestinationBlocked}
+ blockedDestinations={blockedDestinations}
+ environments={environments}
+ />
{showOverwriteOption && (
<Controller
control={control}
@@ -502,7 +683,13 @@ const SingleEnvContent = ({
<Button
type="submit"
variant="project"
- isDisabled={!destinationSelected || isSubmitting}
+ isDisabled={
+ !destinationSelected ||
+ isSubmitting ||
+ isSelfMove ||
+ isCheckingDestination ||
+ isDestinationBlocked
+ }
isPending={isSubmitting}
>
{moveCopy.action}
@@ -580,6 +767,30 @@ const MultiEnvContent = ({
const destinationSelected =
Boolean(selectedPath?.secretPath) && sourceSecretPath !== selectedPath?.secretPath;
+ // a multi-env move relocates each folder within its own environment, so the destination environment of
+ // every check is that folder's source environment.
+ const movedFolders = useMemo<MovedFolder[]>(() => {
+ const result: MovedFolder[] = [];
+ Object.values(folders).forEach((folderRecord) =>
+ Object.entries(folderRecord).forEach(([envSlug, folder]) => {
+ result.push({
+ folderId: folder.id,
+ folderName: folder.name,
+ sourceEnv: envSlug,
+ destinationEnvironment: envSlug
+ });
+ })
+ );
+ return result;
+ }, [folders]);
+
+ const { isSelfMove, isCheckingDestination, isDestinationBlocked, blockedDestinations } =
+ useDestinationMoveGuard({
+ movedFolders,
+ sourceSecretPath,
+ destinationPath: destinationSelected ? selectedPath?.secretPath : undefined
+ });
+
const environmentsToBeSkipped = useMemo(() => {
if (!destinationSelected) return [];
@@ -859,6 +1070,12 @@ const MultiEnvContent = ({
</AlertDescription>
</Alert>
)}
+ <MoveBlockAlerts
+ isSelfMove={isSelfMove}
+ isDestinationBlocked={isDestinationBlocked}
+ blockedDestinations={blockedDestinations}
+ environments={environments}
+ />
{showOverwriteOption && (
<Controller
control={control}
@@ -895,7 +1112,13 @@ const MultiEnvContent = ({
<Button
type="submit"
variant="project"
- isDisabled={!destinationSelected || isSubmitting}
+ isDisabled={
+ !destinationSelected ||
+ isSubmitting ||
+ isSelfMove ||
+ isCheckingDestination ||
+ isDestinationBlocked
+ }
isPending={isSubmitting}
>
{moveCopy.action}