-
Notifications
You must be signed in to change notification settings - Fork 429
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add role api keys in UI (#3042)
- Loading branch information
1 parent
0a28ee0
commit b746d09
Showing
7 changed files
with
555 additions
and
24 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
130 changes: 130 additions & 0 deletions
130
frontend/common/services/useMasterAPIKeyWithMasterAPIKeyRole.ts
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,130 @@ | ||
import { Res } from 'common/types/responses' | ||
import { Req } from 'common/types/requests' | ||
import { service } from 'common/service' | ||
|
||
export const masterAPIKeyWithMasterAPIKeyRoleService = service | ||
.enhanceEndpoints({ | ||
addTagTypes: ['MasterAPIKeyWithMasterAPIKeyRole', 'RoleMasterApiKey'], | ||
}) | ||
.injectEndpoints({ | ||
endpoints: (builder) => ({ | ||
deleteMasterAPIKeyWithMasterAPIKeyRoles: builder.mutation< | ||
Res['masterAPIKeyWithMasterAPIKeyRoles'], | ||
Req['deleteMasterAPIKeyWithMasterAPIKeyRoles'] | ||
>({ | ||
invalidatesTags: ['MasterAPIKeyWithMasterAPIKeyRole'], | ||
query: (query: Req['deleteMasterAPIKeyWithMasterAPIKeyRoles']) => ({ | ||
method: 'DELETE', | ||
url: `organisations/${query.org_id}/master-api-keys/${query.prefix}/roles/${query.role_id}/detach-roles-from-master-api-key/`, | ||
}), | ||
}), | ||
getMasterAPIKeyWithMasterAPIKeyRoles: builder.query< | ||
Res['masterAPIKeyWithMasterAPIKeyRoles'], | ||
Req['getMasterAPIKeyWithMasterAPIKeyRoles'] | ||
>({ | ||
providesTags: (res) => [ | ||
{ id: res?.id, type: 'MasterAPIKeyWithMasterAPIKeyRole' }, | ||
], | ||
query: (query: Req['getMasterAPIKeyWithMasterAPIKeyRoles']) => ({ | ||
url: `organisations/${query.org_id}/master-api-keys/${query.prefix}/`, | ||
}), | ||
}), | ||
getRolesMasterAPIKeyWithMasterAPIKeyRoles: builder.query< | ||
Res['masterAPIKeyWithMasterAPIKeyRoles'], | ||
Req['getMasterAPIKeyWithMasterAPIKeyRoles'] | ||
>({ | ||
providesTags: (res) => [ | ||
{ id: res?.id, type: 'MasterAPIKeyWithMasterAPIKeyRole' }, | ||
], | ||
query: (query: Req['getMasterAPIKeyWithMasterAPIKeyRoles']) => ({ | ||
url: `organisations/${query.org_id}/master-api-keys/${query.prefix}/roles/`, | ||
}), | ||
}), | ||
updateMasterAPIKeyWithMasterAPIKeyRoles: builder.mutation< | ||
Res['masterAPIKeyWithMasterAPIKeyRoles'], | ||
Req['updateMasterAPIKeyWithMasterAPIKeyRoles'] | ||
>({ | ||
invalidatesTags: ['MasterAPIKeyWithMasterAPIKeyRole'], | ||
query: (query: Req['updateMasterAPIKeyWithMasterAPIKeyRoles']) => ({ | ||
body: query.body, | ||
method: 'PUT', | ||
url: `organisations/${query.org_id}/master-api-keys/${query.prefix}/`, | ||
}), | ||
}), | ||
// END OF ENDPOINTS | ||
}), | ||
}) | ||
|
||
export async function getMasterAPIKeyWithMasterAPIKeyRoles( | ||
store: any, | ||
data: Req['getMasterAPIKeyWithMasterAPIKeyRoles'], | ||
options?: Parameters< | ||
typeof masterAPIKeyWithMasterAPIKeyRoleService.endpoints.getMasterAPIKeyWithMasterAPIKeyRoles.initiate | ||
>[1], | ||
) { | ||
return store.dispatch( | ||
masterAPIKeyWithMasterAPIKeyRoleService.endpoints.getMasterAPIKeyWithMasterAPIKeyRoles.initiate( | ||
data, | ||
options, | ||
), | ||
) | ||
} | ||
|
||
export async function getRolesMasterAPIKeyWithMasterAPIKeyRoles( | ||
store: any, | ||
data: Req['getMasterAPIKeyWithMasterAPIKeyRoles'], | ||
options?: Parameters< | ||
typeof masterAPIKeyWithMasterAPIKeyRoleService.endpoints.getRolesMasterAPIKeyWithMasterAPIKeyRoles.initiate | ||
>[1], | ||
) { | ||
return store.dispatch( | ||
masterAPIKeyWithMasterAPIKeyRoleService.endpoints.getRolesMasterAPIKeyWithMasterAPIKeyRoles.initiate( | ||
data, | ||
options, | ||
), | ||
) | ||
} | ||
|
||
export async function deleteMasterAPIKeyWithMasterAPIKeyRoles( | ||
store: any, | ||
data: Req['getMasterAPIKeyWithMasterAPIKeyRoles'], | ||
options?: Parameters< | ||
typeof masterAPIKeyWithMasterAPIKeyRoleService.endpoints.deleteMasterAPIKeyWithMasterAPIKeyRoles.initiate | ||
>[1], | ||
) { | ||
return store.dispatch( | ||
masterAPIKeyWithMasterAPIKeyRoleService.endpoints.deleteMasterAPIKeyWithMasterAPIKeyRoles.initiate( | ||
data, | ||
options, | ||
), | ||
) | ||
} | ||
export async function updateMasterAPIKeyWithMasterAPIKeyRoles( | ||
store: any, | ||
data: Req['updateMasterAPIKeyWithMasterAPIKeyRoles'], | ||
options?: Parameters< | ||
typeof masterAPIKeyWithMasterAPIKeyRoleService.endpoints.updateMasterAPIKeyWithMasterAPIKeyRoles.initiate | ||
>[1], | ||
) { | ||
return store.dispatch( | ||
masterAPIKeyWithMasterAPIKeyRoleService.endpoints.updateMasterAPIKeyWithMasterAPIKeyRoles.initiate( | ||
data, | ||
options, | ||
), | ||
) | ||
} | ||
// END OF FUNCTION_EXPORTS | ||
|
||
export const { | ||
useDeleteMasterAPIKeyWithMasterAPIKeyRolesMutation, | ||
useGetMasterAPIKeyWithMasterAPIKeyRolesQuery, | ||
useGetRolesMasterAPIKeyWithMasterAPIKeyRolesQuery, | ||
useUpdateMasterAPIKeyWithMasterAPIKeyRolesMutation, | ||
// END OF EXPORTS | ||
} = masterAPIKeyWithMasterAPIKeyRoleService | ||
|
||
/* Usage examples: | ||
const { data, isLoading } = useGetMasterAPIKeyWithMasterAPIKeyRolesQuery({ id: 2 }, {}) //get hook | ||
const [createMasterAPIKeyWithMasterAPIKeyRoles, { isLoading, data, isSuccess }] = useCreateMasterAPIKeyWithMasterAPIKeyRolesMutation() //create hook | ||
masterAPIKeyWithMasterAPIKeyRoleService.endpoints.getMasterAPIKeyWithMasterAPIKeyRoles.select({id: 2})(store.getState()) //access data from any function | ||
*/ |
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,135 @@ | ||
import { Res } from 'common/types/responses' | ||
import { Req } from 'common/types/requests' | ||
import { service } from 'common/service' | ||
|
||
export const roleMasterApiKeyService = service | ||
.enhanceEndpoints({ | ||
addTagTypes: ['RoleMasterApiKey', 'MasterAPIKeyWithMasterAPIKeyRole'], | ||
}) | ||
.injectEndpoints({ | ||
endpoints: (builder) => ({ | ||
createRoleMasterApiKey: builder.mutation< | ||
Res['roleMasterApiKey'], | ||
Req['createRoleMasterApiKey'] | ||
>({ | ||
invalidatesTags: [ | ||
{ id: 'LIST', type: 'RoleMasterApiKey' }, | ||
'MasterAPIKeyWithMasterAPIKeyRole', | ||
], | ||
query: (query: Req['createRoleMasterApiKey']) => ({ | ||
body: query.body, | ||
method: 'POST', | ||
url: `organisations/${query.org_id}/roles/${query.role_id}/master-api-keys/`, | ||
}), | ||
}), | ||
deleteRoleMasterApiKey: builder.mutation< | ||
Res['roleMasterApiKey'], | ||
Req['deleteRoleMasterApiKey'] | ||
>({ | ||
invalidatesTags: [ | ||
{ id: 'LIST', type: 'RoleMasterApiKey' }, | ||
'MasterAPIKeyWithMasterAPIKeyRole', | ||
], | ||
query: (query: Req['deleteRoleMasterApiKey']) => ({ | ||
method: 'DELETE', | ||
url: `organisations/${query.org_id}/roles/${query.role_id}/master-api-keys/${query.id}/`, | ||
}), | ||
}), | ||
getRoleMasterApiKey: builder.query< | ||
Res['roleMasterApiKey'], | ||
Req['getRoleMasterApiKey'] | ||
>({ | ||
providesTags: (res) => [{ id: res?.id, type: 'RoleMasterApiKey' }], | ||
query: (query: Req['getRoleMasterApiKey']) => ({ | ||
url: `organisations/${query.org_id}/roles/${query.role_id}/master-api-keys/${query.prefix}/`, | ||
}), | ||
}), | ||
updateRoleMasterApiKey: builder.mutation< | ||
Res['roleMasterApiKey'], | ||
Req['updateRoleMasterApiKey'] | ||
>({ | ||
invalidatesTags: (res) => [ | ||
{ id: 'LIST', type: 'RoleMasterApiKey' }, | ||
{ id: res?.id, type: 'RoleMasterApiKey' }, | ||
], | ||
query: (query: Req['updateRoleMasterApiKey']) => ({ | ||
body: query, | ||
method: 'PUT', | ||
url: `organisations/${query.org_id}/roles/${query.role_id}/master-api-keys/${id}/`, | ||
}), | ||
}), | ||
// END OF ENDPOINTS | ||
}), | ||
}) | ||
|
||
export async function createRoleMasterApiKey( | ||
store: any, | ||
data: Req['createRoleMasterApiKey'], | ||
options?: Parameters< | ||
typeof roleMasterApiKeyService.endpoints.createRoleMasterApiKey.initiate | ||
>[1], | ||
) { | ||
return store.dispatch( | ||
roleMasterApiKeyService.endpoints.createRoleMasterApiKey.initiate( | ||
data, | ||
options, | ||
), | ||
) | ||
} | ||
export async function deleteRoleMasterApiKey( | ||
store: any, | ||
data: Req['deleteRoleMasterApiKey'], | ||
options?: Parameters< | ||
typeof roleMasterApiKeyService.endpoints.deleteRoleMasterApiKey.initiate | ||
>[1], | ||
) { | ||
return store.dispatch( | ||
roleMasterApiKeyService.endpoints.deleteRoleMasterApiKey.initiate( | ||
data, | ||
options, | ||
), | ||
) | ||
} | ||
export async function getRoleMasterApiKey( | ||
store: any, | ||
data: Req['getRoleMasterApiKey'], | ||
options?: Parameters< | ||
typeof roleMasterApiKeyService.endpoints.getRoleMasterApiKey.initiate | ||
>[1], | ||
) { | ||
return store.dispatch( | ||
roleMasterApiKeyService.endpoints.getRoleMasterApiKey.initiate( | ||
data, | ||
options, | ||
), | ||
) | ||
} | ||
export async function updateRoleMasterApiKey( | ||
store: any, | ||
data: Req['updateRoleMasterApiKey'], | ||
options?: Parameters< | ||
typeof roleMasterApiKeyService.endpoints.updateRoleMasterApiKey.initiate | ||
>[1], | ||
) { | ||
return store.dispatch( | ||
roleMasterApiKeyService.endpoints.updateRoleMasterApiKey.initiate( | ||
data, | ||
options, | ||
), | ||
) | ||
} | ||
// END OF FUNCTION_EXPORTS | ||
|
||
export const { | ||
useCreateRoleMasterApiKeyMutation, | ||
useDeleteRoleMasterApiKeyMutation, | ||
useGetRoleMasterApiKeyQuery, | ||
useUpdateRoleMasterApiKeyMutation, | ||
// END OF EXPORTS | ||
} = roleMasterApiKeyService | ||
|
||
/* Usage examples: | ||
const { data, isLoading } = useGetRoleMasterApiKeyQuery({ id: 2 }, {}) //get hook | ||
const [createRoleMasterApiKey, { isLoading, data, isSuccess }] = useCreateRoleMasterApiKeyMutation() //create hook | ||
roleMasterApiKeyService.endpoints.getRoleMasterApiKey.select({id: 2})(store.getState()) //access data from any function | ||
*/ |
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
Oops, something went wrong.