Skip to content

Commit

Permalink
permissions for groups overview
Browse files Browse the repository at this point in the history
  • Loading branch information
reyniersbram committed May 20, 2024
1 parent 9f997b7 commit ceb7f4c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 17 deletions.
10 changes: 8 additions & 2 deletions frontend/src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@ import useCanVisit, {
useIsInstructorOfSubjectCondition,
useIsStudentOfProjectCondition,
useIsInstructorOfProjectCondition,
useIsPartOfSubjectCondition,
useAndCondition,

Check warning on line 12 in frontend/src/router/index.ts

View workflow job for this annotation

GitHub Actions / Run linters

'useAndCondition' is defined but never used
useOrCondition,
useIsInGroupOfProjectCondition,
} from "./middleware/canVisit";
import { ref } from "vue";

declare module "vue-router" {
interface RouteMeta {
Expand Down Expand Up @@ -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+)",
Expand Down
15 changes: 0 additions & 15 deletions frontend/src/router/middleware/canVisit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
};

0 comments on commit ceb7f4c

Please sign in to comment.