π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
server: keep storage warning family selection per-member
Neeraj Gupta0e97aeb7fb50
diff --git a/server/pkg/repo/usage.go b/server/pkg/repo/usage.goindex bfe54d2a07..3ebdb21a0a 100644--- a/server/pkg/repo/usage.go+++ b/server/pkg/repo/usage.go@@ -66,36 +66,20 @@ func (repo *UsageRepository) GetCombinedUsage(ctx context.Context, userIDs []int}func (repo *UsageRepository) GetStorageWarningCandidates(ctx context.Context, usageThreshold int64) ([]StorageWarningCandidate, error) {+ // Intentionally use per-member usage when selecting family candidates. The+ // mailer evaluates aggregate family usage later, but candidate selection is+ // deliberately narrower so families are only pulled into the workflow when a+ // specific member crosses the threshold.rows, err := repo.DB.QueryContext(ctx, `- SELECT recipient_id, is_family_plan- FROM (- SELECT- admin.user_id AS recipient_id,- TRUE AS is_family_plan- FROM users admin- LEFT JOIN users members- ON members.family_admin_id = admin.user_id- LEFT JOIN usage us- ON us.user_id = members.user_id- WHERE- admin.family_admin_id = admin.user_id- AND admin.encrypted_email IS NOT NULL- GROUP BY admin.user_id- HAVING COALESCE(SUM(us.storage_consumed), 0) > $1-- UNION ALL-- SELECT- u.user_id AS recipient_id,- FALSE AS is_family_plan- FROM users u- INNER JOIN usage us- ON us.user_id = u.user_id- WHERE- u.family_admin_id IS NULL- AND u.encrypted_email IS NOT NULL- AND us.storage_consumed > $1- ) candidates+ SELECT+ COALESCE(u.family_admin_id, u.user_id) AS recipient_id,+ u.family_admin_id IS NOT NULL AS is_family_plan+ FROM users u+ INNER JOIN usage us+ ON us.user_id = u.user_id+ WHERE+ us.storage_consumed > $1+ AND u.encrypted_email IS NOT NULLORDER BY recipient_id`, usageThreshold)if err != nil {diff --git a/server/pkg/repo/usage_storage_warning_test.go b/server/pkg/repo/usage_storage_warning_test.goindex 3b946726d2..e4e3c37393 100644--- a/server/pkg/repo/usage_storage_warning_test.go+++ b/server/pkg/repo/usage_storage_warning_test.go@@ -180,7 +180,7 @@ func TestGetStorageWarningCandidatesCollapsesThresholdQualifiedMembersToAdmin(t}}-func TestGetStorageWarningCandidatesIncludesFamiliesAboveThresholdByAggregateUsage(t *testing.T) {+func TestGetStorageWarningCandidatesExcludesFamilyTotalBelowPerMemberThreshold(t *testing.T) {db := getStorageWarningRepoTestDB(t)repo := &UsageRepository{DB: db}ctx := context.Background()@@ -196,43 +196,12 @@ func TestGetStorageWarningCandidatesIncludesFamiliesAboveThresholdByAggregateUsainsertStorageWarningTestUsage(t, db, memberID, 14*testGiB)insertStorageWarningTestSubscription(t, db, adminID, "photos_yearly")- candidates, err := repo.GetStorageWarningCandidates(ctx, 25*testGiB)- if err != nil {- t.Fatalf("GetStorageWarningCandidates() error = %v", err)- }- if len(candidates) != 1 {- t.Fatalf("expected aggregate family usage to select the admin, got %+v", candidates)- }- if candidates[0].RecipientID != adminID {- t.Fatalf("unexpected recipient id: got %d want %d", candidates[0].RecipientID, adminID)- }- if !candidates[0].IsFamilyPlan {- t.Fatal("expected aggregate family candidate to be marked as family plan")- }-}--func TestGetStorageWarningCandidatesExcludeFamiliesBelowAggregateThreshold(t *testing.T) {- db := getStorageWarningRepoTestDB(t)- repo := &UsageRepository{DB: db}- ctx := context.Background()-- adminID := int64(211)- memberID := int64(212)-- insertStorageWarningTestUser(t, db, adminID, &adminID)- insertStorageWarningTestUser(t, db, memberID, &adminID)- insertStorageWarningTestFamilyMember(t, db, adminID, adminID, "SELF")- insertStorageWarningTestFamilyMember(t, db, adminID, memberID, "ACCEPTED")- insertStorageWarningTestUsage(t, db, adminID, 12*testGiB)- insertStorageWarningTestUsage(t, db, memberID, 13*testGiB)- insertStorageWarningTestSubscription(t, db, adminID, "photos_yearly")-candidates, err := repo.GetStorageWarningCandidates(ctx, 25*testGiB)if err != nil {t.Fatalf("GetStorageWarningCandidates() error = %v", err)}if len(candidates) != 0 {- t.Fatalf("expected no candidates below aggregate threshold, got %+v", candidates)+ t.Fatalf("expected no candidates when no member exceeds threshold, got %+v", candidates)}}