Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(HMS-2721): integrate check permissions #65

Merged
merged 3 commits into from
May 30, 2024
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ make dev-static port=9999

The below will be necessary to deploy on the dev cluster.

- Install nvm by: `curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash`.
- Config node 18 by: `nvm install 18; nvm use 18`.
- Run `cp -vf config/bonfire.example.yaml config/bonfire.yaml`.
- Update the `config/bonfire.yaml` file by following the TODO
placeholders.
Expand Down
4 changes: 4 additions & 0 deletions src/AppContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ReactNode, createContext, useState } from 'react';
import { Domain } from './Api/idmsvc';
import { VerifyState } from './Routes/WizardPage/Components/VerifyRegistry/VerifyRegistry';
import React from 'react';
import useIdmPermissions, { IdmPermissions } from './Hooks/useIdmPermissions';

/**
* It represents the application context so common events and properties
Expand Down Expand Up @@ -50,6 +51,7 @@ export interface AppContextType {
/** Set the ephemeral domain information. */
setDomain: (value: Domain) => void;
};
rbac: IdmPermissions;
}

/**
Expand All @@ -76,6 +78,7 @@ export const AppContext = createContext<AppContextType>({
domain: {} as Domain,
setDomain: () => undefined,
},
rbac: {} as IdmPermissions,
});

/**
Expand Down Expand Up @@ -179,6 +182,7 @@ export const AppContextProvider: React.FC<AppContextProviderProps> = ({ children
domain: wizardDomain || ({} as Domain),
setDomain: _setWizardDomain,
},
rbac: useIdmPermissions(),
}}
>
{children}
Expand Down
42 changes: 42 additions & 0 deletions src/Hooks/useIdmPermissions.tsx
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;
Loading