From 12ab40f4cc2f3e69453c9baa36c5a43e527abe71 Mon Sep 17 00:00:00 2001 From: Anastasiia Alekseenko Date: Wed, 14 Jan 2026 13:39:13 +0100 Subject: [PATCH 1/2] feat: [UIE-9988] - IAM Delegation: fix payload for changing role flow --- .../src/features/IAM/Shared/utilities.test.ts | 82 ++++++++++++++++++- .../src/features/IAM/Shared/utilities.ts | 12 ++- 2 files changed, 89 insertions(+), 5 deletions(-) diff --git a/packages/manager/src/features/IAM/Shared/utilities.test.ts b/packages/manager/src/features/IAM/Shared/utilities.test.ts index 9773013e7c2..e8c68667524 100644 --- a/packages/manager/src/features/IAM/Shared/utilities.test.ts +++ b/packages/manager/src/features/IAM/Shared/utilities.test.ts @@ -23,7 +23,7 @@ import { import type { EntitiesRole, ExtendedRoleView, RoleView } from './types'; import type { AssignNewRoleFormValues } from './utilities'; -import type { EntityAccess } from '@linode/api-v4'; +import type { EntityAccess, IamUserRoles } from '@linode/api-v4'; const accountAccess = 'account_access'; const entityAccess = 'entity_access'; @@ -229,6 +229,86 @@ describe('changeUserRole', () => { }) ).toEqual(expectedRoles); }); + + it('should return an object of updated users roles with resource access', () => { + const assignedRoles: IamUserRoles = { + account_access: [], + entity_access: [ + { + id: 12345678, + roles: ['linode_admin', 'linode_contributor'], + type: 'linode', + }, + ], + }; + + const initialRole = 'linode_admin'; + const newRole = 'linode_contributor'; + + const expectedRoles = { + account_access: [], + entity_access: [ + { + id: 12345678, + roles: ['linode_contributor'], + type: 'linode', + }, + ], + }; + expect( + changeUserRole({ + access: entityAccess, + assignedRoles, + initialRole, + newRole, + }) + ).toEqual(expectedRoles); + }); + + it('should return an object of updated users roles with resource access', () => { + const assignedRoles: IamUserRoles = { + account_access: [], + entity_access: [ + { + id: 12345678, + roles: ['linode_admin', 'linode_contributor'], + type: 'linode', + }, + { + id: 1234, + roles: ['linode_admin'], + type: 'linode', + }, + ], + }; + + const initialRole = 'linode_admin'; + const newRole = 'linode_contributor'; + + const expectedRoles = { + account_access: [], + entity_access: [ + { + id: 12345678, + roles: ['linode_contributor'], + type: 'linode', + }, + { + id: 1234, + roles: ['linode_contributor'], + type: 'linode', + }, + ], + }; + expect( + changeUserRole({ + access: entityAccess, + assignedRoles, + initialRole, + newRole, + }) + ).toEqual(expectedRoles); + }); }); describe('deleteUserRole', () => { diff --git a/packages/manager/src/features/IAM/Shared/utilities.ts b/packages/manager/src/features/IAM/Shared/utilities.ts index 91a1b4cadbc..9053c157334 100644 --- a/packages/manager/src/features/IAM/Shared/utilities.ts +++ b/packages/manager/src/features/IAM/Shared/utilities.ts @@ -226,10 +226,14 @@ export const changeUserRole = ({ return { ...assignedRoles, entity_access: assignedRoles.entity_access.map( - (resource: EntityAccess) => ({ - ...resource, - roles: resource.roles.map((role: EntityRoleType) => - role === initialRole ? (newRole as EntityRoleType) : role + (entity: EntityAccess) => ({ + ...entity, + roles: Array.from( + new Set( + entity.roles.map((role: EntityRoleType) => + role === initialRole ? (newRole as EntityRoleType) : role + ) + ) ), }) ), From 003d5ed2ed3e585014cef54198113517da5e248a Mon Sep 17 00:00:00 2001 From: Anastasiia Alekseenko Date: Wed, 14 Jan 2026 13:56:08 +0100 Subject: [PATCH 2/2] Added changeset: IAM Delegation: fix payload for changing role flow --- packages/manager/.changeset/pr-13279-fixed-1768395368171.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 packages/manager/.changeset/pr-13279-fixed-1768395368171.md diff --git a/packages/manager/.changeset/pr-13279-fixed-1768395368171.md b/packages/manager/.changeset/pr-13279-fixed-1768395368171.md new file mode 100644 index 00000000000..52992986797 --- /dev/null +++ b/packages/manager/.changeset/pr-13279-fixed-1768395368171.md @@ -0,0 +1,5 @@ +--- +"@linode/manager": Fixed +--- + +IAM Delegation: fix payload for changing role flow ([#13279](https://github.com/linode/manager/pull/13279))