RezinaLMS-BackEnd/internal/domain/content_access_tier.go
Yared Yemane 6b02a5a1fc Ensure OPEN_LEARNER bypasses subscription and sequential content locks.
Harden LMS and exam-prep gates so only STUDENT is enforced, and return FREE effective_access_tier for OPEN_LEARNER so clients do not show paywall locks.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-14 02:38:00 -07:00

55 lines
1.7 KiB
Go

package domain
import "strings"
// ContentAccessTier controls whether learners need an active subscription to consume content.
// Effective tier cascades at read time: any PREMIUM ancestor makes descendants PREMIUM.
type ContentAccessTier string
const (
ContentAccessFree ContentAccessTier = "FREE"
ContentAccessPremium ContentAccessTier = "PREMIUM"
)
// ContentAccessTierFromDB normalizes persisted values.
func ContentAccessTierFromDB(raw string) ContentAccessTier {
switch strings.TrimSpace(strings.ToUpper(raw)) {
case string(ContentAccessFree):
return ContentAccessFree
default:
return ContentAccessPremium
}
}
// ContentAccessTierFromCreateInput resolves create body: omit → premium; explicit value validated separately.
func ContentAccessTierFromCreateInput(raw *string) ContentAccessTier {
if raw == nil || strings.TrimSpace(*raw) == "" {
return ContentAccessPremium
}
return ContentAccessTierFromDB(*raw)
}
// EffectiveContentAccessTier returns PREMIUM when any tier in the chain is PREMIUM.
func EffectiveContentAccessTier(tiers ...ContentAccessTier) ContentAccessTier {
for _, tier := range tiers {
if tier == ContentAccessPremium {
return ContentAccessPremium
}
}
return ContentAccessFree
}
// RequiresSubscription is true when the effective tier needs an active plan.
func (t ContentAccessTier) RequiresSubscription() bool {
return t == ContentAccessPremium
}
// ContentAccessTierForRole returns the tier shown to a caller.
// OPEN_LEARNER always sees FREE so clients do not apply paywall/lock UI.
func ContentAccessTierForRole(role Role, tier ContentAccessTier) ContentAccessTier {
if role == RoleOpenLearner {
return ContentAccessFree
}
return tier
}