From e0d4e67928a9f4eb67222994131fbf8daca031cc Mon Sep 17 00:00:00 2001 From: Bikram Choudhury Date: Tue, 21 Apr 2026 01:20:41 +0530 Subject: [PATCH] swap source-destination content --- .../ContainerCopy/ContainerCopyMessages.ts | 6 +- .../AddManagedIdentity.test.tsx | 2 +- .../AssignPermissions/AddManagedIdentity.tsx | 2 +- ...ddReadPermissionToDefaultIdentity.test.tsx | 70 ++++++++++--------- ...ddReadWritePermissionToDefaultIdentity.tsx | 18 ++--- .../AssignPermissions/AssignPermissions.tsx | 2 +- .../DefaultManagedIdentity.test.tsx | 15 ++++ .../DefaultManagedIdentity.tsx | 4 +- .../AddManagedIdentity.test.tsx.snap | 4 +- ...dPermissionToDefaultIdentity.test.tsx.snap | 14 ++-- .../AssignPermissions.test.tsx.snap | 12 ++-- .../hooks/useManagedIdentity.tsx | 16 ++--- .../hooks/usePermissionsSection.test.tsx | 51 ++++++++------ .../hooks/usePermissionsSection.tsx | 28 ++++---- 14 files changed, 137 insertions(+), 107 deletions(-) diff --git a/src/Explorer/ContainerCopy/ContainerCopyMessages.ts b/src/Explorer/ContainerCopy/ContainerCopyMessages.ts index c3eceeeed..2cbea8c67 100644 --- a/src/Explorer/ContainerCopy/ContainerCopyMessages.ts +++ b/src/Explorer/ContainerCopy/ContainerCopyMessages.ts @@ -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", diff --git a/src/Explorer/ContainerCopy/CreateCopyJob/Screens/AssignPermissions/AddManagedIdentity.test.tsx b/src/Explorer/ContainerCopy/CreateCopyJob/Screens/AssignPermissions/AddManagedIdentity.test.tsx index dbf5301fa..da2b43f0b 100644 --- a/src/Explorer/ContainerCopy/CreateCopyJob/Screens/AssignPermissions/AddManagedIdentity.test.tsx +++ b/src/Explorer/ContainerCopy/CreateCopyJob/Screens/AssignPermissions/AddManagedIdentity.test.tsx @@ -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(); }); diff --git a/src/Explorer/ContainerCopy/CreateCopyJob/Screens/AssignPermissions/AddManagedIdentity.tsx b/src/Explorer/ContainerCopy/CreateCopyJob/Screens/AssignPermissions/AddManagedIdentity.tsx index 86c59611c..3d22ba9c4 100644 --- a/src/Explorer/ContainerCopy/CreateCopyJob/Screens/AssignPermissions/AddManagedIdentity.tsx +++ b/src/Explorer/ContainerCopy/CreateCopyJob/Screens/AssignPermissions/AddManagedIdentity.tsx @@ -53,7 +53,7 @@ const AddManagedIdentity: React.FC = () => { onCancel={() => onToggle(null, false)} onPrimary={handleAddSystemIdentity} > - {ContainerCopyMessages.addManagedIdentity.enablementDescription(copyJobState.target?.account?.name)} + {ContainerCopyMessages.addManagedIdentity.enablementDescription(copyJobState.source?.account?.name)} ); diff --git a/src/Explorer/ContainerCopy/CreateCopyJob/Screens/AssignPermissions/AddReadPermissionToDefaultIdentity.test.tsx b/src/Explorer/ContainerCopy/CreateCopyJob/Screens/AssignPermissions/AddReadPermissionToDefaultIdentity.test.tsx index 4be27382f..cd9e3f7d0 100644 --- a/src/Explorer/ContainerCopy/CreateCopyJob/Screens/AssignPermissions/AddReadPermissionToDefaultIdentity.test.tsx +++ b/src/Explorer/ContainerCopy/CreateCopyJob/Screens/AssignPermissions/AddReadPermissionToDefaultIdentity.test.tsx @@ -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); diff --git a/src/Explorer/ContainerCopy/CreateCopyJob/Screens/AssignPermissions/AddReadWritePermissionToDefaultIdentity.tsx b/src/Explorer/ContainerCopy/CreateCopyJob/Screens/AssignPermissions/AddReadWritePermissionToDefaultIdentity.tsx index 789bf87d1..315a8caf2 100644 --- a/src/Explorer/ContainerCopy/CreateCopyJob/Screens/AssignPermissions/AddReadWritePermissionToDefaultIdentity.tsx +++ b/src/Explorer/ContainerCopy/CreateCopyJob/Screens/AssignPermissions/AddReadWritePermissionToDefaultIdentity.tsx @@ -33,21 +33,21 @@ const AddReadWritePermissionToDefaultIdentity: React.FC { 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) { diff --git a/src/Explorer/ContainerCopy/CreateCopyJob/Screens/AssignPermissions/AssignPermissions.tsx b/src/Explorer/ContainerCopy/CreateCopyJob/Screens/AssignPermissions/AssignPermissions.tsx index 40a657f59..7c9ec9266 100644 --- a/src/Explorer/ContainerCopy/CreateCopyJob/Screens/AssignPermissions/AssignPermissions.tsx +++ b/src/Explorer/ContainerCopy/CreateCopyJob/Screens/AssignPermissions/AssignPermissions.tsx @@ -106,7 +106,7 @@ const AssignPermissions = () => { tokens={{ childrenGap: 20 }} > - {isSameAccount && copyJobState.migrationType === CopyJobMigrationType.Online + {isSameAccount && copyJobState?.migrationType === CopyJobMigrationType.Online ? ContainerCopyMessages.assignPermissions.intraAccountOnlineDescription( copyJobState?.source?.account?.name || "", ) diff --git a/src/Explorer/ContainerCopy/CreateCopyJob/Screens/AssignPermissions/DefaultManagedIdentity.test.tsx b/src/Explorer/ContainerCopy/CreateCopyJob/Screens/AssignPermissions/DefaultManagedIdentity.test.tsx index 93418859f..9561cbbb2 100644 --- a/src/Explorer/ContainerCopy/CreateCopyJob/Screens/AssignPermissions/DefaultManagedIdentity.test.tsx +++ b/src/Explorer/ContainerCopy/CreateCopyJob/Screens/AssignPermissions/DefaultManagedIdentity.test.tsx @@ -69,6 +69,12 @@ const mockUseToggle = useToggle as jest.MockedFunction; 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, }, diff --git a/src/Explorer/ContainerCopy/CreateCopyJob/Screens/AssignPermissions/DefaultManagedIdentity.tsx b/src/Explorer/ContainerCopy/CreateCopyJob/Screens/AssignPermissions/DefaultManagedIdentity.tsx index 92c752171..9bf0b51c1 100644 --- a/src/Explorer/ContainerCopy/CreateCopyJob/Screens/AssignPermissions/DefaultManagedIdentity.tsx +++ b/src/Explorer/ContainerCopy/CreateCopyJob/Screens/AssignPermissions/DefaultManagedIdentity.tsx @@ -32,7 +32,7 @@ const DefaultManagedIdentity: React.FC = () => { return (
- {ContainerCopyMessages.defaultManagedIdentity.description(copyJobState?.target?.account?.name)}   + {ContainerCopyMessages.defaultManagedIdentity.description(copyJobState?.source?.account?.name)}  
= () => { onCancel={() => onToggle(null, false)} onPrimary={handleAddSystemIdentity} > - {ContainerCopyMessages.defaultManagedIdentity.popoverDescription(copyJobState?.target?.account?.name)} + {ContainerCopyMessages.defaultManagedIdentity.popoverDescription(copyJobState?.source?.account?.name)}
); diff --git a/src/Explorer/ContainerCopy/CreateCopyJob/Screens/AssignPermissions/__snapshots__/AddManagedIdentity.test.tsx.snap b/src/Explorer/ContainerCopy/CreateCopyJob/Screens/AssignPermissions/__snapshots__/AddManagedIdentity.test.tsx.snap index 5e565200b..e0ee4b4a2 100644 --- a/src/Explorer/ContainerCopy/CreateCopyJob/Screens/AssignPermissions/__snapshots__/AddManagedIdentity.test.tsx.snap +++ b/src/Explorer/ContainerCopy/CreateCopyJob/Screens/AssignPermissions/__snapshots__/AddManagedIdentity.test.tsx.snap @@ -204,7 +204,7 @@ exports[`AddManagedIdentity Snapshot Tests renders loading state 1`] = ` - 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.
- 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.
- 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.  
- 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.  
- 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.  
- 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.  
- 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.