From fc6075f19ca9fe0543d41c6a3ecf5d79532c3951 Mon Sep 17 00:00:00 2001 From: Ravi Khadiwala Date: Thu, 7 Nov 2024 13:09:40 -0600 Subject: [PATCH] Include media TTL in backup config --- .../configuration/SubscriptionLevelConfiguration.java | 2 ++ .../controllers/SubscriptionController.java | 9 +++++++-- .../controllers/SubscriptionControllerTest.java | 2 ++ service/src/test/resources/config/test.yml | 1 + 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/configuration/SubscriptionLevelConfiguration.java b/service/src/main/java/org/whispersystems/textsecuregcm/configuration/SubscriptionLevelConfiguration.java index bc89a0828..f8aab68a8 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/configuration/SubscriptionLevelConfiguration.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/configuration/SubscriptionLevelConfiguration.java @@ -6,6 +6,7 @@ package org.whispersystems.textsecuregcm.configuration; import com.fasterxml.jackson.annotation.JsonProperty; +import java.time.Duration; import java.util.Map; import javax.validation.Valid; import javax.validation.constraints.NotEmpty; @@ -30,6 +31,7 @@ public sealed interface SubscriptionLevelConfiguration permits record Backup( @JsonProperty("playProductId") @NotEmpty String playProductId, + @JsonProperty("mediaTtl") @NotNull Duration mediaTtl, @JsonProperty("prices") @Valid Map<@NotEmpty String, @NotNull @Valid SubscriptionPriceConfiguration> prices) implements SubscriptionLevelConfiguration {} diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/controllers/SubscriptionController.java b/service/src/main/java/org/whispersystems/textsecuregcm/controllers/SubscriptionController.java index ee4e1900f..76bea791e 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/controllers/SubscriptionController.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/controllers/SubscriptionController.java @@ -206,7 +206,10 @@ public class SubscriptionController { .entrySet().stream() .collect(Collectors.toMap( e -> String.valueOf(e.getKey()), - e -> new BackupLevelConfiguration(BackupManager.MAX_TOTAL_BACKUP_MEDIA_BYTES, e.getValue().playProductId()))); + e -> new BackupLevelConfiguration( + BackupManager.MAX_TOTAL_BACKUP_MEDIA_BYTES, + e.getValue().playProductId(), + e.getValue().mediaTtl().toDays()))); return new GetSubscriptionConfigurationResponse(buildCurrencyConfiguration(), donationLevels, new BackupConfiguration(backupLevels, subscriptionConfiguration.getbackupFreeTierMediaDuration().toDays()), @@ -517,7 +520,9 @@ public class SubscriptionController { @Schema(description = "The amount of media storage in bytes that a paying subscriber may store") long storageAllowanceBytes, @Schema(description = "The play billing productID associated with this backup level") - String playProductId) {} + String playProductId, + @Schema(description = "The duration, in days, for which your backed up media is retained on the server after you stop refreshing with a paid credential") + long mediaTtlDays) {} @GET @Path("/configuration") diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/controllers/SubscriptionControllerTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/controllers/SubscriptionControllerTest.java index d0d01ed36..512a3b356 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/controllers/SubscriptionControllerTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/controllers/SubscriptionControllerTest.java @@ -1189,6 +1189,7 @@ class SubscriptionControllerTest { assertThat(response.backup().levels()).containsOnlyKeys("201").extractingByKey("201").satisfies(configuration -> { assertThat(configuration.storageAllowanceBytes()).isEqualTo(BackupManager.MAX_TOTAL_BACKUP_MEDIA_BYTES); assertThat(configuration.playProductId()).isEqualTo("testPlayProductId"); + assertThat(configuration.mediaTtlDays()).isEqualTo(40); }); assertThat(response.backup().freeTierMediaDays()).isEqualTo(30); @@ -1244,6 +1245,7 @@ class SubscriptionControllerTest { backupLevels: 201: playProductId: testPlayProductId + mediaTtl: P40D prices: usd: amount: '5' diff --git a/service/src/test/resources/config/test.yml b/service/src/test/resources/config/test.yml index 8f381e250..242ca490b 100644 --- a/service/src/test/resources/config/test.yml +++ b/service/src/test/resources/config/test.yml @@ -370,6 +370,7 @@ subscription: # configuration for Stripe subscriptions backupLevels: 201: playProductId: EXAMPLE + mediaTtl: P30D prices: {} levels: 500: