Merge pull request #1292 from pateljannat/hide-public-pages

feat: configuration to allow guest access
This commit is contained in:
Jannat Patel
2025-02-06 12:41:45 +05:30
committed by GitHub
10 changed files with 55 additions and 13 deletions

View File

@@ -145,9 +145,9 @@ const addChapter = async (close) => {
{ {
onSuccess(data) { onSuccess(data) {
cleanChapter() cleanChapter()
if (!settingsStore.onboardingDetails.data?.is_onboarded) { /* if (!settingsStore.onboardingDetails.data?.is_onboarded) {
settingsStore.onboardingDetails.reload() settingsStore.onboardingDetails.reload()
} } */
outline.value.reload() outline.value.reload()
showToast( showToast(
__('Success'), __('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.', 'This will enforce students to go through programs assigned to them in the correct order.',
type: 'checkbox', 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', label: 'Send calendar invite for evaluations',
name: 'send_calendar_invite_for_evaluations', name: 'send_calendar_invite_for_evaluations',

View File

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

View File

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

View File

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

View File

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

View File

@@ -409,7 +409,7 @@ def get_certified_participants(filters=None, start=0, page_length=30, search=Non
return participants return participants
@frappe.whitelist() @frappe.whitelist(allow_guest=True)
def get_certification_categories(): def get_certification_categories():
categories = [] categories = []
docs = frappe.get_all( docs = frappe.get_all(
@@ -1220,3 +1220,8 @@ def get_notifications(filters):
notification.update(from_user_details) notification.update(from_user_details)
return notifications return notifications
@frappe.whitelist(allow_guest=True)
def is_guest_allowed():
return frappe.get_cached_value("LMS Settings", None, "allow_guest_access")

View File

@@ -10,6 +10,7 @@
"send_calendar_invite_for_evaluations", "send_calendar_invite_for_evaluations",
"is_onboarding_complete", "is_onboarding_complete",
"column_break_zdel", "column_break_zdel",
"allow_guest_access",
"enable_learning_paths", "enable_learning_paths",
"unsplash_access_key", "unsplash_access_key",
"livecode_url", "livecode_url",
@@ -351,12 +352,18 @@
"fieldname": "general_tab", "fieldname": "general_tab",
"fieldtype": "Tab Break", "fieldtype": "Tab Break",
"label": "General" "label": "General"
},
{
"default": "1",
"fieldname": "allow_guest_access",
"fieldtype": "Check",
"label": "Allow Guest Access"
} }
], ],
"index_web_pages_for_search": 1, "index_web_pages_for_search": 1,
"issingle": 1, "issingle": 1,
"links": [], "links": [],
"modified": "2024-11-20 11:55:05.358421", "modified": "2025-02-06 11:42:29.803207",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "LMS", "module": "LMS",
"name": "LMS Settings", "name": "LMS Settings",

View File

@@ -97,3 +97,4 @@ lms.patches.v2_0.delete_web_forms
lms.patches.v2_0.update_desk_access_for_lms_roles lms.patches.v2_0.update_desk_access_for_lms_roles
lms.patches.v2_0.update_quiz_submission_data 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

View File

@@ -0,0 +1,5 @@
import frappe
def execute():
frappe.db.set_single_value("LMS Settings", "allow_guest_access", 1)