-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Prevent clients from accessing programs they are not enrolled in (
#105)
- Loading branch information
1 parent
98a8f24
commit 50757c6
Showing
6 changed files
with
274 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { Box, Typography } from "@mui/material"; | ||
import { redirect } from "next/navigation"; | ||
|
||
import { getUserByEmail } from "@/server/api/users/queries"; | ||
import getUserSession from "@/utils/getUserSession"; | ||
import isUserEnrolledInProgram from "@/utils/isEnrolledInProgram"; | ||
|
||
export default async function DiabetesPreventionPage() { | ||
const session = await getUserSession(); | ||
|
||
if (!session) { | ||
redirect("/"); | ||
} | ||
|
||
const [user, error] = await getUserByEmail(session.user.email, { | ||
populateProgramEnrollments: true, | ||
}); | ||
|
||
if (error !== null) { | ||
return ( | ||
<Box | ||
sx={{ | ||
height: "100vh", | ||
width: "100vw", | ||
display: "flex", | ||
justifyContent: "center", | ||
alignItems: "center", | ||
}} | ||
> | ||
<Typography> | ||
There was an error fetching your diabetes prevention enrollment. | ||
</Typography> | ||
</Box> | ||
); | ||
} | ||
if (user.role !== "client") { | ||
redirect("/dashboard"); | ||
} | ||
|
||
const enrolledInDiabetesPreventionProgram = isUserEnrolledInProgram( | ||
user.programEnrollments, | ||
"Diabetes Prevention", | ||
); | ||
|
||
if (!enrolledInDiabetesPreventionProgram) { | ||
redirect("/dashboard/client"); | ||
} | ||
|
||
return ( | ||
<Box | ||
sx={{ | ||
height: "100vh", | ||
width: "100vw", | ||
display: "flex", | ||
justifyContent: "center", | ||
alignItems: "center", | ||
}} | ||
> | ||
<Typography>Diabetes Prevention Page</Typography> | ||
</Box> | ||
); | ||
} |
63 changes: 63 additions & 0 deletions
63
src/app/dashboard/client/get-preventative-screenings/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { Box, Typography } from "@mui/material"; | ||
import { redirect } from "next/navigation"; | ||
|
||
import { getUserByEmail } from "@/server/api/users/queries"; | ||
import getUserSession from "@/utils/getUserSession"; | ||
import isUserEnrolledInProgram from "@/utils/isEnrolledInProgram"; | ||
|
||
export default async function GetPreventativeScreeningsPage() { | ||
const session = await getUserSession(); | ||
|
||
if (!session) { | ||
redirect("/"); | ||
} | ||
|
||
const [user, error] = await getUserByEmail(session.user.email, { | ||
populateProgramEnrollments: true, | ||
}); | ||
|
||
if (error !== null) { | ||
return ( | ||
<Box | ||
sx={{ | ||
height: "100vh", | ||
width: "100vw", | ||
display: "flex", | ||
justifyContent: "center", | ||
alignItems: "center", | ||
}} | ||
> | ||
<Typography> | ||
There was an error fetching your get preventative screenings | ||
enrollment. | ||
</Typography> | ||
</Box> | ||
); | ||
} | ||
if (user.role !== "client") { | ||
redirect("/dashboard"); | ||
} | ||
|
||
const enrolledInGetPreventativeScreeningsProgram = isUserEnrolledInProgram( | ||
user.programEnrollments, | ||
"GPS (Get Preventative Screenings)", | ||
); | ||
|
||
if (!enrolledInGetPreventativeScreeningsProgram) { | ||
redirect("/dashboard/client"); | ||
} | ||
|
||
return ( | ||
<Box | ||
sx={{ | ||
height: "100vh", | ||
width: "100vw", | ||
display: "flex", | ||
justifyContent: "center", | ||
alignItems: "center", | ||
}} | ||
> | ||
<Typography>Get Preventative Screenings Page</Typography> | ||
</Box> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { Box, Typography } from "@mui/material"; | ||
import { redirect } from "next/navigation"; | ||
|
||
import { getUserByEmail } from "@/server/api/users/queries"; | ||
import getUserSession from "@/utils/getUserSession"; | ||
import isUserEnrolledInProgram from "@/utils/isEnrolledInProgram"; | ||
|
||
export default async function RigsWithoutCigsPage() { | ||
const session = await getUserSession(); | ||
|
||
if (!session) { | ||
redirect("/"); | ||
} | ||
|
||
const [user, error] = await getUserByEmail(session.user.email, { | ||
populateProgramEnrollments: true, | ||
}); | ||
|
||
if (error !== null) { | ||
return ( | ||
<Box | ||
sx={{ | ||
height: "100vh", | ||
width: "100vw", | ||
display: "flex", | ||
justifyContent: "center", | ||
alignItems: "center", | ||
}} | ||
> | ||
<Typography> | ||
There was an error fetching your rigs without cigs enrollment. | ||
</Typography> | ||
</Box> | ||
); | ||
} | ||
if (user.role !== "client") { | ||
redirect("/dashboard"); | ||
} | ||
|
||
const enrolledInRigsWithoutCigsProgram = isUserEnrolledInProgram( | ||
user.programEnrollments, | ||
"Rigs Without Cigs", | ||
); | ||
|
||
if (!enrolledInRigsWithoutCigsProgram) { | ||
redirect("/dashboard/client"); | ||
} | ||
return ( | ||
<Box | ||
sx={{ | ||
height: "100vh", | ||
width: "100vw", | ||
display: "flex", | ||
justifyContent: "center", | ||
alignItems: "center", | ||
}} | ||
> | ||
<Typography>Rigs Without Cigs Page</Typography> | ||
</Box> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { Box, Typography } from "@mui/material"; | ||
import { redirect } from "next/navigation"; | ||
|
||
import { getUserByEmail } from "@/server/api/users/queries"; | ||
import getUserSession from "@/utils/getUserSession"; | ||
import isUserEnrolledInProgram from "@/utils/isEnrolledInProgram"; | ||
|
||
export default async function VaccineVoucherPage() { | ||
const session = await getUserSession(); | ||
|
||
if (!session) { | ||
redirect("/"); | ||
} | ||
|
||
const [user, error] = await getUserByEmail(session.user.email, { | ||
populateProgramEnrollments: true, | ||
}); | ||
|
||
if (error !== null) { | ||
return ( | ||
<Box | ||
sx={{ | ||
height: "100vh", | ||
width: "100vw", | ||
display: "flex", | ||
justifyContent: "center", | ||
alignItems: "center", | ||
}} | ||
> | ||
<Typography> | ||
There was an error fetching your vaccine voucher enrollment. | ||
</Typography> | ||
</Box> | ||
); | ||
} | ||
|
||
if (user.role !== "client") { | ||
redirect("/dashboard"); | ||
} | ||
|
||
const enrolledInVaccineVoucherProgram = isUserEnrolledInProgram( | ||
user.programEnrollments, | ||
"Vaccine Voucher", | ||
); | ||
|
||
if (!enrolledInVaccineVoucherProgram) { | ||
redirect("/dashboard/client"); | ||
} | ||
|
||
return ( | ||
<Box | ||
sx={{ | ||
height: "100vh", | ||
width: "100vw", | ||
display: "flex", | ||
justifyContent: "center", | ||
alignItems: "center", | ||
}} | ||
> | ||
<Typography>Vaccine Voucher Page</Typography> | ||
</Box> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Program, ProgramEnrollment } from "@/types"; | ||
|
||
export default function isEnrolledInProgram( | ||
programEnrollments: ProgramEnrollment[], | ||
program: Program, | ||
) { | ||
return programEnrollments | ||
.filter((programEnrollment) => programEnrollment.status === "accepted") | ||
.some((programEnrollment) => programEnrollment.program === program); | ||
} |