Skip to content

Commit ba26826

Browse files
committed
feat: configuration to allow guest access
1 parent 49631b6 commit ba26826

File tree

10 files changed

+55
-13
lines changed

10 files changed

+55
-13
lines changed

frontend/src/components/Modals/ChapterModal.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,9 @@ const addChapter = async (close) => {
145145
{
146146
onSuccess(data) {
147147
cleanChapter()
148-
if (!settingsStore.onboardingDetails.data?.is_onboarded) {
148+
/* if (!settingsStore.onboardingDetails.data?.is_onboarded) {
149149
settingsStore.onboardingDetails.reload()
150-
}
150+
} */
151151
outline.value.reload()
152152
showToast(
153153
__('Success'),

frontend/src/components/Modals/Settings.vue

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,13 @@ const tabsStructure = computed(() => {
118118
'This will enforce students to go through programs assigned to them in the correct order.',
119119
type: 'checkbox',
120120
},
121+
{
122+
label: 'Allow Guest Access',
123+
name: 'allow_guest_access',
124+
description:
125+
'If enabled, users can access the course and batch lists without logging in.',
126+
type: 'checkbox',
127+
},
121128
{
122129
label: 'Send calendar invite for evaluations',
123130
name: 'send_calendar_invite_for_evaluations',

frontend/src/pages/CourseForm.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,9 +435,9 @@ const submitCourse = () => {
435435
onSuccess(data) {
436436
capture('course_created')
437437
showToast('Success', 'Course created successfully', 'check')
438-
if (!settingsStore.onboardingDetails.data?.is_onboarded) {
438+
/* if (!settingsStore.onboardingDetails.data?.is_onboarded) {
439439
settingsStore.onboardingDetails.reload()
440-
}
440+
} */
441441
router.push({
442442
name: 'CourseForm',
443443
params: { courseName: data.name },

frontend/src/pages/LessonForm.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,9 +396,9 @@ const createNewLesson = () => {
396396
onSuccess() {
397397
capture('lesson_created')
398398
showToast('Success', 'Lesson created successfully', 'check')
399-
if (!settingsStore.onboardingDetails.data?.is_onboarded) {
399+
/* if (!settingsStore.onboardingDetails.data?.is_onboarded) {
400400
settingsStore.onboardingDetails.reload()
401-
}
401+
} */
402402
lessonDetails.reload()
403403
},
404404
}

frontend/src/router.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { createRouter, createWebHistory } from 'vue-router'
22
import { usersStore } from './stores/user'
33
import { sessionStore } from './stores/session'
4+
import { useSettings } from './stores/settings'
45

56
let defaultRoute = '/courses'
67
const routes = [
@@ -218,7 +219,8 @@ let router = createRouter({
218219

219220
router.beforeEach(async (to, from, next) => {
220221
const { userResource } = usersStore()
221-
let { isLoggedIn } = sessionStore()
222+
const { isLoggedIn } = sessionStore()
223+
const { allowGuestAccess } = useSettings()
222224

223225
try {
224226
if (isLoggedIn) {
@@ -227,6 +229,14 @@ router.beforeEach(async (to, from, next) => {
227229
} catch (error) {
228230
isLoggedIn = false
229231
}
232+
233+
if (!isLoggedIn) {
234+
await allowGuestAccess.promise
235+
if (!allowGuestAccess.data) {
236+
window.location.href = '/login'
237+
return
238+
}
239+
}
230240
return next()
231241
})
232242

frontend/src/stores/settings.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export const useSettings = defineStore('settings', () => {
77
const { isLoggedIn } = sessionStore()
88
const isSettingsOpen = ref(false)
99
const activeTab = ref(null)
10+
1011
const learningPaths = createResource({
1112
url: 'frappe.client.get_single_value',
1213
makeParams(values) {
@@ -19,16 +20,22 @@ export const useSettings = defineStore('settings', () => {
1920
cache: ['learningPaths'],
2021
})
2122

22-
const onboardingDetails = createResource({
23+
const allowGuestAccess = createResource({
24+
url: 'lms.lms.api.is_guest_allowed',
25+
auto: true,
26+
cache: ['allowGuestAccess'],
27+
})
28+
29+
/* const onboardingDetails = createResource({
2330
url: 'lms.lms.utils.is_onboarding_complete',
2431
auto: isLoggedIn ? true : false,
2532
cache: ['onboardingDetails'],
26-
})
33+
}) */
2734

2835
return {
2936
isSettingsOpen,
3037
activeTab,
3138
learningPaths,
32-
onboardingDetails,
39+
allowGuestAccess,
3340
}
3441
})

lms/lms/api.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ def get_certified_participants(filters=None, start=0, page_length=30, search=Non
409409
return participants
410410

411411

412-
@frappe.whitelist()
412+
@frappe.whitelist(allow_guest=True)
413413
def get_certification_categories():
414414
categories = []
415415
docs = frappe.get_all(
@@ -1220,3 +1220,8 @@ def get_notifications(filters):
12201220
notification.update(from_user_details)
12211221

12221222
return notifications
1223+
1224+
1225+
@frappe.whitelist(allow_guest=True)
1226+
def is_guest_allowed():
1227+
return frappe.get_cached_value("LMS Settings", None, "allow_guest_access")

lms/lms/doctype/lms_settings/lms_settings.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"send_calendar_invite_for_evaluations",
1111
"is_onboarding_complete",
1212
"column_break_zdel",
13+
"allow_guest_access",
1314
"enable_learning_paths",
1415
"unsplash_access_key",
1516
"livecode_url",
@@ -351,12 +352,18 @@
351352
"fieldname": "general_tab",
352353
"fieldtype": "Tab Break",
353354
"label": "General"
355+
},
356+
{
357+
"default": "1",
358+
"fieldname": "allow_guest_access",
359+
"fieldtype": "Check",
360+
"label": "Allow Guest Access"
354361
}
355362
],
356363
"index_web_pages_for_search": 1,
357364
"issingle": 1,
358365
"links": [],
359-
"modified": "2024-11-20 11:55:05.358421",
366+
"modified": "2025-02-06 11:42:29.803207",
360367
"modified_by": "Administrator",
361368
"module": "LMS",
362369
"name": "LMS Settings",

lms/patches.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,5 @@ lms.patches.v2_0.give_discussions_permissions
9696
lms.patches.v2_0.delete_web_forms
9797
lms.patches.v2_0.update_desk_access_for_lms_roles
9898
lms.patches.v2_0.update_quiz_submission_data
99-
lms.patches.v2_0.convert_quiz_duration_to_minutes
99+
lms.patches.v2_0.convert_quiz_duration_to_minutes
100+
lms.patches.v2_0.allow_guest_access #05-02-2025
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import frappe
2+
3+
4+
def execute():
5+
frappe.db.set_single_value("LMS Settings", "allow_guest_access", 1)

0 commit comments

Comments
 (0)