Skip to content

Commit

Permalink
Merge branch '1501-role-update' into v330
Browse files Browse the repository at this point in the history
  • Loading branch information
peterMuriuki committed Dec 20, 2024
2 parents 67f7e63 + 5ef9cd9 commit 2c25b5a
Show file tree
Hide file tree
Showing 18 changed files with 221 additions and 90 deletions.
8 changes: 4 additions & 4 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
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
4 changes: 2 additions & 2 deletions packages/fhir-import/src/containers/ImportListView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export const DataImportList = () => {
// eslint-disable-next-line react/display-name
render: (_: unknown, record: WorkflowDescription) => (
<span className="d-flex align-items-center">
<RbacCheck permissions={['WebDataImport.read']}>
<RbacCheck permissions={['DataImport.read']}>
<>
<Link
to={`${DATA_IMPORT_DETAIL_URL}/${record.workflowId.toString()}`}
Expand Down Expand Up @@ -118,7 +118,7 @@ export const DataImportList = () => {
<Col className="main-content">
<div className="main-content__header">
<div />
<RbacCheck permissions={['WebDataImport.create']}>
<RbacCheck permissions={['DataImport.create']}>
<Link to={DATA_IMPORT_CREATE_URL}>
<Button type="primary" onClick={() => history.push(DATA_IMPORT_CREATE_URL)}>
<CloudUploadOutlined />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ exports[`Care Teams list view renders correctly: table row 1 page 1 6`] = `
>
<span
class="d-flex align-items-center"
/>
>
<a
class="m-0 p-1"
href="/importDetail/26aae779-0e6f-482d-82c3-a0fad1fd3689_orgToLocationAssignment"
>
View
</a>
</span>
</td>
`;
6 changes: 4 additions & 2 deletions packages/pkg-config/src/configStore/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** stores configuration for any other package */
import { createGlobalState } from 'react-hooks-global-state';
import { USER_PREFERENCE_KEY } from '../constants';
import { clientIdConfig, USER_PREFERENCE_KEY } from '../constants';
import { PaginationProps } from 'antd/lib/pagination/Pagination';

export const supportedLanguageCodes = ['en', 'sw', 'fr', 'ar', 'th', 'vi'] as const;
Expand Down Expand Up @@ -31,6 +31,7 @@ export interface TableState {

/** interface for configs for this package */
export interface ConfigState {
[clientIdConfig]?: string;
languageCode?: LanguageCode;
projectCode?: ProjectCode;
appLoginURL?: string;
Expand Down Expand Up @@ -58,7 +59,8 @@ export enum PractToOrgAssignmentStrategy {
ONE_TO_MANY = 'ONE_TO_MANY', // one practitioner assignable to multiple organizations
}

const defaultConfigs: GlobalState = {
const defaultConfigs: Partial<GlobalState> = {
[clientIdConfig]: undefined,
languageCode: 'en',
appLoginURL: undefined,
keycloakBaseURL: undefined,
Expand Down
3 changes: 3 additions & 0 deletions packages/pkg-config/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
export const SLICE_NOT_REGISTERED =
'Looks like configuration slice is being used without having been yet registered to the store';
export const USER_PREFERENCE_KEY = 'Preference';

// magic strings
export const clientIdConfig = 'clientId' as const;
1 change: 1 addition & 0 deletions packages/pkg-config/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './configStore';
export * from './constants';
Loading

0 comments on commit 2c25b5a

Please sign in to comment.