-
Notifications
You must be signed in to change notification settings - Fork 370
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: [UIE-8129] - add new user permissions api with prefix (#11146)
- Loading branch information
1 parent
9209bc2
commit d52d108
Showing
9 changed files
with
136 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@linode/api-v4": Added | ||
--- | ||
|
||
New IAM endpoints and types ([#11146](https://github.com/linode/manager/pull/11146)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { BETA_API_ROOT } from '../constants'; | ||
import Request, { setData, setMethod, setURL } from '../request'; | ||
import { IamUserPermissions } from './types'; | ||
|
||
/** | ||
* getUserPermissions | ||
* | ||
* Returns the full permissions structure for this User. This includes all entities on | ||
* the Account alongside what level of access this User has to each of them. | ||
* | ||
* @param username { number } the username to look up. | ||
* | ||
*/ | ||
export const getUserPermissions = (username: string) => | ||
Request<IamUserPermissions>( | ||
setURL( | ||
`${BETA_API_ROOT}/iam/role-permissions/users/${encodeURIComponent( | ||
username | ||
)}` | ||
), | ||
setMethod('GET') | ||
); | ||
/** | ||
* updateUserPermissions | ||
* | ||
* Update the permissions a User has. | ||
* | ||
* @param username { number } ID of the client to be viewed. | ||
* @param data { object } the Permissions object to update. | ||
* | ||
*/ | ||
export const updateUserPermissions = ( | ||
username: string, | ||
data: Partial<IamUserPermissions> | ||
) => | ||
Request<IamUserPermissions>( | ||
setURL( | ||
`${BETA_API_ROOT}/iam/role-permissions/users/${encodeURIComponent( | ||
username | ||
)}` | ||
), | ||
setMethod('PUT'), | ||
setData(data) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './types'; | ||
|
||
export * from './iam'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
export interface IamUserPermissions { | ||
account_access: AccountAccessType[]; | ||
resource_access: ResourceAccess[]; | ||
} | ||
|
||
type ResourceType = | ||
| 'linode' | ||
| 'firewall' | ||
| 'nodebalancer' | ||
| 'longview' | ||
| 'domain' | ||
| 'stackscript' | ||
| 'image' | ||
| 'volume' | ||
| 'database' | ||
| 'account' | ||
| 'vpc'; | ||
|
||
type AccountAccessType = | ||
| 'account_linode_admin' | ||
| 'linode_creator' | ||
| 'firewall_creator'; | ||
|
||
type RoleType = 'linode_contributor' | 'firewall_admin'; | ||
|
||
export interface ResourceAccess { | ||
resource_id: number; | ||
resource_type: ResourceType; | ||
roles: RoleType[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@linode/manager": Added | ||
--- | ||
|
||
mock data and query for new permission api ([#11146](https://github.com/linode/manager/pull/11146)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { IamUserPermissions } from '@linode/api-v4'; | ||
import Factory from 'src/factories/factoryProxy'; | ||
|
||
export const userPermissionsFactory = Factory.Sync.makeFactory<IamUserPermissions>( | ||
{ | ||
account_access: [ | ||
'account_linode_admin', | ||
'linode_creator', | ||
'firewall_creator', | ||
], | ||
resource_access: [ | ||
{ | ||
resource_id: 12345678, | ||
resource_type: 'linode', | ||
roles: ['linode_contributor'], | ||
}, | ||
{ | ||
resource_id: 45678901, | ||
resource_type: 'firewall', | ||
roles: ['firewall_admin'], | ||
}, | ||
], | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { APIError, IamUserPermissions } from '@linode/api-v4'; | ||
import { iamQueries } from './queries'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
|
||
export const useAccountUserPermissions = (username: string) => { | ||
return useQuery<IamUserPermissions, APIError[]>( | ||
iamQueries.user(username)._ctx.permissions | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { getUserPermissions } from '@linode/api-v4'; | ||
import { createQueryKeys } from '@lukemorales/query-key-factory'; | ||
|
||
export const iamQueries = createQueryKeys('iam', { | ||
user: (username: string) => ({ | ||
contextQueries: { | ||
permissions: { | ||
queryFn: () => getUserPermissions(username), | ||
queryKey: null, | ||
}, | ||
}, | ||
queryKey: [username], | ||
}), | ||
}); |