Skip to content

Commit

Permalink
chore(dashboard): restrict access for volunteers to only check-in
Browse files Browse the repository at this point in the history
  • Loading branch information
Matej Tarca authored and matejtarca committed Apr 5, 2024
1 parent 3beb2cd commit 8b99eec
Show file tree
Hide file tree
Showing 16 changed files with 61 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from "react";
import requireOrganizer from "@/services/helpers/requireOrganizer";
import { Metadata } from "next";
import ApplicationDetailCard from "@/scenes/Dashboard/scenes/ApplicationDetail/ApplicationDetailCard";
import { disallowVolunteer } from "@/services/helpers/disallowVolunteer";

export const metadata: Metadata = {
title: "Application detail",
Expand All @@ -13,6 +14,7 @@ const ApplicationDetailPage = async ({
params: { applicationId: string; hackathonId: string };
}) => {
await requireOrganizer();
await disallowVolunteer(params.hackathonId);
return (
<ApplicationDetailCard
applicationId={Number(params.applicationId)}
Expand Down
4 changes: 3 additions & 1 deletion src/app/dashboard/[hackathonId]/applications/page.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import React from "react";
import ApplicationsList from "@/scenes/Dashboard/scenes/ApplicationsList/ApplicationsList";
import { disallowVolunteer } from "@/services/helpers/disallowVolunteer";

export const metadata = {
title: "Applications",
};
const ApplicationsPage = ({
const ApplicationsPage = async ({
params: { hackathonId },
}: {
params: { hackathonId: string };
}) => {
await disallowVolunteer(hackathonId);
return <ApplicationsList hackathonId={Number(hackathonId)} />;
};

Expand Down
4 changes: 3 additions & 1 deletion src/app/dashboard/[hackathonId]/applications/review/page.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import React from "react";
import { Metadata } from "next";
import ApplicationReview from "@/scenes/Dashboard/scenes/ApplicationReview/ApplicationReview";
import { disallowVolunteer } from "@/services/helpers/disallowVolunteer";

export const metadata: Metadata = {
title: "Review applications",
};

const Page = ({
const Page = async ({
params: { hackathonId },
}: {
params: { hackathonId: string };
}) => {
await disallowVolunteer(hackathonId);
return <ApplicationReview hackathonId={Number(hackathonId)} />;
};

Expand Down
2 changes: 2 additions & 0 deletions src/app/dashboard/[hackathonId]/form-editor/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Metadata } from "next";
import ApplicationFormEditor from "@/scenes/Dashboard/scenes/ApplicationFormEditor/ApplicationFormEditor";
import getApplicationFormSteps from "@/server/getters/dashboard/applicationFormEditor/applicationFormSteps";
import requireAdmin from "@/services/helpers/requireAdmin";
import { disallowVolunteer } from "@/services/helpers/disallowVolunteer";

export const metadata: Metadata = {
title: "Edit application form",
Expand All @@ -13,6 +14,7 @@ const FormEditorPage = async ({
}: {
params: { hackathonId: string };
}) => {
await disallowVolunteer(hackathonId);
await requireAdmin();
const applicationFormSteps = await getApplicationFormSteps(
Number(hackathonId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from "react";
import { Metadata } from "next";
import FormStepEditor from "@/scenes/Dashboard/scenes/ApplicationFormEditor/scenes/EditStepForm/FormStepEditor";
import requireAdmin from "@/services/helpers/requireAdmin";
import { disallowVolunteer } from "@/services/helpers/disallowVolunteer";

export const metadata: Metadata = {
title: "Edit application form step",
Expand All @@ -12,6 +13,7 @@ const FormEditorStepPage = async ({
}: {
params: { stepId: string; hackathonId: string };
}) => {
await disallowVolunteer(params.hackathonId);
await requireAdmin();

return (
Expand Down
2 changes: 2 additions & 0 deletions src/app/dashboard/[hackathonId]/judging/manage/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import requireAdmin from "@/services/helpers/requireAdmin";
import JudgingManager from "@/scenes/Dashboard/scenes/Judging/scenes/JudgingManager/JudgingManager";
import getJudges from "@/server/getters/dashboard/judging/getJudges";
import getTeamsForJudging from "@/server/getters/dashboard/judging/getTeamsForJudging";
import { disallowVolunteer } from "@/services/helpers/disallowVolunteer";

export const metadata: Metadata = {
title: "Judging manager",
Expand All @@ -14,6 +15,7 @@ const Page = async ({
}: {
params: { hackathonId: string };
}) => {
await disallowVolunteer(hackathonId);
await requireAdmin();
const judges = await getJudges(Number(hackathonId));
const teamsForJudging = await getTeamsForJudging(Number(hackathonId));
Expand Down
2 changes: 2 additions & 0 deletions src/app/dashboard/[hackathonId]/judging/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from "react";
import { Metadata } from "next";
import requireOrganizer from "@/services/helpers/requireOrganizer";
import Judging from "@/scenes/Dashboard/scenes/Judging/Judging";
import { disallowVolunteer } from "@/services/helpers/disallowVolunteer";

export const metadata: Metadata = {
title: "Judging",
Expand All @@ -12,6 +13,7 @@ const Page = async ({
}: {
params: { hackathonId: string };
}) => {
await disallowVolunteer(hackathonId);
await requireOrganizer();
return <Judging hackathonId={Number(hackathonId)} />;
};
Expand Down
2 changes: 2 additions & 0 deletions src/app/dashboard/[hackathonId]/judging/results/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from "react";
import { Metadata } from "next";
import requireAdmin from "@/services/helpers/requireAdmin";
import JudgingResults from "@/scenes/Dashboard/scenes/Judging/scenes/JudgingResults/JudgingResults";
import { disallowVolunteer } from "@/services/helpers/disallowVolunteer";

export const metadata: Metadata = {
title: "Judging manager",
Expand All @@ -12,6 +13,7 @@ const Page = async ({
}: {
params: { hackathonId: string };
}) => {
await disallowVolunteer(hackathonId);
await requireAdmin();
return <JudgingResults hackathonId={Number(hackathonId)} />;
};
Expand Down
2 changes: 2 additions & 0 deletions src/app/dashboard/[hackathonId]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import HackathonInfo from "@/scenes/Dashboard/scenes/HackathonInfo/HackathonInfo";
import requireAdmin from "@/services/helpers/requireAdmin";
import { disallowVolunteer } from "@/services/helpers/disallowVolunteer";

const HackathonDashboardPage = async ({
params: { hackathonId },
Expand All @@ -8,6 +9,7 @@ const HackathonDashboardPage = async ({
hackathonId: string;
};
}) => {
await disallowVolunteer(hackathonId);
await requireAdmin();
return <HackathonInfo hackathonId={Number(hackathonId)} />;
};
Expand Down
2 changes: 2 additions & 0 deletions src/app/dashboard/[hackathonId]/settings/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import requireAdmin from "@/services/helpers/requireAdmin";
import getAdminInfo from "@/server/getters/dashboard/settings/adminInfo";
import getMaxTeamSize from "@/server/getters/dashboard/settings/maxTeamSize";
import getSponsorsInfo from "@/server/getters/dashboard/settings/sponsorsInfo";
import { disallowVolunteer } from "@/services/helpers/disallowVolunteer";

export const metadata = {
title: "Settings",
Expand All @@ -14,6 +15,7 @@ const SettingsPage = async ({
}: {
params: { hackathonId: string };
}) => {
await disallowVolunteer(params.hackathonId);
const hackathonId = Number(params.hackathonId);
await requireAdmin();
const { description } = await getTravelReimbursementRequestDescription(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from "react";
import { Metadata } from "next";
import VoteParameterManager from "@/scenes/Dashboard/scenes/VoteParameterManager/VoteParameterManager";
import requireAdmin from "@/services/helpers/requireAdmin";
import { disallowVolunteer } from "@/services/helpers/disallowVolunteer";

export const metadata: Metadata = {
title: "Settings | Vote parameters",
Expand All @@ -12,6 +13,7 @@ const Page = async ({
}: {
params: { hackathonId: string };
}) => {
await disallowVolunteer(hackathonId);
await requireAdmin();
return <VoteParameterManager hackathonId={Number(hackathonId)} />;
};
Expand Down
2 changes: 2 additions & 0 deletions src/app/dashboard/[hackathonId]/tables/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from "react";
import { Metadata } from "next";
import requireAdmin from "@/services/helpers/requireAdmin";
import TablesManager from "@/scenes/Dashboard/scenes/TablesManager/TablesManager";
import { disallowVolunteer } from "@/services/helpers/disallowVolunteer";

export const metadata: Metadata = {
title: "Teams & Tables",
Expand All @@ -12,6 +13,7 @@ const Page = async ({
}: {
params: { hackathonId: string };
}) => {
await disallowVolunteer(hackathonId);
await requireAdmin();
return <TablesManager hackathonId={Number(hackathonId)} />;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import React from "react";
import TravelReimbursementsList from "@/scenes/Dashboard/scenes/TravelReimbursements/TravelReimbursementsList";
import { disallowVolunteer } from "@/services/helpers/disallowVolunteer";

export const metadata = {
title: "Travel reimbursements",
};
const TravelReimbursementsPage = ({
const TravelReimbursementsPage = async ({
params: { hackathonId },
}: {
params: { hackathonId: string };
}) => {
await disallowVolunteer(hackathonId);
return <TravelReimbursementsList hackathonId={Number(hackathonId)} />;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,16 @@ const HackathonDashboardLayout = async ({
children,
}: HackathonDashboardProps) => {
const session = await getServerSession(authOptions);

// This is a hack to allow volunteers to access the dashboard
const isVolunteersEmail =
session?.user?.email === "[email protected]";
return (
<div>
<DashboardTabs
hackathonId={hackathonId}
isAdmin={Boolean(session?.isAdmin)}
isVolunteer={isVolunteersEmail}
/>
{children}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { usePathname, useRouter } from "next/navigation";
type DashboardTabsProps = {
hackathonId: number;
isAdmin: boolean;
isVolunteer: boolean;
};

type TabValue =
Expand Down Expand Up @@ -36,7 +37,11 @@ const getTabValue = (
return undefined;
};

const DashboardTabs = ({ hackathonId, isAdmin }: DashboardTabsProps) => {
const DashboardTabs = ({
hackathonId,
isAdmin,
isVolunteer,
}: DashboardTabsProps) => {
const path = usePathname();
const { push } = useRouter();

Expand Down Expand Up @@ -77,6 +82,8 @@ const DashboardTabs = ({ hackathonId, isAdmin }: DashboardTabsProps) => {
setTabValue(getTabValue(path, hackathonId));
}, [path, hackathonId]);

if (isVolunteer) return <div className="mt-5"></div>;

return (
<Tabs
className={`w-full ${
Expand Down
19 changes: 19 additions & 0 deletions src/services/helpers/disallowVolunteer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { getServerSession } from "next-auth/next";
import { authOptions } from "@/app/api/auth/[...nextauth]/route";
import { redirect } from "next/navigation";

export const disallowVolunteer = async (hackathonId: string) => {
const session = await getServerSession(authOptions);

if (!session) {
redirect("/application");
return;
}

const isVolunteerEmail = session.user?.email === "[email protected]";

if (isVolunteerEmail) {
redirect(`/dashboard/${hackathonId}/check-in`);
return;
}
};

0 comments on commit 8b99eec

Please sign in to comment.