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

fixed authorizations in projectview #418

Merged
merged 4 commits into from
May 23, 2024
Merged
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
3 changes: 3 additions & 0 deletions frontend/public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@
"submit": "Submit",
"previousSubmissions": "Previous Submissions",
"noFileSelected": "No file selected",
"delete": "Delete",
"deleteProjectWarning": "Are you sure you want to delete this project?",
"imSure": "Yes, I'm sure",
"submissionGrid": {
"late": "Late",
"fail": "Fail",
Expand Down
3 changes: 3 additions & 0 deletions frontend/public/locales/nl/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@
"submit": "Indienen",
"previousSubmissions": "Vorige indieningen",
"noFileSelected": "Er is geen bestand geselecteerd",
"delete": "Verwijder",
"deleteProjectWarning": "Bent u zeker dat u dit project wilt verwijderen?",
"imSure": "Ja, ik ben zeker",
"submissionGrid": {
"late": "Te laat",
"fail": "Gefaald",
Expand Down
31 changes: 24 additions & 7 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ import HomePages from "./pages/home/HomePages.tsx";
import ProjectOverView from "./pages/project/projectOverview.tsx";
import { synchronizeJoinCode } from "./loaders/join-code.ts";
import { fetchMe } from "./utils/fetches/FetchMe.ts";
import {fetchProjectForm} from "./components/ProjectForm/project-form.ts";
import { fetchProjectForm } from "./components/ProjectForm/project-form.ts";
import loadSubmissionOverview from "./loaders/submission-overview-loader.ts";
import CoursesDetail from "./components/Courses/CoursesDetail.tsx";
import loadProjectViewData from "./loaders/project-view-loader.ts";

const router = createBrowserRouter(
createRoutesFromElements(
Expand All @@ -36,9 +37,17 @@ const router = createBrowserRouter(
<Route path=":lang" element={<LanguagePath />}>
<Route path="home" element={<HomePages />} loader={fetchProjectPage} />
<Route path="courses">
<Route index element={<AllCoursesTeacher />} loader={dataLoaderCourses}/>
<Route
index
element={<AllCoursesTeacher />}
loader={dataLoaderCourses}
/>
<Route path="join" loader={synchronizeJoinCode} />
<Route path=":courseId" element={<CoursesDetail />} loader={dataLoaderCourseDetail} />
<Route
path=":courseId"
element={<CoursesDetail />}
loader={dataLoaderCourseDetail}
/>
</Route>
<Route path="projects">
<Route
Expand All @@ -51,12 +60,20 @@ const router = createBrowserRouter(
path=":projectId/overview"
element={<SubmissionsOverview />}
/>
<Route path=":projectId" element={<ProjectView />}></Route>
<Route path="create" element={<ProjectCreateHome />} loader={fetchProjectForm}/>
<Route
path=":projectId"
element={<ProjectView />}
loader={loadProjectViewData}
></Route>
<Route
path="create"
element={<ProjectCreateHome />}
loader={fetchProjectForm}
/>
</Route>
</Route>
</Route>,
),
</Route>
)
);

/**
Expand Down
84 changes: 84 additions & 0 deletions frontend/src/loaders/project-view-loader.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { Params } from "react-router-dom";
import { Deadline } from "../types/deadline";
import { authenticatedFetch } from "../utils/authenticated-fetch";
import { fetchMe } from "../utils/fetches/FetchMe";
import i18next from "i18next";

const API_URL = import.meta.env.VITE_APP_API_HOST;

/**
*
* @param param0 - params: Params<string>
* @returns - projectData: projectData,
* courseData: courseData,
* me: me,
* assignmentText: assignmentText,
* isAdmin: isAdmin
*/
export default async function loadProjectViewData({
params,
}: {
params: Params<string>;
}) {
const me = await fetchMe();

const projectId = params.projectId;

const assignmentResponse = await authenticatedFetch(
`${API_URL}/projects/${projectId}/assignment?lang=${i18next.resolvedLanguage}`
);

let assignmentText;

if (assignmentResponse.ok) {
assignmentText = await assignmentResponse.text();
} else {
throw new Response(assignmentResponse.statusText, {
status: assignmentResponse.status,
});
}

const response = await authenticatedFetch(`${API_URL}/projects/${projectId}`);
if (response.ok) {
const data = await response.json();
const projectData = data["data"];

const transformedDeadlines = projectData.deadlines.map(
(deadlineArray: string[]): Deadline => ({
description: deadlineArray[0],
deadline: deadlineArray[1],
})
);

projectData["deadlines"] = transformedDeadlines;

const courseResponse = await authenticatedFetch(
`${API_URL}/courses/${projectData.course_id}`
);

let courseData;
if (courseResponse.ok) {
courseData = (await courseResponse.json())["data"];
} else {
throw new Response(response.statusText, { status: response.status });
}

courseData["admins"] = courseData["admins"].map((admin: string) => {
const urlSplit = admin.split("/");
return urlSplit[urlSplit.length - 1];
});

const isAdmin =
me.uid === courseData["teacher"] || courseData["admins"].includes(me.uid);

return {
projectData: projectData,
courseData: courseData,
me: me,
assignmentText: assignmentText,
isAdmin: isAdmin,
};
} else {
throw new Response(response.statusText, { status: response.status });
}
}
Loading