Don't delete or "redeem" unlimited use AllocationTokens

We haven't started dealing with timing or discounts yet, but unlimited use tokens should actually be unlimited use

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=243318266
This commit is contained in:
gbrodman 2019-04-12 13:05:06 -07:00 committed by Ben McIlwain
parent 416a39b003
commit d1e3194fce
5 changed files with 44 additions and 3 deletions

View file

@ -88,6 +88,7 @@ import google.registry.model.domain.metadata.MetadataExtension;
import google.registry.model.domain.rgp.GracePeriodStatus;
import google.registry.model.domain.secdns.SecDnsCreateExtension;
import google.registry.model.domain.token.AllocationToken;
import google.registry.model.domain.token.AllocationToken.TokenType;
import google.registry.model.domain.token.AllocationTokenExtension;
import google.registry.model.eppcommon.StatusValue;
import google.registry.model.eppinput.EppInput;
@ -354,8 +355,11 @@ public class DomainCreateFlow implements TransactionalFlow {
newDomain,
ForeignKeyIndex.create(newDomain, newDomain.getDeletionTime()),
EppResourceIndex.create(Key.create(newDomain)));
allocationToken.ifPresent(
t -> entitiesToSave.add(allocationTokenFlowUtils.redeemToken(t, Key.create(historyEntry))));
if (allocationToken.isPresent()
&& TokenType.SINGLE_USE.equals(allocationToken.get().getTokenType())) {
entitiesToSave.add(
allocationTokenFlowUtils.redeemToken(allocationToken.get(), Key.create(historyEntry)));
}
enqueueTasks(newDomain, hasSignedMarks, hasClaimsNotice);
EntityChanges entityChanges =

View file

@ -14,6 +14,7 @@
package google.registry.flows.domain.token;
import static com.google.common.base.Preconditions.checkArgument;
import static google.registry.model.ofy.ObjectifyService.ofy;
import com.google.common.collect.ImmutableMap;
@ -24,6 +25,7 @@ import google.registry.flows.EppException.AssociationProhibitsOperationException
import google.registry.flows.EppException.ParameterValueSyntaxErrorException;
import google.registry.model.domain.DomainCommand;
import google.registry.model.domain.token.AllocationToken;
import google.registry.model.domain.token.AllocationToken.TokenType;
import google.registry.model.registry.Registry;
import google.registry.model.reporting.HistoryEntry;
import java.util.List;
@ -89,9 +91,14 @@ public class AllocationTokenFlowUtils {
: checkResults;
}
/** Redeems an {@link AllocationToken}, returning the redeemed copy. */
/**
* Redeems a SINGLE_USE {@link AllocationToken}, returning the redeemed copy.
*/
public AllocationToken redeemToken(
AllocationToken token, Key<HistoryEntry> redemptionHistoryEntry) {
checkArgument(
TokenType.SINGLE_USE.equals(token.getTokenType()),
"Only SINGLE_USE tokens can be marked as redeemed");
return token.asBuilder().setRedemptionHistoryEntry(redemptionHistoryEntry).build();
}

View file

@ -17,6 +17,7 @@ package google.registry.tools;
import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static com.google.common.collect.Iterables.partition;
import static com.google.common.collect.Streams.stream;
import static google.registry.model.domain.token.AllocationToken.TokenType.SINGLE_USE;
import static google.registry.model.ofy.ObjectifyService.ofy;
import com.beust.jcommander.Parameter;
@ -93,6 +94,7 @@ final class DeleteAllocationTokensCommand extends ConfirmingCommand
ImmutableSet<AllocationToken> tokensToDelete =
ofy().load().keys(batch).values().stream()
.filter(t -> withDomains || !t.getDomainName().isPresent())
.filter(t -> SINGLE_USE.equals(t.getTokenType()))
.filter(t -> !t.isRedeemed())
.collect(toImmutableSet());
if (!dryRun) {