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

Permission fhir import and bulk upload module #1499

Open
wants to merge 2 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
2 changes: 1 addition & 1 deletion app/src/App/fhir-apps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ const FHIRApps = () => {
disableLoginProtection={DISABLE_LOGIN_PROTECTION}
exact
path={`${URL_CLOSE_FLAGS}/:id`}
// permissions={['Flag.update']}
permissions={['Flag.read']}
component={CloseFlag}
/>
<Route
Expand Down
19 changes: 15 additions & 4 deletions packages/fhir-flag/src/components/BaseComponent/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { IBundle } from '@smile-cdr/fhirts/dist/FHIR-R4/interfaces/IBundle';
import { IPractitioner } from '@smile-cdr/fhirts/dist/FHIR-R4/interfaces/IPractitioner';
import { useTranslation } from '../../mls';
import { thatiMinutes } from '../../constants';
import { RbacCheck } from '@opensrp/rbac';

export interface CloseFlagProps {
fhirBaseURL: string;
Expand Down Expand Up @@ -54,7 +55,7 @@ export const CloseFlag = (props: CloseFlagProps) => {
enabled: !!user_id,
staleTime: thatiMinutes,
select: (response) => {
return getResourcesFromBundle<IPractitioner>(response)?.[0];
return getResourcesFromBundle<IPractitioner>(response)[0];
},
}
);
Expand All @@ -80,10 +81,20 @@ export const CloseFlag = (props: CloseFlagProps) => {
return (
<Row>
<Col span={24}>
{flag.data?.subject?.reference?.includes('Location') ? (
<LocationFlag {...commonProps} locationReference={flag.data.subject.reference} />
{flag.data?.subject.reference?.includes('Location') ? (
<RbacCheck
permissions={['Location.read']}
fallback={t('Missing Required permissions to perform this action')}
>
<LocationFlag {...commonProps} locationReference={flag.data.subject.reference} />
</RbacCheck>
) : (
<ProductFlag {...commonProps} inventoryGroupReference={flag.data?.subject.reference} />
<RbacCheck
permissions={['Group.read', 'Location.read', 'List.read']}
fallback={t('Missing Required permissions to perform this action')}
>
<ProductFlag {...commonProps} inventoryGroupReference={flag.data?.subject.reference} />
</RbacCheck>
)}
</Col>
</Row>
Expand Down
20 changes: 18 additions & 2 deletions packages/fhir-flag/src/components/CloseFlagForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { sendErrorNotification, sendSuccessNotification } from '@opensrp/notific
import { useTranslation } from '../../mls';
import { comments, locationName, productName, status } from '../../constants';
import { IFlag } from '@smile-cdr/fhirts/dist/FHIR-R4/interfaces/IFlag';
import { useUserRole } from '@opensrp/rbac';

const { Item: FormItem } = Form;
const { TextArea } = Input;
Expand Down Expand Up @@ -36,6 +37,7 @@ const headerProps = {

const CloseFlagForm = (props: CloseFlagFormProps) => {
const { initialValues, flag, mutationEffect } = props;
const userRole = useUserRole();
const { t } = useTranslation();

const stableInitialValues = useMemo(() => initialValues, [initialValues]);
Expand Down Expand Up @@ -63,6 +65,15 @@ const CloseFlagForm = (props: CloseFlagFormProps) => {
mutate(values);
};

const saveBtnDisabled = userRole.hasPermissions([
'Flag.update',
'Encounter.update',
'Observation.update',
]);
const saveBtnDisabledReason = saveBtnDisabled
? t('Missing Required permissions to perform this action')
: undefined;

return (
<BodyLayout headerProps={headerProps}>
<Row className="user-group">
Expand All @@ -89,8 +100,13 @@ const CloseFlagForm = (props: CloseFlagFormProps) => {
<TextArea rows={4} placeholder={t('How was the flag resolved?')} />
</FormItem>

<FormItem {...tailLayout}>
<Button type="primary" id="submit-button" htmlType="submit">
<FormItem {...tailLayout} help={saveBtnDisabledReason}>
<Button
type="primary"
id="submit-button"
htmlType="submit"
disabled={saveBtnDisabled}
>
{isLoading ? t('Saving') : t('Save')}
</Button>
</FormItem>
Expand Down
124 changes: 77 additions & 47 deletions packages/fhir-import/src/containers/StartImportView/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
import { HTTPMethod, getDefaultHeaders } from '@opensrp/server-service';
import './form.css';
import { getAllConfigs } from '@opensrp/pkg-config';
import { RbacCheck } from '@opensrp/rbac';

const { Text, Title } = Typography;

Expand Down Expand Up @@ -116,38 +117,55 @@ export const DataImportForm = (props: DataImportFormProps) => {
const formItems = [
{
formFieldName: users,
label: 'Users',
UploadBtnText: 'Attach users file',
label: t('Users'),
UploadBtnText: t('Attach users file'),
permissions: ['iam_user.create', 'Practitioner.create', 'iam_user.update'],
},
{
formFieldName: locations,
label: 'Locations',
UploadBtnText: 'Attach locations file',
label: t('Locations'),
UploadBtnText: t('Attach locations file'),
permissions: ['Location.create', 'Location.update'],
},
{
formFieldName: organizations,
label: 'Organizations',
UploadBtnText: 'Attach organizations file',
label: t('Organizations'),
UploadBtnText: t('Attach organizations file'),
permissions: ['Organization.create', 'Organization.update'],
},
{
formFieldName: careteams,
label: 'CareTeams',
UploadBtnText: 'Attach careTeams file',
label: t('CareTeams'),
UploadBtnText: t('Attach careTeams file'),
permissions: ['CareTeam.create', 'CareTeam.update'],
},
{
formFieldName: orgToLocationAssignment,
label: 'Organization location assignment',
label: t('Organization location assignment'),
UploadBtnText: 'Attach assignment file',
permissions: ['OrganizationAffiliation.create', 'OrganizationAffiliation.update'],
},
{
formFieldName: userToOrganizationAssignment,
label: 'User organization assignment',
UploadBtnText: 'Attach assignment file',
label: t('User organization assignment'),
UploadBtnText: t('Attach assignment file'),
permissions: ['PractitionerRole.create', 'PractitionerRole.update'],
},
{
formFieldName: inventories,
label: 'Inventory',
UploadBtnText: 'Attach inventory file',
label: t('Inventory'),
UploadBtnText: t('Attach inventory file'),
permissions: ['Group.create', 'Group.update'],
disabled: !inventoryListId,
disabledReason: t('A list resource Id is not correctly configured'),
},
{
formFieldName: products,
label: t('Products'),
UploadBtnText: t('Attach product file'),
permissions: ['Group.create', 'Group.update'],
disabled: !productListId,
disabledReason: t('A list resource Id is not correctly configured'),
},
];

Expand All @@ -166,47 +184,59 @@ export const DataImportForm = (props: DataImportFormProps) => {
}}
>
{formItems.map((item) => {
const { formFieldName, label, UploadBtnText } = item;
const { formFieldName, label, UploadBtnText, permissions, disabled, disabledReason } =
item;
const disableInfoProps =
disabled && disabledReason
? { validateStatus: 'warning' as const, help: disabledReason }
: {};
return (
<Form.Item
key={formFieldName}
id={formFieldName}
hidden={hidden?.includes(formFieldName)}
name={formFieldName}
label={label}
valuePropName="fileList"
getValueFromEvent={normalizeFileInputEvent}
>
<Upload
<RbacCheck permissions={permissions} key={formFieldName}>
<Form.Item
key={formFieldName}
{...disableInfoProps}
id={formFieldName}
beforeUpload={() => false}
accept="text/csv"
multiple={false}
maxCount={1}
hidden={hidden?.includes(formFieldName)}
name={formFieldName}
label={label}
valuePropName="fileList"
getValueFromEvent={normalizeFileInputEvent}
>
<Button icon={<UploadOutlined />}>{UploadBtnText}</Button>
</Upload>
</Form.Item>
<Upload
disabled={disabled}
id={formFieldName}
beforeUpload={() => false}
accept="text/csv"
multiple={false}
maxCount={1}
>
<Button icon={<UploadOutlined />}>{UploadBtnText}</Button>
</Upload>
</Form.Item>
</RbacCheck>
);
})}
<Form.Item
id={products}
hidden={hidden?.includes(products)}
name={products}
label={'Products'}
valuePropName="fileList"
getValueFromEvent={normalizeFileInputEvent}
>
<Upload
{/* <RbacCheck permissions={['Group.create', 'Group.update']}>
<Form.Item
id={products}
beforeUpload={() => false}
accept="text/csv"
multiple={false}
maxCount={1}
hidden={hidden?.includes(products)}
name={products}
label={'Products'}
valuePropName="fileList"
getValueFromEvent={normalizeFileInputEvent}
>
<Button icon={<UploadOutlined />}>{'Attach product file'}</Button>
</Upload>
</Form.Item>
<Upload
disabled={!!productListId}
id={products}
beforeUpload={() => false}
accept="text/csv"
multiple={false}
maxCount={1}
>
<Button icon={<UploadOutlined />}>{'Attach product file'}</Button>
</Upload>
</Form.Item>
</RbacCheck> */}
<Form.Item>
<Space>
<Button type="primary" id="submit-button" disabled={isLoading} htmlType="submit">
Expand Down
Loading