Support device transfers (SERVER-41, SERVER-42) (#32)

This change introduces a `transfer` device capability and account creation argument in support of the iOS device transfer effort.
This commit is contained in:
Jon Chambers
2020-05-12 12:23:18 -04:00
committed by GitHub
parent 4cea9023f2
commit 001a9310c3
7 changed files with 133 additions and 12 deletions

View File

@@ -254,6 +254,7 @@ public class AccountController {
public AccountCreationResult verifyAccount(@PathParam("verification_code") String verificationCode,
@HeaderParam("Authorization") String authorizationHeader,
@HeaderParam("X-Signal-Agent") String userAgent,
@QueryParam("transfer") Optional<Boolean> availableForTransfer,
@Valid AccountAttributes accountAttributes)
throws RateLimitExceededException
{
@@ -296,6 +297,10 @@ public class AccountController {
rateLimiters.getPinLimiter().clear(number);
}
if (availableForTransfer.orElse(false) && existingAccount.map(Account::isTransferSupported).orElse(false)) {
throw new WebApplicationException(Response.status(409).build());
}
Account account = createAccount(number, password, userAgent, accountAttributes);
metricRegistry.meter(name(AccountController.class, "verify", Util.getCountryCode(number))).mark();

View File

@@ -150,6 +150,10 @@ public class Account implements Principal {
return devices.stream().anyMatch(device -> device.getCapabilities() != null && device.getCapabilities().isStorage());
}
public boolean isTransferSupported() {
return getMasterDevice().map(Device::getCapabilities).map(Device.DeviceCapabilities::isTransfer).orElse(false);
}
public boolean isEnabled() {
return
getMasterDevice().isPresent() &&

View File

@@ -276,12 +276,16 @@ public class Device {
@JsonProperty
private boolean storage;
@JsonProperty
private boolean transfer;
public DeviceCapabilities() {}
public DeviceCapabilities(boolean uuid, boolean gv2, boolean storage) {
this.uuid = uuid;
this.gv2 = gv2;
this.storage = storage;
public DeviceCapabilities(boolean uuid, boolean gv2, boolean storage, boolean transfer) {
this.uuid = uuid;
this.gv2 = gv2;
this.storage = storage;
this.transfer = transfer;
}
public boolean isUuid() {
@@ -295,6 +299,10 @@ public class Device {
public boolean isStorage() {
return storage;
}
public boolean isTransfer() {
return transfer;
}
}
}