diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerService.java b/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerService.java index aeb517396..9570d82c9 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerService.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerService.java @@ -901,6 +901,7 @@ public class WhisperServerService extends Application dynamicConfigurationManager; + private final ExperimentEnrollmentManager experimentEnrollmentManager; private final ProfileBadgeConverter profileBadgeConverter; private final Map badgeConfigurationMap; @@ -129,26 +131,29 @@ public class ProfileController { private static final Counter VERSION_NOT_FOUND_COUNTER = Metrics.counter(name(ProfileController.class, "versionNotFound")); private static final String INVALID_ACCEPT_LANGUAGE_COUNTER_NAME = name(ProfileController.class, "invalidAcceptLanguage"); + private static final String PNP_FLAG_EXPERIMENT_NAME = "pnpCompatibilityFlag"; + public ProfileController( - Clock clock, - RateLimiters rateLimiters, - AccountsManager accountsManager, - ProfilesManager profilesManager, - DynamicConfigurationManager dynamicConfigurationManager, - ProfileBadgeConverter profileBadgeConverter, - BadgesConfiguration badgesConfiguration, - S3Client s3client, - PostPolicyGenerator policyGenerator, - PolicySigner policySigner, - String bucket, - ServerZkProfileOperations zkProfileOperations, - Executor batchIdentityCheckExecutor) { + Clock clock, + RateLimiters rateLimiters, + AccountsManager accountsManager, + ProfilesManager profilesManager, + DynamicConfigurationManager dynamicConfigurationManager, ExperimentEnrollmentManager experimentEnrollmentManager, + ProfileBadgeConverter profileBadgeConverter, + BadgesConfiguration badgesConfiguration, + S3Client s3client, + PostPolicyGenerator policyGenerator, + PolicySigner policySigner, + String bucket, + ServerZkProfileOperations zkProfileOperations, + Executor batchIdentityCheckExecutor) { this.clock = clock; this.rateLimiters = rateLimiters; this.accountsManager = accountsManager; this.profilesManager = profilesManager; this.dynamicConfigurationManager = dynamicConfigurationManager; - this.profileBadgeConverter = profileBadgeConverter; + this.experimentEnrollmentManager = experimentEnrollmentManager; + this.profileBadgeConverter = profileBadgeConverter; this.badgeConfigurationMap = badgesConfiguration.getBadges().stream().collect(Collectors.toMap( BadgeConfiguration::getId, Function.identity())); this.zkProfileOperations = zkProfileOperations; @@ -437,7 +442,8 @@ public class ProfileController { return new BaseProfileResponse(account.getIdentityKey(IdentityType.ACI), account.getUnidentifiedAccessKey().map(UnidentifiedAccessChecksum::generateFor).orElse(null), account.isUnrestrictedUnidentifiedAccess(), - UserCapabilities.createForAccount(account), + UserCapabilities.createForAccount(account, + experimentEnrollmentManager.isEnrolled(account.getIdentifier(IdentityType.ACI), PNP_FLAG_EXPERIMENT_NAME)), profileBadgeConverter.convert( getAcceptableLanguagesForRequest(containerRequestContext), account.getBadges(), @@ -449,7 +455,8 @@ public class ProfileController { return new BaseProfileResponse(account.getIdentityKey(IdentityType.PNI), null, false, - UserCapabilities.createForAccount(account), + UserCapabilities.createForAccount(account, + experimentEnrollmentManager.isEnrolled(account.getIdentifier(IdentityType.ACI), PNP_FLAG_EXPERIMENT_NAME)), Collections.emptyList(), new PniServiceIdentifier(account.getPhoneNumberIdentifier())); } diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/entities/UserCapabilities.java b/service/src/main/java/org/whispersystems/textsecuregcm/entities/UserCapabilities.java index 682d1524b..378055b61 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/entities/UserCapabilities.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/entities/UserCapabilities.java @@ -12,7 +12,7 @@ public record UserCapabilities(boolean paymentActivation, boolean pni, boolean pnp) { - public static UserCapabilities createForAccount(final Account account) { - return new UserCapabilities(account.isPaymentActivationSupported(), true, true); + public static UserCapabilities createForAccount(final Account account, final boolean includePnpFlag) { + return new UserCapabilities(account.isPaymentActivationSupported(), true, includePnpFlag); } } diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/grpc/ProfileGrpcHelper.java b/service/src/main/java/org/whispersystems/textsecuregcm/grpc/ProfileGrpcHelper.java index 4469556a2..5331e4b67 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/grpc/ProfileGrpcHelper.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/grpc/ProfileGrpcHelper.java @@ -105,7 +105,7 @@ public class ProfileGrpcHelper { final ProfileBadgeConverter profileBadgeConverter) { final GetUnversionedProfileResponse.Builder responseBuilder = GetUnversionedProfileResponse.newBuilder() .setIdentityKey(ByteString.copyFrom(targetAccount.getIdentityKey(targetIdentifier.identityType()).serialize())) - .setCapabilities(buildUserCapabilities(org.whispersystems.textsecuregcm.entities.UserCapabilities.createForAccount(targetAccount))); + .setCapabilities(buildUserCapabilities(org.whispersystems.textsecuregcm.entities.UserCapabilities.createForAccount(targetAccount, true))); switch (targetIdentifier.identityType()) { case ACI -> { diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/controllers/ProfileControllerTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/controllers/ProfileControllerTest.java index 507806228..fe263678b 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/controllers/ProfileControllerTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/controllers/ProfileControllerTest.java @@ -88,6 +88,7 @@ import org.whispersystems.textsecuregcm.entities.CreateProfileRequest; import org.whispersystems.textsecuregcm.entities.ExpiringProfileKeyCredentialProfileResponse; import org.whispersystems.textsecuregcm.entities.ProfileAvatarUploadAttributes; import org.whispersystems.textsecuregcm.entities.VersionedProfileResponse; +import org.whispersystems.textsecuregcm.experiment.ExperimentEnrollmentManager; import org.whispersystems.textsecuregcm.identity.AciServiceIdentifier; import org.whispersystems.textsecuregcm.identity.IdentityType; import org.whispersystems.textsecuregcm.identity.PniServiceIdentifier; @@ -157,6 +158,7 @@ class ProfileControllerTest { accountsManager, profilesManager, dynamicConfigurationManager, + mock(ExperimentEnrollmentManager.class), (acceptableLanguages, accountBadges, isSelf) -> List.of(new Badge("TEST", "other", "Test Badge", "This badge is in unit tests.", List.of("l", "m", "h", "x", "xx", "xxx"), "SVG", List.of(new BadgeSvg("sl", "sd"), new BadgeSvg("ml", "md"), new BadgeSvg("ll", "ld"))) ), diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/grpc/ProfileAnonymousGrpcServiceTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/grpc/ProfileAnonymousGrpcServiceTest.java index c6f0e2abf..33fe59cc7 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/grpc/ProfileAnonymousGrpcServiceTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/grpc/ProfileAnonymousGrpcServiceTest.java @@ -162,7 +162,7 @@ public class ProfileAnonymousGrpcServiceTest extends SimpleBaseGrpcTest