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