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

Restrict Unauthorized Users from Accessing Facility's Patient Registration #7498

Merged
merged 27 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
f3c3c4a
add auth checks
AshrafMd-1 Mar 31, 2024
1a49d6a
Merge branch 'coronasafe:develop' into Fix-#7244-1
AshrafMd-1 Apr 1, 2024
1bd1c43
Merge branch 'develop' into Fix-#7244-1
AshrafMd-1 Apr 2, 2024
0129bca
remove merge conflict
AshrafMd-1 Apr 2, 2024
34f9ec5
Merge branch 'develop' into Fix-#7244-1
AshrafMd-1 Apr 3, 2024
898d8be
Merge branch 'develop' into Fix-#7244-1
AshrafMd-1 Apr 4, 2024
2e3e2d7
Merge branch 'coronasafe:develop' into Fix-#7244-1
AshrafMd-1 Apr 8, 2024
1647ca5
Merge branch 'develop' into Fix-#7244-1
AshrafMd-1 Apr 10, 2024
8cb5999
Merge branch 'develop' into Fix-#7244-1
nihal467 Apr 16, 2024
9176fb7
Merge branch 'develop' into Fix-#7244-1
nihal467 Apr 16, 2024
cbe9b95
Update ManagePatients.tsx
AshrafMd-1 Apr 16, 2024
b5190ef
Merge branch 'develop' into Fix-#7244-1
AshrafMd-1 Apr 16, 2024
ea46df6
fix linting
AshrafMd-1 Apr 16, 2024
fc27461
Merge branch 'develop' into Fix-#7244-1
nihal467 Apr 23, 2024
344b083
Merge branch 'develop' into Fix-#7244-1
AshrafMd-1 Apr 24, 2024
4cc00f9
add error notification
AshrafMd-1 Apr 26, 2024
18bbeb4
Merge branch 'develop' into Fix-#7244-1
AshrafMd-1 Apr 26, 2024
0b4ec2f
fix lint
AshrafMd-1 Apr 27, 2024
c4decb4
fix lint
AshrafMd-1 Apr 27, 2024
2e81525
fix codes
AshrafMd-1 May 1, 2024
381e085
Merge branch 'develop' into Fix-#7244-1
AshrafMd-1 May 1, 2024
cc9337c
Merge branch 'develop' into Fix-#7244-1
nihal467 May 7, 2024
5523fe2
fix bug
AshrafMd-1 May 13, 2024
3a3f5f3
fix bug
AshrafMd-1 May 13, 2024
09a613d
Merge branch 'develop' into Fix-#7244-1
AshrafMd-1 May 13, 2024
3fa79b3
dont allow null home facility users to add patient
AshrafMd-1 May 13, 2024
5c9682f
Merge branch 'coronasafe:develop' into Fix-#7244-1
AshrafMd-1 May 13, 2024
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
3 changes: 3 additions & 0 deletions src/Components/Common/FacilitySelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ interface FacilitySelectProps {
multiple?: boolean;
facilityType?: number;
district?: string;
state?: string;
showAll?: boolean;
showNOptions?: number;
freeText?: boolean;
Expand All @@ -33,6 +34,7 @@ export const FacilitySelect = (props: FacilitySelectProps) => {
className = "",
facilityType,
district,
state,
freeText = false,
errors = "",
} = props;
Expand All @@ -47,6 +49,7 @@ export const FacilitySelect = (props: FacilitySelectProps) => {
facility_type: facilityType,
exclude_user: exclude_user,
district,
state,
};

const { data } = await request(
Expand Down
12 changes: 12 additions & 0 deletions src/Components/ExternalResult/FacilitiesSelectDialogue.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import DialogModal from "../Common/Dialog";
import { FacilitySelect } from "../Common/FacilitySelect";
import { FacilityModel } from "../Facility/models";
import { useTranslation } from "react-i18next";
import useAuthUser from "../../Common/hooks/useAuthUser";

interface Props {
show: boolean;
Expand All @@ -15,6 +16,7 @@ interface Props {
const FacilitiesSelectDialog = (props: Props) => {
const { show, handleOk, handleCancel, selectedFacility, setSelected } = props;
const { t } = useTranslation();
const authUser = useAuthUser();

return (
<DialogModal
Expand All @@ -29,6 +31,16 @@ const FacilitiesSelectDialog = (props: Props) => {
errors=""
showAll={false}
multiple={false}
district={
authUser?.user_type === "DistrictAdmin"
? authUser?.district?.toString()
: undefined
}
state={
authUser?.user_type === "StateAdmin"
? authUser?.state?.toString()
: undefined
}
/>
<div className="mt-4 flex flex-col gap-2 sm:flex-row sm:justify-end">
<Cancel onClick={handleCancel} />
Expand Down
22 changes: 20 additions & 2 deletions src/Components/Patient/ManagePatients.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -736,11 +736,29 @@ export const PatientManager = () => {
<ButtonV2
id="add-patient-details"
onClick={() => {
if (qParams.facility)
const showAllFacilityUsers = ["DistrictAdmin", "StateAdmin"];
if (
qParams.facility &&
showAllFacilityUsers.includes(authUser.user_type)
)
navigate(`/facility/${qParams.facility}/patient`);
else if (onlyAccessibleFacility)
navigate(`/facility/${onlyAccessibleFacility.id}/patient`);
else setShowDialog("create");
else if (
!showAllFacilityUsers.includes(authUser.user_type) &&
authUser.home_facility_object?.id !== qParams.facility
)
Notification.Error({
msg: "Oops! Non-Home facility users don't have permission to perform this action.",
});
else if (
!showAllFacilityUsers.includes(authUser.user_type) &&
authUser.home_facility_object?.id
) {
navigate(
`/facility/${authUser.home_facility_object.id}/patient`,
);
} else setShowDialog("create");
}}
className="w-full lg:w-fit"
>
Expand Down
25 changes: 20 additions & 5 deletions src/Components/Patient/PatientHome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -642,11 +642,25 @@ export const PatientHome = (props: any) => {
className="mt-4 w-full"
disabled={!patientData.is_active}
authorizeFor={NonReadOnlyUsers}
onClick={() =>
navigate(
`/facility/${patientData?.facility}/patient/${id}/update`,
)
}
onClick={() => {
const showAllFacilityUsers = [
"DistrictAdmin",
"StateAdmin",
];
if (
!showAllFacilityUsers.includes(authUser.user_type) &&
authUser.home_facility_object?.id !==
patientData.facility
) {
Notification.Error({
msg: "Oops! Non-Home facility users don't have permission to perform this action.",
});
} else {
navigate(
`/facility/${patientData?.facility}/patient/${id}/update`,
);
}
}}
>
<CareIcon icon="l-edit-alt" className="text-lg" />
Update Details
Expand Down Expand Up @@ -808,6 +822,7 @@ export const PatientHome = (props: any) => {
</div>
</dl>
</div>

<div className="mt-2 flex">
<ButtonV2
className="mr-2 w-full bg-white hover:bg-gray-100"
Expand Down
29 changes: 29 additions & 0 deletions src/Components/Patient/PatientRegister.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import useAuthUser from "../../Common/hooks/useAuthUser.js";
import useQuery from "../../Utils/request/useQuery.js";
import routes from "../../Redux/api.js";
import request from "../../Utils/request/request.js";
import Error404 from "../ErrorPages/404";
import SelectMenuV2 from "../Form/SelectMenuV2.js";

const Loading = lazy(() => import("../Common/Loading"));
Expand Down Expand Up @@ -1061,6 +1062,34 @@ export const PatientRegister = (props: PatientRegisterProps) => {
return <Loading />;
}

const PatientRegisterAuth = () => {
const showAllFacilityUsers = ["DistrictAdmin", "StateAdmin"];
if (
!showAllFacilityUsers.includes(authUser.user_type) &&
authUser.home_facility_object?.id === facilityId
) {
return true;
}
if (
authUser.user_type === "DistrictAdmin" &&
authUser.district === facilityObject?.district
) {
return true;
}
if (
authUser.user_type === "StateAdmin" &&
authUser.state === facilityObject?.state
) {
return true;
}

return false;
};

if (!isLoading && facilityId && facilityObject && !PatientRegisterAuth()) {
return <Error404 />;
}

return (
<div className="px-2 pb-2">
{statusDialog.show && (
Expand Down
Loading