mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2026-04-20 21:40:46 +01:00
swap source-destination content
This commit is contained in:
@@ -66,7 +66,7 @@ export default {
|
||||
// Assign Permissions Screen
|
||||
assignPermissions: {
|
||||
crossAccountDescription:
|
||||
"To copy data from the source to the destination container, ensure that the managed identity of the destination account has read-write access to the source account by completing the following steps.",
|
||||
"To copy data from the source to the destination container, ensure that the managed identity of the source account has read-write access to the destination account by completing the following steps.",
|
||||
intraAccountOnlineDescription: (accountName: string) =>
|
||||
`Follow the steps below to enable online copy on your "${accountName}" account.`,
|
||||
crossAccountConfiguration: {
|
||||
@@ -122,7 +122,7 @@ export default {
|
||||
readWritePermissionAssigned: {
|
||||
title: "Read-write permissions assigned to the default identity.",
|
||||
description:
|
||||
"To allow data copy from source to the destination container, provide read-write access on the source account to the default identity of the destination account.",
|
||||
"To allow data copy from source to the destination container, provide read-write access on the destination account to the default identity of the source account.",
|
||||
tooltip: {
|
||||
content: "Learn more about",
|
||||
hrefText: "Read-write permissions.",
|
||||
@@ -130,7 +130,7 @@ export default {
|
||||
},
|
||||
popoverTitle: "Assign read-write permissions to default identity.",
|
||||
popoverDescription:
|
||||
'Assign read-write permissions on the source account to the default identity of the destination account. To confirm, click the "Yes" button.',
|
||||
'Assign read-write permissions on the destination account to the default identity of the source account. To confirm, click the "Yes" button.',
|
||||
},
|
||||
pointInTimeRestore: {
|
||||
title: "Point In Time Restore enabled",
|
||||
|
||||
@@ -198,7 +198,7 @@ describe("AddManagedIdentity", () => {
|
||||
|
||||
it("displays correct enablement description with account name", () => {
|
||||
const expectedDescription = ContainerCopyMessages.addManagedIdentity.enablementDescription(
|
||||
mockCopyJobState.target.account.name,
|
||||
mockCopyJobState.source.account.name,
|
||||
);
|
||||
expect(screen.getByText(expectedDescription)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
@@ -53,7 +53,7 @@ const AddManagedIdentity: React.FC<AddManagedIdentityProps> = () => {
|
||||
onCancel={() => onToggle(null, false)}
|
||||
onPrimary={handleAddSystemIdentity}
|
||||
>
|
||||
{ContainerCopyMessages.addManagedIdentity.enablementDescription(copyJobState.target?.account?.name)}
|
||||
{ContainerCopyMessages.addManagedIdentity.enablementDescription(copyJobState.source?.account?.name)}
|
||||
</PopoverMessage>
|
||||
</Stack>
|
||||
);
|
||||
|
||||
@@ -96,6 +96,10 @@ describe("AddReadWritePermissionToDefaultIdentity Component", () => {
|
||||
properties: {
|
||||
documentEndpoint: "https://source-account.documents.azure.com:443/",
|
||||
},
|
||||
identity: {
|
||||
principalId: "source-principal-id",
|
||||
type: "SystemAssigned",
|
||||
},
|
||||
},
|
||||
databaseId: "source-db",
|
||||
containerId: "source-container",
|
||||
@@ -245,9 +249,9 @@ describe("AddReadWritePermissionToDefaultIdentity Component", () => {
|
||||
|
||||
it("should call handleAddReadWritePermission when primary button is clicked", async () => {
|
||||
mockGetAccountDetailsFromResourceId.mockReturnValue({
|
||||
subscriptionId: "source-sub-id",
|
||||
resourceGroup: "source-rg",
|
||||
accountName: "source-account",
|
||||
subscriptionId: "target-sub-id",
|
||||
resourceGroup: "target-rg",
|
||||
accountName: "target-account",
|
||||
});
|
||||
mockAssignRole.mockResolvedValue({ id: "role-assignment-id" } as RoleAssignmentType);
|
||||
|
||||
@@ -258,7 +262,7 @@ describe("AddReadWritePermissionToDefaultIdentity Component", () => {
|
||||
|
||||
await waitFor(() => {
|
||||
expect(mockGetAccountDetailsFromResourceId).toHaveBeenCalledWith(
|
||||
"/subscriptions/source-sub-id/resourceGroups/source-rg/providers/Microsoft.DocumentDB/databaseAccounts/source-account",
|
||||
"/subscriptions/target-sub-id/resourceGroups/target-rg/providers/Microsoft.DocumentDB/databaseAccounts/target-account",
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -271,9 +275,9 @@ describe("AddReadWritePermissionToDefaultIdentity Component", () => {
|
||||
|
||||
it("should successfully assign role and update context", async () => {
|
||||
mockGetAccountDetailsFromResourceId.mockReturnValue({
|
||||
subscriptionId: "source-sub-id",
|
||||
resourceGroup: "source-rg",
|
||||
accountName: "source-account",
|
||||
subscriptionId: "target-sub-id",
|
||||
resourceGroup: "target-rg",
|
||||
accountName: "target-account",
|
||||
});
|
||||
mockAssignRole.mockResolvedValue({ id: "role-assignment-id" } as RoleAssignmentType);
|
||||
|
||||
@@ -284,10 +288,10 @@ describe("AddReadWritePermissionToDefaultIdentity Component", () => {
|
||||
|
||||
await waitFor(() => {
|
||||
expect(mockAssignRole).toHaveBeenCalledWith(
|
||||
"source-sub-id",
|
||||
"source-rg",
|
||||
"source-account",
|
||||
"target-principal-id",
|
||||
"target-sub-id",
|
||||
"target-rg",
|
||||
"target-account",
|
||||
"source-principal-id",
|
||||
);
|
||||
});
|
||||
|
||||
@@ -298,9 +302,9 @@ describe("AddReadWritePermissionToDefaultIdentity Component", () => {
|
||||
|
||||
it("should handle error when assignRole fails", async () => {
|
||||
mockGetAccountDetailsFromResourceId.mockReturnValue({
|
||||
subscriptionId: "source-sub-id",
|
||||
resourceGroup: "source-rg",
|
||||
accountName: "source-account",
|
||||
subscriptionId: "target-sub-id",
|
||||
resourceGroup: "target-rg",
|
||||
accountName: "target-account",
|
||||
});
|
||||
mockAssignRole.mockRejectedValue(new Error("Permission denied"));
|
||||
|
||||
@@ -323,9 +327,9 @@ describe("AddReadWritePermissionToDefaultIdentity Component", () => {
|
||||
|
||||
it("should handle error without message", async () => {
|
||||
mockGetAccountDetailsFromResourceId.mockReturnValue({
|
||||
subscriptionId: "source-sub-id",
|
||||
resourceGroup: "source-rg",
|
||||
accountName: "source-account",
|
||||
subscriptionId: "target-sub-id",
|
||||
resourceGroup: "target-rg",
|
||||
accountName: "target-account",
|
||||
});
|
||||
mockAssignRole.mockRejectedValue({});
|
||||
|
||||
@@ -350,9 +354,9 @@ describe("AddReadWritePermissionToDefaultIdentity Component", () => {
|
||||
|
||||
it("should show loading state during role assignment", async () => {
|
||||
mockGetAccountDetailsFromResourceId.mockReturnValue({
|
||||
subscriptionId: "source-sub-id",
|
||||
resourceGroup: "source-rg",
|
||||
accountName: "source-account",
|
||||
subscriptionId: "target-sub-id",
|
||||
resourceGroup: "target-rg",
|
||||
accountName: "target-account",
|
||||
});
|
||||
|
||||
mockAssignRole.mockImplementation(
|
||||
@@ -371,9 +375,9 @@ describe("AddReadWritePermissionToDefaultIdentity Component", () => {
|
||||
|
||||
it.skip("should not assign role when assignRole returns falsy", async () => {
|
||||
mockGetAccountDetailsFromResourceId.mockReturnValue({
|
||||
subscriptionId: "source-sub-id",
|
||||
resourceGroup: "source-rg",
|
||||
accountName: "source-account",
|
||||
subscriptionId: "target-sub-id",
|
||||
resourceGroup: "target-rg",
|
||||
accountName: "target-account",
|
||||
});
|
||||
mockAssignRole.mockResolvedValue(null);
|
||||
|
||||
@@ -431,10 +435,10 @@ describe("AddReadWritePermissionToDefaultIdentity Component", () => {
|
||||
...mockContextValue,
|
||||
copyJobState: {
|
||||
...mockContextValue.copyJobState,
|
||||
target: {
|
||||
...mockContextValue.copyJobState.target,
|
||||
source: {
|
||||
...mockContextValue.copyJobState.source,
|
||||
account: {
|
||||
...mockContextValue.copyJobState.target.account!,
|
||||
...mockContextValue.copyJobState.source.account!,
|
||||
identity: {
|
||||
principalId: "",
|
||||
type: "SystemAssigned",
|
||||
@@ -446,9 +450,9 @@ describe("AddReadWritePermissionToDefaultIdentity Component", () => {
|
||||
|
||||
mockUseToggle.mockReturnValue([true, jest.fn()]);
|
||||
mockGetAccountDetailsFromResourceId.mockReturnValue({
|
||||
subscriptionId: "source-sub-id",
|
||||
resourceGroup: "source-rg",
|
||||
accountName: "source-account",
|
||||
subscriptionId: "target-sub-id",
|
||||
resourceGroup: "target-rg",
|
||||
accountName: "target-account",
|
||||
});
|
||||
mockAssignRole.mockResolvedValue({ id: "role-assignment-id" } as RoleAssignmentType);
|
||||
|
||||
@@ -458,7 +462,7 @@ describe("AddReadWritePermissionToDefaultIdentity Component", () => {
|
||||
fireEvent.click(primaryButton);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(mockAssignRole).toHaveBeenCalledWith("source-sub-id", "source-rg", "source-account", "");
|
||||
expect(mockAssignRole).toHaveBeenCalledWith("target-sub-id", "target-rg", "target-account", "");
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -476,9 +480,9 @@ describe("AddReadWritePermissionToDefaultIdentity Component", () => {
|
||||
|
||||
mockUseToggle.mockReturnValue([true, jest.fn()]);
|
||||
mockGetAccountDetailsFromResourceId.mockReturnValue({
|
||||
subscriptionId: "source-sub-id",
|
||||
resourceGroup: "source-rg",
|
||||
accountName: "source-account",
|
||||
subscriptionId: "target-sub-id",
|
||||
resourceGroup: "target-rg",
|
||||
accountName: "target-account",
|
||||
});
|
||||
mockAssignRole.mockResolvedValue({ id: "role-assignment-id" } as RoleAssignmentType);
|
||||
|
||||
|
||||
@@ -33,21 +33,21 @@ const AddReadWritePermissionToDefaultIdentity: React.FC<AddReadWritePermissionTo
|
||||
|
||||
const handleAddReadWritePermission = async () => {
|
||||
const { source, target } = copyJobState;
|
||||
const selectedSourceAccount = source?.account;
|
||||
const selectedTargetAccount = target?.account;
|
||||
|
||||
try {
|
||||
const {
|
||||
subscriptionId: sourceSubscriptionId,
|
||||
resourceGroup: sourceResourceGroup,
|
||||
accountName: sourceAccountName,
|
||||
} = getAccountDetailsFromResourceId(selectedSourceAccount?.id);
|
||||
subscriptionId: targetSubscriptionId,
|
||||
resourceGroup: targetResourceGroup,
|
||||
accountName: targetAccountName,
|
||||
} = getAccountDetailsFromResourceId(selectedTargetAccount?.id);
|
||||
|
||||
setLoading(true);
|
||||
const assignedRole = await assignRole(
|
||||
sourceSubscriptionId,
|
||||
sourceResourceGroup,
|
||||
sourceAccountName,
|
||||
target?.account?.identity?.principalId ?? "",
|
||||
targetSubscriptionId,
|
||||
targetResourceGroup,
|
||||
targetAccountName,
|
||||
source?.account?.identity?.principalId ?? "",
|
||||
);
|
||||
|
||||
if (assignedRole) {
|
||||
|
||||
@@ -106,7 +106,7 @@ const AssignPermissions = () => {
|
||||
tokens={{ childrenGap: 20 }}
|
||||
>
|
||||
<Text variant="medium" style={{ color: "var(--colorNeutralForeground1)" }}>
|
||||
{isSameAccount && copyJobState.migrationType === CopyJobMigrationType.Online
|
||||
{isSameAccount && copyJobState?.migrationType === CopyJobMigrationType.Online
|
||||
? ContainerCopyMessages.assignPermissions.intraAccountOnlineDescription(
|
||||
copyJobState?.source?.account?.name || "",
|
||||
)
|
||||
|
||||
@@ -69,6 +69,12 @@ const mockUseToggle = useToggle as jest.MockedFunction<typeof useToggle>;
|
||||
describe("DefaultManagedIdentity", () => {
|
||||
const mockCopyJobContextValue = {
|
||||
copyJobState: {
|
||||
source: {
|
||||
account: {
|
||||
name: "test-cosmos-account",
|
||||
id: "/subscriptions/test-sub/resourceGroups/test-rg/providers/Microsoft.DocumentDB/databaseAccounts/test-cosmos-account",
|
||||
},
|
||||
},
|
||||
target: {
|
||||
account: {
|
||||
name: "test-cosmos-account",
|
||||
@@ -260,6 +266,12 @@ describe("DefaultManagedIdentity", () => {
|
||||
const contextValueWithoutAccount = {
|
||||
...mockCopyJobContextValue,
|
||||
copyJobState: {
|
||||
source: {
|
||||
account: {
|
||||
name: "",
|
||||
id: "/subscriptions/test-sub/resourceGroups/test-rg/providers/Microsoft.DocumentDB/databaseAccounts/",
|
||||
},
|
||||
},
|
||||
target: {
|
||||
account: {
|
||||
name: "",
|
||||
@@ -277,6 +289,9 @@ describe("DefaultManagedIdentity", () => {
|
||||
const contextValueWithNullAccount = {
|
||||
...mockCopyJobContextValue,
|
||||
copyJobState: {
|
||||
source: {
|
||||
account: null as DatabaseAccount | null,
|
||||
},
|
||||
target: {
|
||||
account: null as DatabaseAccount | null,
|
||||
},
|
||||
|
||||
@@ -32,7 +32,7 @@ const DefaultManagedIdentity: React.FC<AddManagedIdentityProps> = () => {
|
||||
return (
|
||||
<Stack className="defaultManagedIdentityContainer" tokens={{ childrenGap: 15, padding: "0 0 0 20px" }}>
|
||||
<div className="toggle-label">
|
||||
{ContainerCopyMessages.defaultManagedIdentity.description(copyJobState?.target?.account?.name)}
|
||||
{ContainerCopyMessages.defaultManagedIdentity.description(copyJobState?.source?.account?.name)}
|
||||
<InfoTooltip content={managedIdentityTooltip} />
|
||||
</div>
|
||||
<Toggle
|
||||
@@ -54,7 +54,7 @@ const DefaultManagedIdentity: React.FC<AddManagedIdentityProps> = () => {
|
||||
onCancel={() => onToggle(null, false)}
|
||||
onPrimary={handleAddSystemIdentity}
|
||||
>
|
||||
{ContainerCopyMessages.defaultManagedIdentity.popoverDescription(copyJobState?.target?.account?.name)}
|
||||
{ContainerCopyMessages.defaultManagedIdentity.popoverDescription(copyJobState?.source?.account?.name)}
|
||||
</PopoverMessage>
|
||||
</Stack>
|
||||
);
|
||||
|
||||
@@ -204,7 +204,7 @@ exports[`AddManagedIdentity Snapshot Tests renders loading state 1`] = `
|
||||
<span
|
||||
class="themeText css-110"
|
||||
>
|
||||
Enable system-assigned managed identity on the test-target-account. To confirm, click the "Yes" button.
|
||||
Enable system-assigned managed identity on the source-account-name. To confirm, click the "Yes" button.
|
||||
</span>
|
||||
<div
|
||||
class="ms-Stack css-125"
|
||||
@@ -359,7 +359,7 @@ exports[`AddManagedIdentity Snapshot Tests renders with toggle on and popover vi
|
||||
<span
|
||||
class="themeText css-110"
|
||||
>
|
||||
Enable system-assigned managed identity on the test-target-account. To confirm, click the "Yes" button.
|
||||
Enable system-assigned managed identity on the source-account-name. To confirm, click the "Yes" button.
|
||||
</span>
|
||||
<div
|
||||
class="ms-Stack css-125"
|
||||
|
||||
@@ -8,7 +8,7 @@ exports[`AddReadWritePermissionToDefaultIdentity Component Edge Cases should han
|
||||
<span
|
||||
class="toggle-label css-110"
|
||||
>
|
||||
To allow data copy from source to the destination container, provide read-write access on the source account to the default identity of the destination account.
|
||||
To allow data copy from source to the destination container, provide read-write access on the destination account to the default identity of the source account.
|
||||
|
||||
<div
|
||||
data-testid="info-tooltip"
|
||||
@@ -71,7 +71,7 @@ exports[`AddReadWritePermissionToDefaultIdentity Component Edge Cases should han
|
||||
<span
|
||||
class="toggle-label css-110"
|
||||
>
|
||||
To allow data copy from source to the destination container, provide read-write access on the source account to the default identity of the destination account.
|
||||
To allow data copy from source to the destination container, provide read-write access on the destination account to the default identity of the source account.
|
||||
|
||||
<div
|
||||
data-testid="info-tooltip"
|
||||
@@ -134,7 +134,7 @@ exports[`AddReadWritePermissionToDefaultIdentity Component Rendering should rend
|
||||
<span
|
||||
class="toggle-label css-110"
|
||||
>
|
||||
To allow data copy from source to the destination container, provide read-write access on the source account to the default identity of the destination account.
|
||||
To allow data copy from source to the destination container, provide read-write access on the destination account to the default identity of the source account.
|
||||
|
||||
<div
|
||||
data-testid="info-tooltip"
|
||||
@@ -197,7 +197,7 @@ exports[`AddReadWritePermissionToDefaultIdentity Component Rendering should rend
|
||||
<span
|
||||
class="toggle-label css-110"
|
||||
>
|
||||
To allow data copy from source to the destination container, provide read-write access on the source account to the default identity of the destination account.
|
||||
To allow data copy from source to the destination container, provide read-write access on the destination account to the default identity of the source account.
|
||||
|
||||
<div
|
||||
data-testid="info-tooltip"
|
||||
@@ -260,7 +260,7 @@ exports[`AddReadWritePermissionToDefaultIdentity Component Rendering should rend
|
||||
<div
|
||||
data-testid="popover-content"
|
||||
>
|
||||
Assign read-write permissions on the source account to the default identity of the destination account. To confirm, click the "Yes" button.
|
||||
Assign read-write permissions on the destination account to the default identity of the source account. To confirm, click the "Yes" button.
|
||||
</div>
|
||||
<button
|
||||
data-testid="popover-cancel"
|
||||
@@ -285,7 +285,7 @@ exports[`AddReadWritePermissionToDefaultIdentity Component Rendering should rend
|
||||
<span
|
||||
class="toggle-label css-110"
|
||||
>
|
||||
To allow data copy from source to the destination container, provide read-write access on the source account to the default identity of the destination account.
|
||||
To allow data copy from source to the destination container, provide read-write access on the destination account to the default identity of the source account.
|
||||
|
||||
<div
|
||||
data-testid="info-tooltip"
|
||||
@@ -348,7 +348,7 @@ exports[`AddReadWritePermissionToDefaultIdentity Component Rendering should rend
|
||||
<span
|
||||
class="toggle-label css-110"
|
||||
>
|
||||
To allow data copy from source to the destination container, provide read-write access on the source account to the default identity of the destination account.
|
||||
To allow data copy from source to the destination container, provide read-write access on the destination account to the default identity of the source account.
|
||||
|
||||
<div
|
||||
data-testid="info-tooltip"
|
||||
|
||||
@@ -9,7 +9,7 @@ exports[`AssignPermissions Component Accordion Behavior should render accordion
|
||||
<span
|
||||
class="css-110"
|
||||
>
|
||||
To copy data from the source to the destination container, ensure that the managed identity of the destination account has read-write access to the source account by completing the following steps.
|
||||
To copy data from the source to the destination container, ensure that the managed identity of the source account has read-write access to the destination account by completing the following steps.
|
||||
</span>
|
||||
<div
|
||||
class="ms-Stack css-111"
|
||||
@@ -212,7 +212,7 @@ exports[`AssignPermissions Component Edge Cases should calculate correct indent
|
||||
<span
|
||||
class="css-110"
|
||||
>
|
||||
To copy data from the source to the destination container, ensure that the managed identity of the destination account has read-write access to the source account by completing the following steps.
|
||||
To copy data from the source to the destination container, ensure that the managed identity of the source account has read-write access to the destination account by completing the following steps.
|
||||
</span>
|
||||
<div
|
||||
class="ms-Stack css-111"
|
||||
@@ -618,7 +618,7 @@ exports[`AssignPermissions Component Edge Cases should handle missing account na
|
||||
<span
|
||||
class="css-110"
|
||||
>
|
||||
To copy data from the source to the destination container, ensure that the managed identity of the destination account has read-write access to the source account by completing the following steps.
|
||||
To copy data from the source to the destination container, ensure that the managed identity of the source account has read-write access to the destination account by completing the following steps.
|
||||
</span>
|
||||
<div
|
||||
class="ms-Stack css-111"
|
||||
@@ -1153,7 +1153,7 @@ exports[`AssignPermissions Component Permission Groups should render permission
|
||||
<span
|
||||
class="css-110"
|
||||
>
|
||||
To copy data from the source to the destination container, ensure that the managed identity of the destination account has read-write access to the source account by completing the following steps.
|
||||
To copy data from the source to the destination container, ensure that the managed identity of the source account has read-write access to the destination account by completing the following steps.
|
||||
</span>
|
||||
<div
|
||||
class="ms-Stack css-111"
|
||||
@@ -1307,7 +1307,7 @@ exports[`AssignPermissions Component Rendering should render without crashing wi
|
||||
<span
|
||||
class="css-110"
|
||||
>
|
||||
To copy data from the source to the destination container, ensure that the managed identity of the destination account has read-write access to the source account by completing the following steps.
|
||||
To copy data from the source to the destination container, ensure that the managed identity of the source account has read-write access to the destination account by completing the following steps.
|
||||
</span>
|
||||
<div
|
||||
data-testid="shimmer-tree"
|
||||
@@ -1329,7 +1329,7 @@ exports[`AssignPermissions Component Rendering should render without crashing wi
|
||||
<span
|
||||
class="css-110"
|
||||
>
|
||||
To copy data from the source to the destination container, ensure that the managed identity of the destination account has read-write access to the source account by completing the following steps.
|
||||
To copy data from the source to the destination container, ensure that the managed identity of the source account has read-write access to the destination account by completing the following steps.
|
||||
</span>
|
||||
<div
|
||||
data-testid="shimmer-tree"
|
||||
|
||||
@@ -26,18 +26,18 @@ const useManagedIdentity = (
|
||||
const handleAddSystemIdentity = useCallback(async (): Promise<void> => {
|
||||
try {
|
||||
setLoading(true);
|
||||
const selectedTargetAccount = copyJobState?.target?.account;
|
||||
const selectedSourceAccount = copyJobState?.source?.account;
|
||||
const {
|
||||
subscriptionId: targetSubscriptionId,
|
||||
resourceGroup: targetResourceGroup,
|
||||
accountName: targetAccountName,
|
||||
} = getAccountDetailsFromResourceId(selectedTargetAccount?.id) || {};
|
||||
subscriptionId: sourceSubscriptionId,
|
||||
resourceGroup: sourceResourceGroup,
|
||||
accountName: sourceAccountName,
|
||||
} = getAccountDetailsFromResourceId(selectedSourceAccount?.id) || {};
|
||||
|
||||
const updatedAccount = await updateIdentityFn(targetSubscriptionId, targetResourceGroup, targetAccountName);
|
||||
const updatedAccount = await updateIdentityFn(sourceSubscriptionId, sourceResourceGroup, sourceAccountName);
|
||||
if (updatedAccount) {
|
||||
setCopyJobState((prevState) => ({
|
||||
...prevState,
|
||||
target: { ...prevState.target, account: updatedAccount },
|
||||
source: { ...prevState.source, account: updatedAccount },
|
||||
}));
|
||||
}
|
||||
} catch (error) {
|
||||
@@ -46,7 +46,7 @@ const useManagedIdentity = (
|
||||
setContextError(errorMessage);
|
||||
setLoading(false);
|
||||
}
|
||||
}, [copyJobState?.target?.account?.id, updateIdentityFn, setCopyJobState]);
|
||||
}, [copyJobState?.source?.account?.id, updateIdentityFn, setCopyJobState]);
|
||||
|
||||
return { loading, handleAddSystemIdentity };
|
||||
};
|
||||
|
||||
@@ -5,17 +5,17 @@ import { noop } from "underscore";
|
||||
import { CapabilityNames } from "../../../../../../Common/Constants";
|
||||
import * as RbacUtils from "../../../../../../Utils/arm/RbacUtils";
|
||||
import {
|
||||
BackupPolicyType,
|
||||
CopyJobMigrationType,
|
||||
DefaultIdentityType,
|
||||
IdentityType,
|
||||
BackupPolicyType,
|
||||
CopyJobMigrationType,
|
||||
DefaultIdentityType,
|
||||
IdentityType,
|
||||
} from "../../../../Enums/CopyJobEnums";
|
||||
import { CopyJobContextState } from "../../../../Types/CopyJobTypes";
|
||||
import * as CopyJobPrerequisitesCacheModule from "../../../Utils/useCopyJobPrerequisitesCache";
|
||||
import usePermissionSections, {
|
||||
checkTargetHasReadWriteRoleOnSource,
|
||||
PermissionGroupConfig,
|
||||
SECTION_IDS,
|
||||
checkTargetHasReadWriteRoleOnSource,
|
||||
PermissionGroupConfig,
|
||||
SECTION_IDS,
|
||||
} from "./usePermissionsSection";
|
||||
|
||||
jest.mock("../../../../../../Utils/arm/RbacUtils");
|
||||
@@ -284,22 +284,25 @@ describe("usePermissionsSection", () => {
|
||||
describe("Section validation", () => {
|
||||
it("should validate addManagedIdentity section correctly", async () => {
|
||||
const stateWithSystemAssigned = createMockState({
|
||||
target: {
|
||||
source: {
|
||||
account: {
|
||||
id: "target-account-id",
|
||||
name: "target-account",
|
||||
id: "source-account-id",
|
||||
name: "source-account",
|
||||
identity: {
|
||||
type: IdentityType.SystemAssigned,
|
||||
principalId: "principal-123",
|
||||
},
|
||||
properties: {
|
||||
defaultIdentity: DefaultIdentityType.FirstPartyIdentity,
|
||||
backupPolicy: {
|
||||
type: BackupPolicyType.Periodic,
|
||||
},
|
||||
capabilities: [],
|
||||
},
|
||||
location: "",
|
||||
type: "",
|
||||
kind: "",
|
||||
},
|
||||
subscription: undefined,
|
||||
subscriptionId: "",
|
||||
databaseId: "",
|
||||
containerId: "",
|
||||
},
|
||||
@@ -322,22 +325,26 @@ describe("usePermissionsSection", () => {
|
||||
|
||||
it("should validate defaultManagedIdentity section correctly", async () => {
|
||||
const stateWithSystemAssignedIdentity = createMockState({
|
||||
target: {
|
||||
source: {
|
||||
account: {
|
||||
id: "target-account-id",
|
||||
name: "target-account",
|
||||
id: "source-account-id",
|
||||
name: "source-account",
|
||||
identity: {
|
||||
type: IdentityType.SystemAssigned,
|
||||
principalId: "principal-123",
|
||||
},
|
||||
properties: {
|
||||
defaultIdentity: DefaultIdentityType.SystemAssignedIdentity,
|
||||
backupPolicy: {
|
||||
type: BackupPolicyType.Periodic,
|
||||
},
|
||||
capabilities: [],
|
||||
},
|
||||
location: "",
|
||||
type: "",
|
||||
kind: "",
|
||||
},
|
||||
subscription: undefined,
|
||||
subscriptionId: "",
|
||||
databaseId: "",
|
||||
containerId: "",
|
||||
},
|
||||
@@ -384,22 +391,26 @@ describe("usePermissionsSection", () => {
|
||||
mockedRbacUtils.fetchRoleDefinitions.mockResolvedValue(mockRoleDefinitions);
|
||||
|
||||
const state = createMockState({
|
||||
target: {
|
||||
source: {
|
||||
account: {
|
||||
id: "target-account-id",
|
||||
name: "target-account",
|
||||
id: "source-account-id",
|
||||
name: "source-account",
|
||||
identity: {
|
||||
type: IdentityType.SystemAssigned,
|
||||
principalId: "principal-123",
|
||||
},
|
||||
properties: {
|
||||
defaultIdentity: DefaultIdentityType.SystemAssignedIdentity,
|
||||
backupPolicy: {
|
||||
type: BackupPolicyType.Periodic,
|
||||
},
|
||||
capabilities: [],
|
||||
},
|
||||
location: "",
|
||||
type: "",
|
||||
kind: "",
|
||||
},
|
||||
subscription: undefined,
|
||||
subscriptionId: "",
|
||||
databaseId: "",
|
||||
containerId: "",
|
||||
},
|
||||
|
||||
@@ -50,10 +50,10 @@ const PERMISSION_SECTIONS_CONFIG: PermissionSectionConfig[] = [
|
||||
Component: AddManagedIdentity,
|
||||
disabled: true,
|
||||
validate: (state: CopyJobContextState) => {
|
||||
const targetAccountIdentityType = (state?.target?.account?.identity?.type ?? "").toLowerCase();
|
||||
const sourceAccountIdentityType = (state?.source?.account?.identity?.type ?? "").toLowerCase();
|
||||
return (
|
||||
targetAccountIdentityType === IdentityType.SystemAssigned ||
|
||||
targetAccountIdentityType === IdentityType.UserAssigned
|
||||
sourceAccountIdentityType === IdentityType.SystemAssigned ||
|
||||
sourceAccountIdentityType === IdentityType.UserAssigned
|
||||
);
|
||||
},
|
||||
},
|
||||
@@ -63,8 +63,8 @@ const PERMISSION_SECTIONS_CONFIG: PermissionSectionConfig[] = [
|
||||
Component: DefaultManagedIdentity,
|
||||
disabled: true,
|
||||
validate: (state: CopyJobContextState) => {
|
||||
const targetAccountDefaultIdentity = (state?.target?.account?.properties?.defaultIdentity ?? "").toLowerCase();
|
||||
return targetAccountDefaultIdentity === DefaultIdentityType.SystemAssignedIdentity;
|
||||
const sourceAccountDefaultIdentity = (state?.source?.account?.properties?.defaultIdentity ?? "").toLowerCase();
|
||||
return sourceAccountDefaultIdentity === DefaultIdentityType.SystemAssignedIdentity;
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -73,18 +73,18 @@ const PERMISSION_SECTIONS_CONFIG: PermissionSectionConfig[] = [
|
||||
Component: AddReadWritePermissionToDefaultIdentity,
|
||||
disabled: true,
|
||||
validate: async (state: CopyJobContextState) => {
|
||||
const principalId = state?.target?.account?.identity?.principalId;
|
||||
const selectedSourceAccount = state?.source?.account;
|
||||
const principalId = state?.source?.account?.identity?.principalId;
|
||||
const selectedTargetAccount = state?.target?.account;
|
||||
const {
|
||||
subscriptionId: sourceSubscriptionId,
|
||||
resourceGroup: sourceResourceGroup,
|
||||
accountName: sourceAccountName,
|
||||
} = getAccountDetailsFromResourceId(selectedSourceAccount?.id);
|
||||
subscriptionId: targetSubscriptionId,
|
||||
resourceGroup: targetResourceGroup,
|
||||
accountName: targetAccountName,
|
||||
} = getAccountDetailsFromResourceId(selectedTargetAccount?.id);
|
||||
|
||||
const rolesAssigned = await fetchRoleAssignments(
|
||||
sourceSubscriptionId,
|
||||
sourceResourceGroup,
|
||||
sourceAccountName,
|
||||
targetSubscriptionId,
|
||||
targetResourceGroup,
|
||||
targetAccountName,
|
||||
principalId,
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user