From 7ff22080f04165ef999db48392e98703120e1fb4 Mon Sep 17 00:00:00 2001 From: Yared Yemane Date: Wed, 15 Jul 2026 00:32:58 -0700 Subject: [PATCH] Disable exam-prep precedence locking for STUDENT learners. Exam-prep content is gated by subscription/tier only. Learn English sequential locking is unchanged. Co-authored-by: Cursor --- internal/domain/lms_access.go | 3 ++- internal/domain/role.go | 9 ++++++++- internal/domain/role_test.go | 10 ++++++++-- internal/services/lmsprogress/service.go | 8 ++++---- internal/services/rbac/seeds.go | 2 +- .../web_server/handlers/exam_prep_progress_helper.go | 3 ++- 6 files changed, 25 insertions(+), 10 deletions(-) diff --git a/internal/domain/lms_access.go b/internal/domain/lms_access.go index 4a701e96..9df307d8 100644 --- a/internal/domain/lms_access.go +++ b/internal/domain/lms_access.go @@ -2,7 +2,8 @@ package domain // LMSEntityAccess describes learner gating for a program, course, module, or lesson. // Included for STUDENT and OPEN_LEARNER; omitted (nil) for staff roles in API responses. -// OPEN_LEARNER always has is_accessible and is_completed true and bypasses subscription gates; STUDENT reflects real progress and gating. +// OPEN_LEARNER always has is_accessible and is_completed true and bypasses subscription gates. +// STUDENT Learn English access reflects sequential prerequisites; exam-prep is accessible when subscription/tier allows (no precedence locks). // Progress fields count completed published practices vs total published practices in the // entity's scope. progress_percent keeps the legacy whole-number value; use // progress_percent_precise for decimal precision in learner UIs. diff --git a/internal/domain/role.go b/internal/domain/role.go index ce6dba1e..6a70002e 100644 --- a/internal/domain/role.go +++ b/internal/domain/role.go @@ -22,11 +22,18 @@ func (r Role) IsValid() bool { } } -// UsesLMSSequentialGating is true when LMS APIs apply sequential prerequisite locks (403 when blocked). +// UsesLMSSequentialGating is true when Learn English (LMS) APIs apply sequential prerequisite locks (403 when blocked). +// Exam-prep does not use this — see UsesExamPrepSequentialGating. func (r Role) UsesLMSSequentialGating() bool { return r == RoleStudent } +// UsesExamPrepSequentialGating is true when exam-prep APIs apply precedence / practice-order locks. +// Currently disabled for all roles: STUDENT access is subscription/tier only; OPEN_LEARNER already bypasses gates. +func (r Role) UsesExamPrepSequentialGating() bool { + return false +} + // IsCustomerLearnerRole is true for platform roles that sign in as customers and consume learner-facing LMS APIs. func (r Role) IsCustomerLearnerRole() bool { return r == RoleStudent || r == RoleOpenLearner diff --git a/internal/domain/role_test.go b/internal/domain/role_test.go index 324218d0..606b4c29 100644 --- a/internal/domain/role_test.go +++ b/internal/domain/role_test.go @@ -8,7 +8,10 @@ func TestRoleOpenLearnerBypassesSubscriptionAndSequentialLocks(t *testing.T) { t.Fatal("OPEN_LEARNER must bypass subscription gates") } if role.UsesLMSSequentialGating() { - t.Fatal("OPEN_LEARNER must not use sequential / precedence locking") + t.Fatal("OPEN_LEARNER must not use Learn English sequential locking") + } + if role.UsesExamPrepSequentialGating() { + t.Fatal("OPEN_LEARNER must not use exam-prep sequential locking") } if !role.IsCustomerLearnerRole() { t.Fatal("OPEN_LEARNER should be a customer learner role") @@ -21,6 +24,9 @@ func TestRoleStudentKeepsSubscriptionAndSequentialLocks(t *testing.T) { t.Fatal("STUDENT must not bypass subscription gates") } if !role.UsesLMSSequentialGating() { - t.Fatal("STUDENT must use sequential / precedence locking") + t.Fatal("STUDENT must use Learn English sequential / precedence locking") + } + if role.UsesExamPrepSequentialGating() { + t.Fatal("STUDENT must not use exam-prep sequential / precedence locking") } } diff --git a/internal/services/lmsprogress/service.go b/internal/services/lmsprogress/service.go index 67ef9392..88035f09 100644 --- a/internal/services/lmsprogress/service.go +++ b/internal/services/lmsprogress/service.go @@ -435,7 +435,7 @@ func (s *Service) ApplyExamPrepAccessCatalogCourse(ctx context.Context, role dom return err } ok, reason := true, "" - if role.UsesLMSSequentialGating() { + if role.UsesExamPrepSequentialGating() { ok, reason, err = s.CanAccessExamPrepCatalogCourse(ctx, userID, cc.ID) if err != nil { return err @@ -456,7 +456,7 @@ func (s *Service) ApplyExamPrepAccessUnit(ctx context.Context, role domain.Role, return err } ok, reason := true, "" - if role.UsesLMSSequentialGating() { + if role.UsesExamPrepSequentialGating() { ok, reason, err = s.CanAccessExamPrepUnit(ctx, userID, u.ID) if err != nil { return err @@ -477,7 +477,7 @@ func (s *Service) ApplyExamPrepAccessModule(ctx context.Context, role domain.Rol return err } ok, reason := true, "" - if role.UsesLMSSequentialGating() { + if role.UsesExamPrepSequentialGating() { ok, reason, err = s.CanAccessExamPrepModule(ctx, userID, m.ID) if err != nil { return err @@ -498,7 +498,7 @@ func (s *Service) ApplyExamPrepAccessLesson(ctx context.Context, role domain.Rol return err } ok, reason := true, "" - if role.UsesLMSSequentialGating() { + if role.UsesExamPrepSequentialGating() { ok, reason, err = s.CanAccessExamPrepLesson(ctx, userID, les.ID) if err != nil { return err diff --git a/internal/services/rbac/seeds.go b/internal/services/rbac/seeds.go index 49b39e2a..f30f6ae9 100644 --- a/internal/services/rbac/seeds.go +++ b/internal/services/rbac/seeds.go @@ -352,7 +352,7 @@ var AllPermissions = []domain.PermissionSeed{ } // defaultStudentLearnerPermissions is the learner consumption permission set shared by STUDENT and OPEN_LEARNER. -// LMS sequential prerequisite locking applies only to STUDENT in application handlers. +// Learn English sequential prerequisite locking applies only to STUDENT; exam-prep has no precedence locking. var defaultStudentLearnerPermissions = []string{ // Course browsing "course_categories.list", "course_categories.get", diff --git a/internal/web_server/handlers/exam_prep_progress_helper.go b/internal/web_server/handlers/exam_prep_progress_helper.go index 6079aeba..6b2c9d5f 100644 --- a/internal/web_server/handlers/exam_prep_progress_helper.go +++ b/internal/web_server/handlers/exam_prep_progress_helper.go @@ -10,7 +10,8 @@ import ( func (h *Handler) enforceExamPrepPracticeSequenceForStudent(c *fiber.Ctx, questionSetID int64) error { role, _ := c.Locals("role").(domain.Role) - if !role.UsesLMSSequentialGating() { + // Exam-prep has no precedence locking; subscription/tier middleware is the access gate. + if !role.UsesExamPrepSequentialGating() { return nil } userID, ok := c.Locals("user_id").(int64)