feat: configuration to allow guest access

This commit is contained in:
Jannat Patel
2025-02-06 12:14:24 +05:30
parent 49631b6e56
commit ba26826896
10 changed files with 55 additions and 13 deletions

View File

@@ -145,9 +145,9 @@ const addChapter = async (close) => {
{
onSuccess(data) {
cleanChapter()
if (!settingsStore.onboardingDetails.data?.is_onboarded) {
/* if (!settingsStore.onboardingDetails.data?.is_onboarded) {
settingsStore.onboardingDetails.reload()
}
} */
outline.value.reload()
showToast(
__('Success'),

View File

@@ -118,6 +118,13 @@ const tabsStructure = computed(() => {
'This will enforce students to go through programs assigned to them in the correct order.',
type: 'checkbox',
},
{
label: 'Allow Guest Access',
name: 'allow_guest_access',
description:
'If enabled, users can access the course and batch lists without logging in.',
type: 'checkbox',
},
{
label: 'Send calendar invite for evaluations',
name: 'send_calendar_invite_for_evaluations',

View File

@@ -435,9 +435,9 @@ const submitCourse = () => {
onSuccess(data) {
capture('course_created')
showToast('Success', 'Course created successfully', 'check')
if (!settingsStore.onboardingDetails.data?.is_onboarded) {
/* if (!settingsStore.onboardingDetails.data?.is_onboarded) {
settingsStore.onboardingDetails.reload()
}
} */
router.push({
name: 'CourseForm',
params: { courseName: data.name },

View File

@@ -396,9 +396,9 @@ const createNewLesson = () => {
onSuccess() {
capture('lesson_created')
showToast('Success', 'Lesson created successfully', 'check')
if (!settingsStore.onboardingDetails.data?.is_onboarded) {
/* if (!settingsStore.onboardingDetails.data?.is_onboarded) {
settingsStore.onboardingDetails.reload()
}
} */
lessonDetails.reload()
},
}

View File

@@ -1,6 +1,7 @@
import { createRouter, createWebHistory } from 'vue-router'
import { usersStore } from './stores/user'
import { sessionStore } from './stores/session'
import { useSettings } from './stores/settings'
let defaultRoute = '/courses'
const routes = [
@@ -218,7 +219,8 @@ let router = createRouter({
router.beforeEach(async (to, from, next) => {
const { userResource } = usersStore()
let { isLoggedIn } = sessionStore()
const { isLoggedIn } = sessionStore()
const { allowGuestAccess } = useSettings()
try {
if (isLoggedIn) {
@@ -227,6 +229,14 @@ router.beforeEach(async (to, from, next) => {
} catch (error) {
isLoggedIn = false
}
if (!isLoggedIn) {
await allowGuestAccess.promise
if (!allowGuestAccess.data) {
window.location.href = '/login'
return
}
}
return next()
})

View File

@@ -7,6 +7,7 @@ export const useSettings = defineStore('settings', () => {
const { isLoggedIn } = sessionStore()
const isSettingsOpen = ref(false)
const activeTab = ref(null)
const learningPaths = createResource({
url: 'frappe.client.get_single_value',
makeParams(values) {
@@ -19,16 +20,22 @@ export const useSettings = defineStore('settings', () => {
cache: ['learningPaths'],
})
const onboardingDetails = createResource({
const allowGuestAccess = createResource({
url: 'lms.lms.api.is_guest_allowed',
auto: true,
cache: ['allowGuestAccess'],
})
/* const onboardingDetails = createResource({
url: 'lms.lms.utils.is_onboarding_complete',
auto: isLoggedIn ? true : false,
cache: ['onboardingDetails'],
})
}) */
return {
isSettingsOpen,
activeTab,
learningPaths,
onboardingDetails,
allowGuestAccess,
}
})