Skip to content

Commit b818d78

Browse files
committed
Fix course catalogue access logic and remove unused meta requirements from router
1 parent 3955a86 commit b818d78

2 files changed

Lines changed: 29 additions & 13 deletions

File tree

assets/vue/router/catalogue.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
export default {
22
path: "/catalogue",
3-
meta: { requiresAdmin: true, requiresSessionAdmin: true },
43
component: () => import("../components/layout/SimpleRouterViewLayout.vue"),
54
children: [
65
{

assets/vue/views/course/CatalogueCourses.vue

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -132,23 +132,40 @@ const isPrivilegedUser =
132132
securityStore.isAdmin || securityStore.isTeacher || securityStore.isHRM || securityStore.isSessionAdmin
133133
134134
const allowCatalogueAccess = computed(() => {
135-
if (isAnonymous) return platformConfigStore.getSetting("catalog.course_catalog_published") !== "false"
136-
if (isPrivilegedUser) return true
137-
if (securityStore.isStudent)
135+
if (isAnonymous) {
136+
return platformConfigStore.getSetting("catalog.course_catalog_published") !== "false"
137+
}
138+
139+
if (isPrivilegedUser) {
140+
return true
141+
}
142+
143+
if (securityStore.isStudent) {
138144
return platformConfigStore.getSetting("catalog.allow_students_to_browse_courses") !== "false"
145+
}
146+
139147
return false
140148
})
141149
142-
if (!allowCatalogueAccess.value) {
143-
if (!securityStore.user?.id) {
144-
router.push({ name: "Login" })
145-
} else if (securityStore.isStudent) {
146-
router.push({ name: "Home" })
147-
} else {
148-
router.push({ name: "Index" })
150+
watch(allowCatalogueAccess, async (newValue) => {
151+
if (true !== newValue) {
152+
return
149153
}
150-
throw new Error("Catalogue access denied by settings")
151-
}
154+
155+
if (!securityStore.isAuthenticated) {
156+
await router.push({ name: "Login" })
157+
158+
return
159+
}
160+
161+
if (securityStore.isStudent) {
162+
await router.push({ name: "Home" })
163+
164+
return
165+
}
166+
167+
await router.push({ name: "Index" })
168+
})
152169
153170
const currentUserId = securityStore.user?.id ?? null
154171
const status = ref(false)

0 commit comments

Comments
 (0)