Send acceptable languages instead of request into the profile badge converter
This commit is contained in:
parent
81a21c0d5f
commit
bd40e32f3b
|
@ -294,7 +294,7 @@ public class WhisperServerService extends Application<WhisperServerConfiguration
|
|||
environment.getObjectMapper().setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.NONE);
|
||||
environment.getObjectMapper().setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
|
||||
|
||||
ProfileBadgeConverter profileBadgeConverter = (request, accountBadges) -> Set.of(); // TODO: Provide an actual implementation.
|
||||
ProfileBadgeConverter profileBadgeConverter = (acceptableLanguages, accountBadges) -> Set.of(); // TODO: Provide an actual implementation.
|
||||
|
||||
JdbiFactory jdbiFactory = new JdbiFactory(DefaultNameStrategy.CHECK_EMPTY);
|
||||
Jdbi accountJdbi = jdbiFactory.build(environment, config.getAccountsDatabaseConfiguration(), "accountdb");
|
||||
|
|
|
@ -5,8 +5,9 @@
|
|||
|
||||
package org.whispersystems.textsecuregcm.badges;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import javax.ws.rs.core.Request;
|
||||
import org.whispersystems.textsecuregcm.entities.Badge;
|
||||
import org.whispersystems.textsecuregcm.storage.AccountBadge;
|
||||
|
||||
|
@ -14,9 +15,7 @@ public interface ProfileBadgeConverter {
|
|||
|
||||
/**
|
||||
* Converts the {@link AccountBadge}s for an account into the objects
|
||||
* that can be returned on a profile fetch. This requires returning
|
||||
* localized strings given the user's locale which will be retrieved from
|
||||
* the {@link Request} object passed in.
|
||||
* that can be returned on a profile fetch.
|
||||
*/
|
||||
Set<Badge> convert(Request request, Set<AccountBadge> accountBadges);
|
||||
Set<Badge> convert(List<Locale> acceptableLanguages, Set<AccountBadge> accountBadges);
|
||||
}
|
||||
|
|
|
@ -10,6 +10,8 @@ import io.dropwizard.auth.Auth;
|
|||
import java.security.SecureRandom;
|
||||
import java.time.ZoneOffset;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
@ -24,15 +26,17 @@ import javax.ws.rs.PathParam;
|
|||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.WebApplicationException;
|
||||
import javax.ws.rs.container.ContainerRequestContext;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Request;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.Response.Status;
|
||||
import org.apache.commons.codec.DecoderException;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.apache.commons.codec.binary.Hex;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.glassfish.jersey.message.internal.AcceptableLanguageTag;
|
||||
import org.glassfish.jersey.message.internal.InboundMessageContext;
|
||||
import org.signal.zkgroup.InvalidInputException;
|
||||
import org.signal.zkgroup.VerificationFailedException;
|
||||
import org.signal.zkgroup.profiles.ProfileKeyCommitment;
|
||||
|
@ -183,14 +187,14 @@ public class ProfileController {
|
|||
public Optional<Profile> getProfile(
|
||||
@Auth Optional<AuthenticatedAccount> auth,
|
||||
@HeaderParam(OptionalAccess.UNIDENTIFIED) Optional<Anonymous> accessKey,
|
||||
@Context Request request,
|
||||
@Context ContainerRequestContext containerRequestContext,
|
||||
@PathParam("uuid") UUID uuid,
|
||||
@PathParam("version") String version)
|
||||
throws RateLimitExceededException {
|
||||
if (!isZkEnabled) {
|
||||
throw new WebApplicationException(Response.Status.NOT_FOUND);
|
||||
}
|
||||
return getVersionedProfile(auth.map(AuthenticatedAccount::getAccount), accessKey, request, uuid, version, Optional.empty());
|
||||
return getVersionedProfile(auth.map(AuthenticatedAccount::getAccount), accessKey, containerRequestContext.getAcceptableLanguages(), uuid, version, Optional.empty());
|
||||
}
|
||||
|
||||
@Timed
|
||||
|
@ -200,7 +204,7 @@ public class ProfileController {
|
|||
public Optional<Profile> getProfile(
|
||||
@Auth Optional<AuthenticatedAccount> auth,
|
||||
@HeaderParam(OptionalAccess.UNIDENTIFIED) Optional<Anonymous> accessKey,
|
||||
@Context Request request,
|
||||
@Context ContainerRequestContext containerRequestContext,
|
||||
@PathParam("uuid") UUID uuid,
|
||||
@PathParam("version") String version,
|
||||
@PathParam("credentialRequest") String credentialRequest)
|
||||
|
@ -208,13 +212,13 @@ public class ProfileController {
|
|||
if (!isZkEnabled) {
|
||||
throw new WebApplicationException(Response.Status.NOT_FOUND);
|
||||
}
|
||||
return getVersionedProfile(auth.map(AuthenticatedAccount::getAccount), accessKey, request, uuid, version, Optional.of(credentialRequest));
|
||||
return getVersionedProfile(auth.map(AuthenticatedAccount::getAccount), accessKey, containerRequestContext.getAcceptableLanguages(), uuid, version, Optional.of(credentialRequest));
|
||||
}
|
||||
|
||||
private Optional<Profile> getVersionedProfile(
|
||||
Optional<Account> requestAccount,
|
||||
Optional<Anonymous> accessKey,
|
||||
Request request,
|
||||
List<Locale> acceptableLanguages,
|
||||
UUID uuid,
|
||||
String version,
|
||||
Optional<String> credentialRequest)
|
||||
|
@ -265,7 +269,7 @@ public class ProfileController {
|
|||
UserCapabilities.createForAccount(accountProfile.get()),
|
||||
username.orElse(null),
|
||||
null,
|
||||
profileBadgeConverter.convert(request, accountProfile.get().getBadges()),
|
||||
profileBadgeConverter.convert(acceptableLanguages, accountProfile.get().getBadges()),
|
||||
credential.orElse(null)));
|
||||
} catch (InvalidInputException e) {
|
||||
logger.info("Bad profile request", e);
|
||||
|
|
|
@ -96,7 +96,7 @@ class ProfileControllerTest {
|
|||
profilesManager,
|
||||
usernamesManager,
|
||||
dynamicConfigurationManager,
|
||||
(request, accountBadges) -> Set.of(), // TODO: Test with some badges.
|
||||
(acceptableLanguages, accountBadges) -> Set.of(), // TODO: Test with some badges.
|
||||
s3client,
|
||||
postPolicyGenerator,
|
||||
policySigner,
|
||||
|
|
Loading…
Reference in New Issue