From ceb7f4cc105e297c0358037be416d9235b96c66a Mon Sep 17 00:00:00 2001 From: Bram Reyniers Date: Mon, 20 May 2024 16:32:13 +0200 Subject: [PATCH] permissions for groups overview --- frontend/src/router/index.ts | 10 ++++++++-- frontend/src/router/middleware/canVisit.ts | 15 --------------- 2 files changed, 8 insertions(+), 17 deletions(-) diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.ts index 284a15d8..32587b76 100644 --- a/frontend/src/router/index.ts +++ b/frontend/src/router/index.ts @@ -9,12 +9,10 @@ import useCanVisit, { useIsInstructorOfSubjectCondition, useIsStudentOfProjectCondition, useIsInstructorOfProjectCondition, - useIsPartOfSubjectCondition, useAndCondition, useOrCondition, useIsInGroupOfProjectCondition, } from "./middleware/canVisit"; -import { ref } from "vue"; declare module "vue-router" { interface RouteMeta { @@ -87,6 +85,14 @@ const router = createRouter({ name: "groups", component: () => import("../views/GroupsView.vue"), props: (route) => ({ projectId: Number(route.params.projectId) }), + meta: { + middleware: useCanVisit( + useOrCondition( + useIsStudentOfProjectCondition, + useIsInstructorOfProjectCondition + ) + ), + }, }, { path: "/groups/:groupId(\\d+)", diff --git a/frontend/src/router/middleware/canVisit.ts b/frontend/src/router/middleware/canVisit.ts index 7e997cc7..4a7b66b0 100644 --- a/frontend/src/router/middleware/canVisit.ts +++ b/frontend/src/router/middleware/canVisit.ts @@ -129,18 +129,3 @@ export const useIsInGroupOfProjectCondition: CanVisitCondition = (qc, ctx) => { }); return { condition, isLoading }; }; - -export const useIsPartOfSubjectCondition: CanVisitCondition = (qc, ctx) => { - const subjectId = Number(ctx.to.params.subjectId); - const { data: subjects, isLoading } = useSubjectsQuery(qc); - const condition = computed(() => { - const student_subjects = subjects.value?.as_student || []; - const instructor_subjects = subjects.value?.as_instructor || []; - return ( - [...student_subjects, ...instructor_subjects].findIndex( - (subject) => subject.id === subjectId - ) !== -1 - ); - }); - return { condition, isLoading }; -};