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

Role definition update #1511

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
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
10 changes: 5 additions & 5 deletions app/src/App/fhir-apps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -216,15 +216,15 @@ const FHIRApps = () => {
disableLoginProtection={DISABLE_LOGIN_PROTECTION}
exact
path={DATA_IMPORT_LIST_URL}
permissions={['WebDataImport.read']}
permissions={['DataImport.read']}
component={DataImportList}
/>
<PrivateComponent
redirectPath={APP_CALLBACK_URL}
disableLoginProtection={DISABLE_LOGIN_PROTECTION}
exact
path={`${DATA_IMPORT_CREATE_URL}`}
permissions={['WebDataImport.create']}
permissions={['DataImport.create']}
component={StartDataImport}
/>
<PrivateComponent
Expand All @@ -233,7 +233,7 @@ const FHIRApps = () => {
exact
path={`${DATA_IMPORT_DETAIL_URL}/:${'workflowId'}`}
{...patientProps}
permissions={['WebDataImport.read']}
permissions={['DataImport.read']}
component={ImportDetailViewDetails}
/>
<PrivateComponent
Expand All @@ -242,7 +242,7 @@ const FHIRApps = () => {
exact
path={`${DATA_IMPORT_LIST_URL}/:${'workflowId'}`}
{...patientProps}
permissions={['WebDataImport.read']}
permissions={['DataImport.read']}
component={DataImportList}
/>
<PrivateComponent
Expand Down Expand Up @@ -501,7 +501,7 @@ const FHIRApps = () => {
redirectPath={APP_CALLBACK_URL}
disableLoginProtection={DISABLE_LOGIN_PROTECTION}
path={LIST_HEALTHCARE_URL}
permissions={['HealthCareList.read']}
permissions={['HealthcareService.read']}
component={HealthCareList}
/>
<PrivateComponent
Expand Down
4 changes: 2 additions & 2 deletions app/src/App/tests/App.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe('App - unauthenticated', () => {
</ContextProvider>
);
// before resolving get oauth state request, the user is logged out
expect(wrapper.text()).toMatchInlineSnapshot(`"AdministrationLogin"`);
expect(wrapper.text()).toMatchInlineSnapshot(`"AdministrationData ImportsLogin"`);

await act(async () => {
await flushPromises();
Expand Down Expand Up @@ -175,7 +175,7 @@ describe('App - authenticated', () => {
);
// before resolving get oauth state request, the user is logged out
expect(wrapper.text()).toMatchInlineSnapshot(
`"AdministrationdemoWelcome to OpenSRPUser ManagementQuestionnaire Management"`
`"AdministrationData ImportsdemoWelcome to OpenSRPUser ManagementQuestionnaire ManagementData Imports"`
);

await act(async () => {
Expand Down
3 changes: 3 additions & 0 deletions app/src/configs/dispatchConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
ProjectCode,
setAllConfigs,
getAllConfigs,
clientIdConfig,
} from '@opensrp/pkg-config';
import {
BACKEND_ACTIVE,
Expand All @@ -17,6 +18,7 @@ import {
AUTHZ_STRATEGY,
COMMODITIES_LIST_RESOURCE_ID,
FHIR_INVENTORY_LIST_ID,
OPENSRP_CLIENT_ID,
} from './env';
import { URL_BACKEND_LOGIN, URL_REACT_LOGIN } from '../constants';

Expand All @@ -26,6 +28,7 @@ const defaultvalues = getAllConfigs();

const configObject: ConfigState = {
...defaultvalues,
[clientIdConfig]: OPENSRP_CLIENT_ID,
languageCode: LANGUAGE_CODE as LanguageCode,
projectCode: PROJECT_CODE as ProjectCode,
appLoginURL: APP_LOGIN_URL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,16 @@ Array [
</Link>
</MenuItem>
</SubMenu>,
<MenuItem
icon={<UploadIcon />}
>
<Link
className="admin-link"
to="/import"
>
Data Imports
</Link>
</MenuItem>,
]
`;

Expand Down Expand Up @@ -169,6 +179,16 @@ Array [
</Link>
</MenuItem>
</SubMenu>,
<MenuItem
icon={<UploadIcon />}
>
<Link
className="admin-link"
to="/import"
>
Data Imports
</Link>
</MenuItem>,
]
`;

Expand Down Expand Up @@ -300,6 +320,16 @@ Object {
</Link>
</MenuItem>
</SubMenu>
<MenuItem
icon={<UploadIcon />}
>
<Link
className="admin-link"
to="/import"
>
Data Imports
</Link>
</MenuItem>
</Menu>
</div>,
null,
Expand Down Expand Up @@ -389,5 +419,15 @@ Array [
</Link>
</MenuItem>
</SubMenu>,
<MenuItem
icon={<UploadIcon />}
>
<Link
className="admin-link"
to="/import"
>
Data Imports
</Link>
</MenuItem>,
]
`;
1 change: 1 addition & 0 deletions app/src/containers/pages/Home/tests/Home.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ describe('containers/pages/Home', () => {
'Location Management',
'Organization Management',
'Questionnaire Management',
'Data Imports',
]);
links.forEach((link) => {
expect(link).toMatchSnapshot(link.textContent ?? undefined);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`containers/pages/Home renders Home correctly & changes Title of page 2: Data Imports 1`] = `
<button
class="ant-btn css-dev-only-do-not-override-k7429z ant-btn-link admin-link btn-links"
type="button"
>
<span>
Data Imports
</span>
</button>
`;

exports[`containers/pages/Home renders Home correctly & changes Title of page 2: Location Management 1`] = `
<button
class="ant-btn css-dev-only-do-not-override-k7429z ant-btn-link admin-link btn-links"
Expand Down
2 changes: 1 addition & 1 deletion app/src/routes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ export function getRoutes(roles: string[], t: TFunction, userRole: UserRole): Ro
title: t('Data Imports'),
key: 'data-import',
enabled: true,
permissions: ['WebDataImport.read'],
permissions: ['DataImport.read'],
url: DATA_IMPORT_LIST_URL,
isHomePageLink: true,
},
Expand Down
51 changes: 48 additions & 3 deletions app/src/routes/tests/index.test.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import React from 'react';
import { store } from '@opensrp/store';
import { authenticateUser } from '@onaio/session-reducer';
import { filterFalsyRoutes, getRoutes } from '..';
import { DashboardOutlined } from '@ant-design/icons';
import React from 'react';
import { superUserRole } from '@opensrp/react-utils';
import UploadIcon from '@2fd/ant-design-icons/lib/Upload';

jest.mock('../../configs/env');
jest.mock('../../configs/settings');
Expand Down Expand Up @@ -124,67 +125,111 @@ describe('routes', () => {
{
key: 'users',
title: 'Users',
permissions: ['iam_user.read'],

url: '/admin/users',
},
{
key: 'user-groups',
permissions: ['iam_group.read'],

title: 'User Groups',
url: '/admin/users/groups',
},
{
key: 'user-roles',
permissions: ['iam_role.read'],
title: 'User Roles',
url: '/admin/users/roles',
},
],
enabled: true,
isHomePageLink: true,
key: 'user-management',
permissions: ['iam_user.read'],
title: 'User Management',
url: '/admin/users',
},
{
children: [
{
key: 'location-unit',
permissions: ['Location.read'],

title: 'Hierarchy',
url: '/admin/location/unit',
},
{
key: 'all-locations',
permissions: ['Location.read'],

title: 'All Locations',
url: '/admin/location/all',
},
],
enabled: true,
isHomePageLink: true,
key: 'location-management',
permissions: ['Location.read'],

title: 'Location Management',
url: '/admin/location/unit',
},
{
children: [
{
key: 'ORGS',
permissions: ['Organization.read'],

title: 'Organizations',
url: '/admin/teams',
},
{
enabled: true,
key: 'org-assignment',
permissions: ['OrganizationAffiliation.read', 'Location.read'],

title: 'Organization Assignment',
url: '/admin/teams/team-assignment',
},
],
enabled: true,
isHomePageLink: true,
key: 'org-management',
permissions: ['Organization.read'],

title: 'Organization Management',
url: '/admin/teams',
},
{
enabled: true,
isHomePageLink: true,
key: 'fhir-quest',
permissions: ['Questionnaire.read'],

title: 'Questionnaire Management',
url: '/quest',
},
{ enabled: true, key: 'fhir-quest', title: 'Questionnaire Management', url: '/quest' },
],
enabled: true,
key: 'admin',
otherProps: {
icon: <DashboardOutlined />,
},
permissions: [],
title: 'Administration',
},
{
enabled: true,
isHomePageLink: true,
key: 'data-import',
otherProps: {
icon: <UploadIcon />,
},
permissions: ['DataImport.read'],
title: 'Data Imports',
url: '/import',
},
]);
});

Expand All @@ -201,7 +246,7 @@ describe('routes', () => {
(t: string) => t,
superUserRole
);
const parentKeys = routes.flatMap((x) => x.children).map((x) => x.key);
const parentKeys = routes.flatMap((x) => x.children).map((x) => (x ? x.key ?? '' : ''));
expect(parentKeys).toContain('org-management');
expect(parentKeys).toContain('user-management');
expect(parentKeys).toContain('location-management');
Expand Down
2 changes: 1 addition & 1 deletion packages/fhir-flag/src/components/CloseFlagForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const CloseFlagForm = (props: CloseFlagFormProps) => {
mutate(values);
};

const saveBtnDisabled = userRole.hasPermissions([
const saveBtnDisabled = !userRole.hasPermissions([
'Flag.update',
'Encounter.update',
'Observation.update',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { flag } from '../../Utils/tests/fixtures';
import { QueryClient, QueryClientProvider } from 'react-query';
import userEvents from '@testing-library/user-event';
import { status } from '../../../constants';
import { ContextProvider } from '@opensrp/react-utils';

jest.mock('@opensrp/notifications', () => ({
__esModule: true,
Expand Down Expand Up @@ -46,7 +47,9 @@ describe('CloseFlagForm component', () => {

render(
<QueryClientProvider client={queryClient}>
<CloseFlagForm {...props} />
<ContextProvider>
<CloseFlagForm {...props} />
</ContextProvider>
</QueryClientProvider>
);

Expand Down Expand Up @@ -83,7 +86,9 @@ describe('CloseFlagForm component', () => {

render(
<QueryClientProvider client={queryClient}>
<CloseFlagForm {...props} />
<ContextProvider>
<CloseFlagForm {...props} />
</ContextProvider>
</QueryClientProvider>
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import {
import userEvents from '@testing-library/user-event';
import { status } from '../../../constants';
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 @@ -122,9 +124,11 @@ test('renders correctly and fetches data', async () => {

render(
<QueryClientProvider client={queryClient}>
<Router history={history}>
<LocationFlag {...defaultProps} />
</Router>
<RoleContext.Provider value={superUserRole}>
<Router history={history}>
<LocationFlag {...defaultProps} />
</Router>
</RoleContext.Provider>
</QueryClientProvider>
);

Expand Down
Loading
Loading