Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[server] Add tiered Locker limits for free and paid users

AmanRajSinghMourya786f3a26e259
diff --git a/server/pkg/controller/usage.go b/server/pkg/controller/usage.go
index 6728e459dd..bc2de2966a 100644
--- a/server/pkg/controller/usage.go
+++ b/server/pkg/controller/usage.go
@@ -27,9 +27,13 @@ type UsageController struct {
UploadResultCache map[int64]bool
}
-const MaxLockerFiles = 1000
+// Locker limits by subscription tier
+const lockerFreeFileLimit = 100
+const lockerPaidFileLimit = 1000
+const lockerFreeStorageLimit = 1 * 1024 * 1024 * 1024 // 1 GiB
+const lockerPaidStorageLimit = 10 * 1024 * 1024 * 1024 // 10 GiB
+
const hundredMBInBytes = 100 * 1024 * 1024
-const lockerFamilyStorageLimit = 10 * 1024 * 1024 * 1024 // 10 GiB
// CanUploadFile returns error if the file of given size (with StorageOverflowAboveSubscriptionLimit buffer) can be
// uploaded or not. If size is not passed, it validates if current usage is less than subscription storage.
@@ -91,16 +95,34 @@ func (c *UsageController) canUploadFile(ctx context.Context, userID int64, size
if lUsageErr != nil {
return stacktrace.Propagate(lUsageErr, "failed to fetch locker usage")
}
+
+ // Determine if user has paid subscription for tiered limits
+ isPaidUser := false
+ if err := c.BillingCtrl.HasActiveSelfOrFamilySubscription(subscriptionAdminID, true); err == nil {
+ isPaidUser = true
+ }
+
+ // Apply tiered file and storage limits
+ maxFiles := int64(lockerFreeFileLimit)
+ maxStorage := int64(lockerFreeStorageLimit)
+ if isPaidUser {
+ maxFiles = int64(lockerPaidFileLimit)
+ maxStorage = int64(lockerPaidStorageLimit)
+ }
+
+ // Check file count limit
+ if lockerUsage.TotalFileCount >= maxFiles {
+ return stacktrace.Propagate(&ente.ErrFileLimitReached, "")
+ }
+
+ // Check storage limit
projectedLockerUsage := lockerUsage.TotalUsage
if size != nil {
projectedLockerUsage += *size
}
- if lockerUsage.TotalFileCount >= MaxLockerFiles {
- return stacktrace.Propagate(&ente.ErrFileLimitReached, "")
- }
- if projectedLockerUsage >= lockerFamilyStorageLimit {
+ if projectedLockerUsage >= maxStorage {
return stacktrace.Propagate(ente.ErrStorageLimitExceeded,
- fmt.Sprintf("locker family storage limit exceeded (limit %d, usage %d)", lockerFamilyStorageLimit, projectedLockerUsage))
+ fmt.Sprintf("locker storage limit exceeded (limit %d, usage %d)", maxStorage, projectedLockerUsage))
}
}
diff --git a/server/pkg/controller/user/user_details.go b/server/pkg/controller/user/user_details.go
index 7b56066cb4..090d5694e2 100644
--- a/server/pkg/controller/user/user_details.go
+++ b/server/pkg/controller/user/user_details.go
@@ -165,5 +165,6 @@ func (c *UserController) GetDetailsV2(ctx *gin.Context, userID int64, fetchMemor
result.FamilyData = familyData
}
}
+
return result, nil
}
diff --git a/server/pkg/controller/user/userauth.go b/server/pkg/controller/user/userauth.go
index 9a8eb7d9a8..b632781876 100644
--- a/server/pkg/controller/user/userauth.go
+++ b/server/pkg/controller/user/userauth.go
@@ -357,17 +357,33 @@ func (c *UserController) GetActiveSessions(context *gin.Context, userID int64) (
return tokens, nil
}
-func (c *UserController) ensureLockerPaidAccess(userID int64, app ente.App) error {
+func (c *UserController) ensureLockerAccess(userID int64, app ente.App) error {
if app != ente.Locker {
return nil
}
- const restrictionMsg = "locker is restricted to paid users currently"
- if err := c.BillingController.HasActiveSelfOrFamilySubscription(userID, true); err != nil {
- if !errors.Is(err, ente.ErrNoActiveSubscription) && !errors.Is(err, ente.ErrSharingDisabledForFreeAccounts) {
- log.WithError(err).Error("locker access: failed to verify active subscription status")
+
+ // Check if user has Photos or Auth tokens (existing Ente user)
+ // Free tier: Users with existing Photos/Auth account can use Locker with limited features
+ // Paid tier: Users with paid Photos subscription get full Locker features
+ apps, err := c.UserAuthRepo.GetAppsForUser(userID)
+ if err != nil {
+ return stacktrace.Propagate(err, "failed to check user apps")
+ }
+
+ hasPhotosOrAuth := false
+ for _, userApp := range apps {
+ if userApp == ente.Photos || userApp == ente.Auth {
+ hasPhotosOrAuth = true
+ break
}
- return stacktrace.Propagate(ente.ErrLockerRegistrationDisabled, restrictionMsg)
}
+
+ if !hasPhotosOrAuth {
+ return stacktrace.Propagate(ente.ErrLockerRegistrationDisabled,
+ "locker is available only to existing Ente users")
+ }
+
+ // Check rollout limit
if err := c.UserAuthRepo.EnsureLockerRolloutAccess(userID); err != nil {
return stacktrace.Propagate(err, "locker access: rollout check failed")
}
@@ -375,7 +391,7 @@ func (c *UserController) ensureLockerPaidAccess(userID int64, app ente.App) erro
}
func (c *UserController) AddTokenAndNotify(userID int64, app ente.App, token string, ip string, userAgent string) error {
- if err := c.ensureLockerPaidAccess(userID, app); err != nil {
+ if err := c.ensureLockerAccess(userID, app); err != nil {
return err
}
err := c.UserAuthRepo.AddToken(userID, app, token, ip, userAgent)
@@ -501,7 +517,7 @@ func (c *UserController) onVerificationSuccess(context *gin.Context, email strin
if errors.Is(err, sql.ErrNoRows) {
// user creation is pending on key attributes set based on the password.
// No need to send login notification
- if lockerErr := c.ensureLockerPaidAccess(userID, app); lockerErr != nil {
+ if lockerErr := c.ensureLockerAccess(userID, app); lockerErr != nil {
return ente.EmailAuthorizationResponse{}, lockerErr
}
err = c.UserAuthRepo.AddToken(userID, app, token,