From 408cd3fd7d8edd33a98d048e6450a3687922b276 Mon Sep 17 00:00:00 2001 From: Yared Yemane Date: Thu, 28 May 2026 01:09:46 -0700 Subject: [PATCH] Use practice completion to unlock next student lesson. Switch lesson accessibility gating from deprecated lesson-complete records to published practice completion of the previous lesson so unlocking follows /progress/practices completion flow. Co-authored-by: Cursor --- internal/services/lmsprogress/service.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/internal/services/lmsprogress/service.go b/internal/services/lmsprogress/service.go index ad46909..d2d20cf 100644 --- a/internal/services/lmsprogress/service.go +++ b/internal/services/lmsprogress/service.go @@ -118,7 +118,8 @@ func (s *Service) CanAccessModule(ctx context.Context, userID, moduleID int64) ( return true, "", nil } -// CanAccessLesson requires the module chain to be accessible and the previous lesson in the module to be completed. +// CanAccessLesson requires the module chain to be accessible and the previous lesson in the module +// to be completed based on published practice completion in that lesson. func (s *Service) CanAccessLesson(ctx context.Context, userID, lessonID int64) (ok bool, reason string, err error) { lesson, err := s.store.GetLessonByID(ctx, lessonID) if err != nil { @@ -135,11 +136,13 @@ func (s *Service) CanAccessLesson(ctx context.Context, userID, lessonID int64) ( } return false, "", err } - has, err := s.store.LmsUserHasLessonProgress(ctx, userID, prev.ID) + + // Lesson unlock for STUDENT now follows practice completion, not deprecated lesson-complete writes. + prevCompletedPractices, prevTotalPractices, err := s.store.LmsUserPracticeProgressInLesson(ctx, userID, prev.ID) if err != nil { return false, "", err } - if !has { + if !lmsProgressComplete(prevCompletedPractices, prevTotalPractices) { return false, errPrevLesson, nil } return true, "", nil