Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/manager/.changeset/pr-13279-fixed-1768395368171.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/manager": Fixed
---

IAM Delegation: fix payload for changing role flow ([#13279](https://github.com/linode/manager/pull/13279))
82 changes: 81 additions & 1 deletion packages/manager/src/features/IAM/Shared/utilities.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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', () => {
Expand Down
12 changes: 8 additions & 4 deletions packages/manager/src/features/IAM/Shared/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
)
),
})
),
Expand Down