Skip to content

Commit

Permalink
feat: configuration to allow guest access
Browse files Browse the repository at this point in the history
  • Loading branch information
pateljannat committed Feb 6, 2025
1 parent 49631b6 commit ba26826
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 13 deletions.
4 changes: 2 additions & 2 deletions frontend/src/components/Modals/ChapterModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
7 changes: 7 additions & 0 deletions frontend/src/components/Modals/Settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/pages/CourseForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/pages/LessonForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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()
},
}
Expand Down
12 changes: 11 additions & 1 deletion frontend/src/router.js
Original file line number Diff line number Diff line change
@@ -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 = [
Expand Down Expand Up @@ -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) {
Expand All @@ -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()
})

Expand Down
13 changes: 10 additions & 3 deletions frontend/src/stores/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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,
}
})
7 changes: 6 additions & 1 deletion lms/lms/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ def get_certified_participants(filters=None, start=0, page_length=30, search=Non
return participants


@frappe.whitelist()
@frappe.whitelist(allow_guest=True)
def get_certification_categories():
categories = []
docs = frappe.get_all(
Expand Down Expand Up @@ -1220,3 +1220,8 @@ def get_notifications(filters):
notification.update(from_user_details)

return notifications


@frappe.whitelist(allow_guest=True)
def is_guest_allowed():
return frappe.get_cached_value("LMS Settings", None, "allow_guest_access")
9 changes: 8 additions & 1 deletion lms/lms/doctype/lms_settings/lms_settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"send_calendar_invite_for_evaluations",
"is_onboarding_complete",
"column_break_zdel",
"allow_guest_access",
"enable_learning_paths",
"unsplash_access_key",
"livecode_url",
Expand Down Expand Up @@ -351,12 +352,18 @@
"fieldname": "general_tab",
"fieldtype": "Tab Break",
"label": "General"
},
{
"default": "1",
"fieldname": "allow_guest_access",
"fieldtype": "Check",
"label": "Allow Guest Access"
}
],
"index_web_pages_for_search": 1,
"issingle": 1,
"links": [],
"modified": "2024-11-20 11:55:05.358421",
"modified": "2025-02-06 11:42:29.803207",
"modified_by": "Administrator",
"module": "LMS",
"name": "LMS Settings",
Expand Down
3 changes: 2 additions & 1 deletion lms/patches.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,5 @@ lms.patches.v2_0.give_discussions_permissions
lms.patches.v2_0.delete_web_forms
lms.patches.v2_0.update_desk_access_for_lms_roles
lms.patches.v2_0.update_quiz_submission_data
lms.patches.v2_0.convert_quiz_duration_to_minutes
lms.patches.v2_0.convert_quiz_duration_to_minutes
lms.patches.v2_0.allow_guest_access #05-02-2025
5 changes: 5 additions & 0 deletions lms/patches/v2_0/allow_guest_access.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import frappe


def execute():
frappe.db.set_single_value("LMS Settings", "allow_guest_access", 1)

0 comments on commit ba26826

Please sign in to comment.