diff --git a/.run/SSE Server.run.xml b/.run/SSE Server.run.xml index de915ad00d..d0e1fcdab8 100644 --- a/.run/SSE Server.run.xml +++ b/.run/SSE Server.run.xml @@ -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> \ No newline at end of file diff --git a/Modules/Devices/src/Devices.Application/Identities/Queries/IsIdentityOfUserDeleted/Handler.cs b/Modules/Devices/src/Devices.Application/Identities/Queries/IsIdentityOfUserDeleted/Handler.cs index 1b667b4b19..37be9ea8b0 100644 --- a/Modules/Devices/src/Devices.Application/Identities/Queries/IsIdentityOfUserDeleted/Handler.cs +++ b/Modules/Devices/src/Devices.Application/Identities/Queries/IsIdentityOfUserDeleted/Handler.cs @@ -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); } } diff --git a/Modules/Devices/src/Devices.Application/Infrastructure/Persistence/Repository/IIdentitiesRepository.cs b/Modules/Devices/src/Devices.Application/Infrastructure/Persistence/Repository/IIdentitiesRepository.cs index f199f44993..7a93b6813a 100644 --- a/Modules/Devices/src/Devices.Application/Infrastructure/Persistence/Repository/IIdentitiesRepository.cs +++ b/Modules/Devices/src/Devices.Application/Infrastructure/Persistence/Repository/IIdentitiesRepository.cs @@ -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); diff --git a/Modules/Devices/src/Devices.Infrastructure/Persistence/Repository/IdentitiesRepository.cs b/Modules/Devices/src/Devices.Infrastructure/Persistence/Repository/IdentitiesRepository.cs index 28e6f51130..33255da85a 100644 --- a/Modules/Devices/src/Devices.Infrastructure/Persistence/Repository/IdentitiesRepository.cs +++ b/Modules/Devices/src/Devices.Infrastructure/Persistence/Repository/IdentitiesRepository.cs @@ -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)