From 7847191d9792b7934a2ff2ac4b05607cb0921501 Mon Sep 17 00:00:00 2001 From: Daniel Egger Date: Fri, 19 Apr 2024 12:46:38 +0200 Subject: [PATCH] Fix `ignoreGuardsForHomeRoute` workaround... --- .../components/header/MainNavigationBar.vue | 2 +- client/src/router/guards.ts | 9 ++++++-- client/src/router/index.ts | 23 ++++--------------- server/config/urls.py | 2 +- 4 files changed, 14 insertions(+), 22 deletions(-) diff --git a/client/src/components/header/MainNavigationBar.vue b/client/src/components/header/MainNavigationBar.vue index 3d432ac1..6d9ba7ea 100644 --- a/client/src/components/header/MainNavigationBar.vue +++ b/client/src/components/header/MainNavigationBar.vue @@ -60,7 +60,7 @@ const selectedCourseSessionTitle = computed(() => { const appointmentsUrl = computed(() => { const currentCourseSession = courseSessionsStore.currentCourseSession; if (currentCourseSession) { - return `/course/${currentCourseSession.course.slug}/appointments`; + return `/course/dashboard/due-dates`; } else { return `/appointments`; } diff --git a/client/src/router/guards.ts b/client/src/router/guards.ts index 7e8b1ed6..ea3e8504 100644 --- a/client/src/router/guards.ts +++ b/client/src/router/guards.ts @@ -51,7 +51,10 @@ const loginRequired = (to: RouteLocationNormalized) => { return !to.meta?.public; }; -export async function handleCurrentCourseSession(to: RouteLocationNormalized) { +export async function handleCurrentCourseSession( + to: RouteLocationNormalized, + options?: { unset?: boolean } +) { // register after login hooks const userStore = useUserStore(); if (userStore.loggedIn) { @@ -59,7 +62,9 @@ export async function handleCurrentCourseSession(to: RouteLocationNormalized) { if (to.params.courseSlug) { courseSessionsStore._currentCourseSlug = to.params.courseSlug as string; } else { - courseSessionsStore._currentCourseSlug = ""; + if (options?.unset) { + courseSessionsStore._currentCourseSlug = ""; + } } if (!courseSessionsStore.loaded) { console.log("handleCurrentCourseSession: loadCourseSessionsData"); diff --git a/client/src/router/index.ts b/client/src/router/index.ts index 2e9f94d7..992d884a 100644 --- a/client/src/router/index.ts +++ b/client/src/router/index.ts @@ -12,7 +12,6 @@ import { } from "@/router/guards"; import { addToHistory } from "@/router/history"; import { onboardingRedirect } from "@/router/onboarding"; -import type { RouteLocationNormalized } from "vue-router"; import { createRouter, createWebHistory } from "vue-router"; const router = createRouter({ @@ -396,26 +395,14 @@ router.beforeEach(updateLoggedIn); router.beforeEach(redirectToLoginIfRequired); // register after login hooks -router.beforeEach( - async (to, from) => - await ignoreGuardsForHomeRoute(to, from, handleCurrentCourseSession) -); +router.beforeEach(async (to, from) => await handleCurrentCourseSession(to)); +router.beforeEach(async (to, from) => await handleCourseSessionAsQueryParam(to)); -router.beforeEach( - async (to, from) => - await ignoreGuardsForHomeRoute(to, from, handleCourseSessionAsQueryParam) +// only unset the current course session in the after hook +router.afterEach( + async (to, from) => await handleCurrentCourseSession(to, { unset: true }) ); -async function ignoreGuardsForHomeRoute( - to: RouteLocationNormalized, - from: RouteLocationNormalized, - guard: any -) { - if (to.name !== "home") { - return await guard(to); - } -} - router.beforeEach(addToHistory); export default router; diff --git a/server/config/urls.py b/server/config/urls.py index 716d4747..1bd57c20 100644 --- a/server/config/urls.py +++ b/server/config/urls.py @@ -41,10 +41,10 @@ from vbv_lernwelt.course.views import ( from vbv_lernwelt.course_session.views import get_course_session_documents from vbv_lernwelt.dashboard.views import ( get_dashboard_config, + get_dashboard_due_dates, get_dashboard_persons, get_mentee_count, get_mentor_open_tasks_count, - get_dashboard_due_dates, ) from vbv_lernwelt.edoniq_test.views import ( export_students,