-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(HMS-2721): add a hook for the permissions
This change add the useIdmPermissions which is used to check the required permissions on the UI. Signed-off-by: Alejandro Visiedo <[email protected]>
- Loading branch information
Showing
1 changed file
with
42 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,42 @@ | ||
import { usePermissions } from '@redhat-cloud-services/frontend-components-utilities/RBACHook'; | ||
|
||
const APP = 'idmsvc'; | ||
|
||
export interface IdmPermissions { | ||
isLoading: boolean; | ||
permissions: { | ||
hasTokenCreate: boolean | undefined; | ||
hasDomainsRead: boolean | undefined; | ||
hasDomainsList: boolean | undefined; | ||
hasDomainsUpdate: boolean | undefined; | ||
hasDomainsDelete: boolean | undefined; | ||
}; | ||
} | ||
|
||
/** | ||
* @returns useIdmPermissions encapsulate the permissions for | ||
* domain integration service. | ||
*/ | ||
const useIdmPermissions = (): IdmPermissions => { | ||
const { hasAccess: hasTokensCreate, isLoading: isLoadingTokensCreate } = usePermissions(APP, [APP + ':token:create'], false, true); | ||
const { hasAccess: hasDomainsRead, isLoading: isLoadingDomainsRead } = usePermissions(APP, [APP + ':domains:read'], false, true); | ||
const { hasAccess: hasDomainsUpdate, isLoading: isLoadingDomainsUpdate } = usePermissions(APP, [APP + ':domains:update'], false, true); | ||
const { hasAccess: hasDomainsDelete, isLoading: isLoadingDomainsDelete } = usePermissions(APP, [APP + ':domains:delete'], false, true); | ||
const { hasAccess: hasDomainsList, isLoading: isLoadingDomainsList } = usePermissions(APP, [APP + ':domains:list'], false, true); | ||
|
||
const isLoading: boolean = | ||
isLoadingTokensCreate || isLoadingDomainsRead || isLoadingDomainsUpdate || isLoadingDomainsDelete || isLoadingDomainsList; | ||
|
||
return { | ||
isLoading: isLoading, | ||
permissions: { | ||
hasTokenCreate: hasTokensCreate, | ||
hasDomainsRead: hasDomainsRead, | ||
hasDomainsList: hasDomainsList, | ||
hasDomainsUpdate: hasDomainsUpdate, | ||
hasDomainsDelete: hasDomainsDelete, | ||
}, | ||
}; | ||
}; | ||
|
||
export default useIdmPermissions; |