Skip to content

armgit / ente

Public Imported from GitHub
0

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

Avoid deleting accounts of paid users with active subs

Neeraj Gupta6f1c1d6ed27a
diff --git a/server/pkg/controller/user/inactive_user_orchestrator.go b/server/pkg/controller/user/inactive_user_orchestrator.go
index 68c8a3512b..80b8cab239 100644
--- a/server/pkg/controller/user/inactive_user_orchestrator.go
+++ b/server/pkg/controller/user/inactive_user_orchestrator.go
@@ -160,6 +160,15 @@ func (c *InactiveUserOrchestrator) processCandidate(candidate repo.UserInactivit
return false, nil
}
+ hasActivePaidEntitlement, err := c.hasActivePaidEntitlement(user.ID)
+ if err != nil {
+ return false, err
+ }
+ if hasActivePaidEntitlement {
+ log.WithField("user_id", user.ID).Info("Skipping inactive user processing because user has active paid entitlement")
+ return false, nil
+ }
+
lastActivity, found, err := c.UserRepo.GetLatestTokenActivity(user.ID)
if err != nil {
return false, err
@@ -186,6 +195,14 @@ func (c *InactiveUserOrchestrator) processCandidate(candidate repo.UserInactivit
if c.UserController == nil {
return false, fmt.Errorf("inactive user deletion requires user controller")
}
+ hasActivePaidEntitlement, err := c.hasActivePaidEntitlement(user.ID)
+ if err != nil {
+ return false, err
+ }
+ if hasActivePaidEntitlement {
+ log.WithField("user_id", user.ID).Info("Skipping inactive user deletion because user has active paid entitlement")
+ return false, nil
+ }
// Re-check right before deletion to avoid deleting users who became active
// after earlier reads in long processing runs.
@@ -252,6 +269,17 @@ func (c *InactiveUserOrchestrator) processCandidate(candidate repo.UserInactivit
return true, nil
}
+func (c *InactiveUserOrchestrator) hasActivePaidEntitlement(userID int64) (bool, error) {
+ err := c.UserController.BillingController.HasActiveSelfOrFamilySubscription(userID, true)
+ if err == nil {
+ return true, nil
+ }
+ if errors.Is(err, ente.ErrNoActiveSubscription) || errors.Is(err, ente.ErrSharingDisabledForFreeAccounts) {
+ return false, nil
+ }
+ return false, err
+}
+
func (c *InactiveUserOrchestrator) resolveNextStage(userID int64, lastActivity int64, now int64) (inactivityEmailStage, error) {
history, err := c.NotificationHistoryRepo.GetLastNotificationTimes(userID, inactiveUserDeletionTemplateIDs)
if err != nil {