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 <cursoragent@cursor.com>
This commit is contained in:
Yared Yemane 2026-05-28 01:09:46 -07:00
parent fc67de935d
commit 408cd3fd7d

View File

@ -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