Skip to content

Commit

Permalink
IsDeleted route returns 500 if identity is deleted (#964)
Browse files Browse the repository at this point in the history
* fix: use FirstOrDefault instead of Single when reading the identity

* chore: formatting
  • Loading branch information
tnotheis authored Dec 6, 2024
1 parent a60956b commit 24ed7a0
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 27 deletions.
32 changes: 16 additions & 16 deletions .run/SSE Server.run.xml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="SSE Server" type="LaunchSettings" factoryName=".NET Launch Settings Profile">
<option name="LAUNCH_PROFILE_PROJECT_FILE_PATH" value="$PROJECT_DIR$/Applications/SseServer/src/SseServer/SseServer.csproj"/>
<option name="LAUNCH_PROFILE_TFM" value="net8.0"/>
<option name="LAUNCH_PROFILE_NAME" value="Default"/>
<option name="USE_EXTERNAL_CONSOLE" value="0"/>
<option name="USE_MONO" value="0"/>
<option name="RUNTIME_ARGUMENTS" value=""/>
<option name="GENERATE_APPLICATIONHOST_CONFIG" value="1"/>
<option name="SHOW_IIS_EXPRESS_OUTPUT" value="0"/>
<option name="SEND_DEBUG_REQUEST" value="1"/>
<option name="ADDITIONAL_IIS_EXPRESS_ARGUMENTS" value=""/>
<method v="2">
<option name="Build"/>
</method>
</configuration>
</component>
<configuration default="false" name="SSE Server" type="LaunchSettings" factoryName=".NET Launch Settings Profile">
<option name="LAUNCH_PROFILE_PROJECT_FILE_PATH" value="$PROJECT_DIR$/Applications/SseServer/src/SseServer/SseServer.csproj" />
<option name="LAUNCH_PROFILE_TFM" value="net9.0" />
<option name="LAUNCH_PROFILE_NAME" value="Default" />
<option name="USE_EXTERNAL_CONSOLE" value="0" />
<option name="USE_MONO" value="0" />
<option name="RUNTIME_ARGUMENTS" value="" />
<option name="GENERATE_APPLICATIONHOST_CONFIG" value="1" />
<option name="SHOW_IIS_EXPRESS_OUTPUT" value="0" />
<option name="SEND_DEBUG_REQUEST" value="1" />
<option name="ADDITIONAL_IIS_EXPRESS_ARGUMENTS" value="" />
<method v="2">
<option name="Build" />
</method>
</configuration>
</component>
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,29 @@ public Handler(IIdentitiesRepository identitiesRepository)

public async Task<IsIdentityOfUserDeletedResponse> Handle(IsIdentityOfUserDeletedQuery request, CancellationToken cancellationToken)
{
var identity = await _identitiesRepository.FindSingle(Identity.HasUser(request.Username), cancellationToken);
var identity = await _identitiesRepository.FindFirst(Identity.HasUser(request.Username), cancellationToken);

if (identity.IsGracePeriodOver)
return new IsIdentityOfUserDeletedResponse(true, identity.DeletionGracePeriodEndsAt);
bool isDeleted;
DateTime? deletionGracePeriodEndsAt;

var auditLogEntries = await _identitiesRepository.GetIdentityDeletionProcessAuditLogs(
IdentityDeletionProcessAuditLogEntry.IsAssociatedToUser(Username.Parse(request.Username)),
cancellationToken);
if (identity != null)
{
isDeleted = identity.IsGracePeriodOver;
deletionGracePeriodEndsAt = identity.IsGracePeriodOver ? identity.DeletionGracePeriodEndsAt : null;
}
else
{
var auditLogEntries = await _identitiesRepository.GetIdentityDeletionProcessAuditLogs(
IdentityDeletionProcessAuditLogEntry.IsAssociatedToUser(Username.Parse(request.Username)),
cancellationToken);

var deletionCompletedAuditLogEntry = auditLogEntries.FirstOrDefault(l => l.MessageKey == MessageKey.DeletionCompleted);
var deletionCompletedAuditLogEntry = auditLogEntries.FirstOrDefault(l => l.MessageKey == MessageKey.DeletionCompleted);

isDeleted = deletionCompletedAuditLogEntry != null;
deletionGracePeriodEndsAt = deletionCompletedAuditLogEntry?.CreatedAt;
}

return new IsIdentityOfUserDeletedResponse(isDeleted, deletionGracePeriodEndsAt);

return new IsIdentityOfUserDeletedResponse(deletionCompletedAuditLogEntry != null, deletionCompletedAuditLogEntry?.CreatedAt);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public interface IIdentitiesRepository
Task<IEnumerable<Identity>> FindAllWithDeletionProcessInStatus(DeletionProcessStatus status, CancellationToken cancellationToken, bool track = false);
Task<int> CountByClientId(string clientId, CancellationToken cancellationToken);
Task<IEnumerable<Identity>> Find(Expression<Func<Identity, bool>> filter, CancellationToken cancellationToken, bool track = false);
Task<Identity> FindSingle(Expression<Func<Identity, bool>> filter, CancellationToken cancellationToken, bool track = false);
Task<Identity?> FindFirst(Expression<Func<Identity, bool>> filter, CancellationToken cancellationToken, bool track = false);
Task Delete(Expression<Func<Identity, bool>> filter, CancellationToken cancellationToken);

Task Add(Identity identity, string password);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,12 @@ public async Task<IEnumerable<Identity>> Find(Expression<Func<Identity, bool>> f
.ToListAsync(cancellationToken);
}

public async Task<Identity> FindSingle(Expression<Func<Identity, bool>> filter, CancellationToken cancellationToken, bool track = false)
public async Task<Identity?> FindFirst(Expression<Func<Identity, bool>> filter, CancellationToken cancellationToken, bool track = false)
{
return await (track ? _identities : _readonlyIdentities)
.IncludeAll(_dbContext)
.Where(filter)
.SingleAsync(cancellationToken);
.FirstOrDefaultAsync(cancellationToken);
}

public async Task Delete(Expression<Func<Identity, bool>> filter, CancellationToken cancellationToken)
Expand Down

0 comments on commit 24ed7a0

Please sign in to comment.