Skip to content

Commit

Permalink
Update rbac in team management
Browse files Browse the repository at this point in the history
  • Loading branch information
peterMuriuki committed Sep 5, 2023
1 parent b126f96 commit 7c656d6
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ const AffiliationTable: React.FC<Props> = (props: Props) => {
const [seeModal, setSeeModal] = useState<boolean>(false);
const [location, setLocation] = useState<ILocation>();
const { t } = useTranslation();
const userRole = useUserRole();

const {
data: affiliationsData,
Expand Down Expand Up @@ -110,9 +109,6 @@ const AffiliationTable: React.FC<Props> = (props: Props) => {
{
title: t('Assigned teams'),
render: (_, record) => {
if (userRole.hasPermissions('organizationAffiliation.read')) {
return '';
}
const { id } = record;
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
const affiliations = affiliationsByLocId[`${locationResourceType}/${id}`] ?? [];
Expand All @@ -128,7 +124,7 @@ const AffiliationTable: React.FC<Props> = (props: Props) => {
width: '10%',
// eslint-disable-next-line react/display-name
render: (_, record) => (
<RbacCheck permissions={['organizationAffiliation.update']}>
<RbacCheck permissions={['OrganizationAffiliation.update']}>
<Button
type="link"
className="action-button"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
locationTreeStateDucks,
} from '@opensrp/fhir-location-management';
import { useTranslation } from '../../mls';
import { RbacCheck } from '@opensrp/rbac';

const { reducerName, reducer, setSelectedNode, getSelectedNode } = locationTreeStateDucks;

Expand Down Expand Up @@ -100,7 +101,9 @@ export const AffiliationList: React.FC<LocationUnitListProps> = (props: Location
</Col>
<Col className="bg-white p-3 border-left" span={18}>
<div className="bg-white p-3">
<AffiliationTable baseUrl={fhirBaseURL} locationNodes={tableNodes} />
<RbacCheck permissions={['OrganizationAffiliation.read']}>
<AffiliationTable baseUrl={fhirBaseURL} locationNodes={tableNodes} />
</RbacCheck>
</div>
</Col>
</Row>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import {
import { organizationAffiliationResourceType, organizationResourceType } from '../../../constants';
import userEvent from '@testing-library/user-event';
import * as notifications from '@opensrp/notifications';
import { RoleContext } from '@opensrp/rbac';
import { superUserRole } from '@opensrp/react-utils';

jest.mock('@opensrp/notifications', () => ({
__esModule: true,
Expand Down Expand Up @@ -59,13 +61,15 @@ const props = {
const AppWrapper = ({ children }: any) => {
return (
<Provider store={store}>
<QueryClientProvider client={queryClient}>
<Switch>
<Route exact path="/assignments">
{children}
</Route>
</Switch>
</QueryClientProvider>
<RoleContext.Provider value={superUserRole}>
<QueryClientProvider client={queryClient}>
<Switch>
<Route exact path="/assignments">
{children}
</Route>
</Switch>
</QueryClientProvider>
</RoleContext.Provider>
</Provider>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export const OrganizationList = (props: OrganizationListProps) => {
// eslint-disable-next-line react/display-name
render: (_: unknown, record: TableData) => (
<span className="d-flex align-items-center">
<RbacCheck permissions={['organization.update']}>
<RbacCheck permissions={['Organization.update']}>
<>
<Link to={`${URL_EDIT_ORGANIZATION}/${record.id}`} className="m-0 p-1">
{t('Edit')}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -463,3 +463,64 @@ exports[`renders correctly when listing organizations: table row 3 page 2 2`] =
</span>
</td>
`;

exports[`responds as expected to errors: Header title 1`] = `
<h4
class="ant-typography page-header css-dev-only-do-not-override-k7429z"
>
Organization list
</h4>
`;

exports[`responds as expected to errors: table row 1 page 1 1`] = `
<td
class="ant-table-cell"
colspan="2"
>
<div
class="css-dev-only-do-not-override-k7429z ant-empty ant-empty-normal"
>
<div
class="ant-empty-image"
>
<svg
height="41"
viewBox="0 0 64 41"
width="64"
xmlns="http://www.w3.org/2000/svg"
>
<g
fill="none"
fill-rule="evenodd"
transform="translate(0 1)"
>
<ellipse
cx="32"
cy="33"
fill="#f5f5f5"
rx="32"
ry="7"
/>
<g
fill-rule="nonzero"
stroke="#d9d9d9"
>
<path
d="M55 12.76L44.854 1.258C44.367.474 43.656 0 42.907 0H21.093c-.749 0-1.46.474-1.947 1.257L9 12.761V22h46v-9.24z"
/>
<path
d="M41.613 15.931c0-1.605.994-2.93 2.227-2.931H55v18.137C55 33.26 53.68 35 52.05 35h-40.1C10.32 35 9 33.259 9 31.137V13h11.16c1.233 0 2.227 1.323 2.227 2.928v.022c0 1.605 1.005 2.901 2.237 2.901h14.752c1.232 0 2.237-1.308 2.237-2.913v-.007z"
fill="#fafafa"
/>
</g>
</g>
</svg>
</div>
<div
class="ant-empty-description"
>
No data
</div>
</div>
</td>
`;
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import {
} from './fixtures';
import userEvents from '@testing-library/user-event';
import { allAffiliations } from '../../../OrganizationAffiliation/tests/fixures';
import { RoleContext } from '@opensrp/rbac';
import { superUserRole } from '@opensrp/react-utils';

jest.mock('fhirclient', () => {
return jest.requireActual('fhirclient/lib/entry/browser');
Expand Down Expand Up @@ -65,16 +67,18 @@ const props = {
const AppWrapper = (props: any) => {
return (
<Provider store={store}>
<QueryClientProvider client={queryClient}>
<Switch>
<Route exact path={`${ORGANIZATION_LIST_URL}`}>
{(routeProps) => <OrganizationList {...{ ...props, ...routeProps }} />}
</Route>
<Route exact path={`${ORGANIZATION_LIST_URL}/:id`}>
{(routeProps) => <OrganizationList {...{ ...props, ...routeProps }} />}
</Route>
</Switch>
</QueryClientProvider>
<RoleContext.Provider value={superUserRole}>
<QueryClientProvider client={queryClient}>
<Switch>
<Route exact path={`${ORGANIZATION_LIST_URL}`}>
{(routeProps) => <OrganizationList {...{ ...props, ...routeProps }} />}
</Route>
<Route exact path={`${ORGANIZATION_LIST_URL}/:id`}>
{(routeProps) => <OrganizationList {...{ ...props, ...routeProps }} />}
</Route>
</Switch>
</QueryClientProvider>
</RoleContext.Provider>
</Provider>
);
};
Expand Down

0 comments on commit 7c656d6

Please sign in to comment.