Fixed bug in user deletion where compare/exchange value wasn't deleted.

This commit is contained in:
Judah Himango CW
2019-04-01 11:22:30 -05:00
parent cae73f5627
commit 82d6bd562a
2 changed files with 16 additions and 8 deletions
+2 -2
View File
@@ -19,10 +19,10 @@
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute> <GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute> <GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute> <GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
<Version>6.0.1</Version> <Version>6.0.2</Version>
<GeneratePackageOnBuild>False</GeneratePackageOnBuild> <GeneratePackageOnBuild>False</GeneratePackageOnBuild>
<RootNamespace>Raven.Identity</RootNamespace> <RootNamespace>Raven.Identity</RootNamespace>
<PackageReleaseNotes>Compare/exchange to enforce unique emails cluster-wide, storing with email address as the key.</PackageReleaseNotes> <PackageReleaseNotes>Fixed user deletion that failed to delete compare/exchange key.</PackageReleaseNotes>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
+14 -6
View File
@@ -192,11 +192,6 @@ namespace Raven.Identity
ThrowIfNullDisposedCancelled(user, cancellationToken); ThrowIfNullDisposedCancelled(user, cancellationToken);
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();
// Delete the user and save it. We must save it because deleting is a cluster-wide operation.
// Only if the deletion succeeds will we remove the cluseter-wide compare/exchange key.
this.DbSession.Delete(user);
await this.DbSession.SaveChangesAsync();
// Remove the cluster-wide compare/exchange key. // Remove the cluster-wide compare/exchange key.
var deletionResult = await DeleteUserEmailReservation(user.Email); var deletionResult = await DeleteUserEmailReservation(user.Email);
if (!deletionResult.Successful) if (!deletionResult.Successful)
@@ -211,6 +206,11 @@ namespace Raven.Identity
}); });
} }
// Delete the user and save it. We must save it because deleting is a cluster-wide operation.
// Only if the deletion succeeds will we remove the cluseter-wide compare/exchange key.
this.DbSession.Delete(user);
await this.DbSession.SaveChangesAsync();
return IdentityResult.Success; return IdentityResult.Success;
} }
@@ -874,7 +874,15 @@ namespace Raven.Identity
private Task<CompareExchangeResult<string>> DeleteUserEmailReservation(string email) private Task<CompareExchangeResult<string>> DeleteUserEmailReservation(string email)
{ {
var key = GetCompareExchangeKeyFromEmail(email); var key = GetCompareExchangeKeyFromEmail(email);
var deleteEmailOperation = new DeleteCompareExchangeValueOperation<string>(key, 0); var store = DbSession.Advanced.DocumentStore;
var readResult = store.Operations.Send(new GetCompareExchangeValueOperation<string>(key));
if (readResult == null)
{
return Task.FromResult(new CompareExchangeResult<string>() { Successful = false });
}
var deleteEmailOperation = new DeleteCompareExchangeValueOperation<string>(key, readResult.Index);
return DbSession.Advanced.DocumentStore.Operations.SendAsync(deleteEmailOperation); return DbSession.Advanced.DocumentStore.Operations.SendAsync(deleteEmailOperation);
} }