1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-02 00:22:50 -05:00

Enable Nullable In Auth Repositories (#4600)

This commit is contained in:
Justin Baur
2024-08-09 09:31:06 -04:00
committed by GitHub
parent 374ef95656
commit 56d6c91b25
25 changed files with 76 additions and 30 deletions

View File

@ -8,6 +8,8 @@ using Bit.Infrastructure.EntityFramework.Repositories;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
#nullable enable
namespace Bit.Infrastructure.EntityFramework.Auth.Repositories;
public class AuthRequestRepository : Repository<Core.Auth.Entities.AuthRequest, AuthRequest, Guid>, IAuthRequestRepository
@ -25,7 +27,7 @@ public class AuthRequestRepository : Repository<Core.Auth.Entities.AuthRequest,
var expiredRequests = await dbContext.AuthRequests
.Where(a => (a.Type != AuthRequestType.AdminApproval && a.CreationDate.AddSeconds(userRequestExpiration.TotalSeconds) < DateTime.UtcNow)
|| (a.Type == AuthRequestType.AdminApproval && a.Approved != true && a.CreationDate.AddSeconds(adminRequestExpiration.TotalSeconds) < DateTime.UtcNow)
|| (a.Type == AuthRequestType.AdminApproval && a.Approved == true && a.ResponseDate.Value.AddSeconds(afterAdminApprovalExpiration.TotalSeconds) < DateTime.UtcNow))
|| (a.Type == AuthRequestType.AdminApproval && a.Approved == true && a.ResponseDate!.Value.AddSeconds(afterAdminApprovalExpiration.TotalSeconds) < DateTime.UtcNow))
.ToListAsync();
dbContext.AuthRequests.RemoveRange(expiredRequests);
return await dbContext.SaveChangesAsync();

View File

@ -10,6 +10,8 @@ using Microsoft.Data.SqlClient;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
#nullable enable
namespace Bit.Infrastructure.EntityFramework.Auth.Repositories;
public class EmergencyAccessRepository : Repository<Core.Auth.Entities.EmergencyAccess, EmergencyAccess, Guid>, IEmergencyAccessRepository
@ -35,7 +37,7 @@ public class EmergencyAccessRepository : Repository<Core.Auth.Entities.Emergency
await base.DeleteAsync(emergencyAccess);
}
public async Task<EmergencyAccessDetails> GetDetailsByIdGrantorIdAsync(Guid id, Guid grantorId)
public async Task<EmergencyAccessDetails?> GetDetailsByIdGrantorIdAsync(Guid id, Guid grantorId)
{
using (var scope = ServiceScopeFactory.CreateScope())
{

View File

@ -6,6 +6,8 @@ using Bit.Infrastructure.EntityFramework.Repositories;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
#nullable enable
namespace Bit.Infrastructure.EntityFramework.Auth.Repositories;
public class GrantRepository : BaseEntityFrameworkRepository, IGrantRepository
@ -36,7 +38,7 @@ public class GrantRepository : BaseEntityFrameworkRepository, IGrantRepository
}
}
public async Task<IGrant> GetByKeyAsync(string key)
public async Task<IGrant?> GetByKeyAsync(string key)
{
using (var scope = ServiceScopeFactory.CreateScope())
{
@ -92,4 +94,3 @@ public class GrantRepository : BaseEntityFrameworkRepository, IGrantRepository
}
}
}

View File

@ -2,6 +2,8 @@
using Bit.Infrastructure.EntityFramework.Repositories;
using Bit.Infrastructure.EntityFramework.Repositories.Queries;
#nullable enable
namespace Bit.Infrastructure.EntityFramework.Auth.Repositories.Queries;
public class EmergencyAccessDetailsViewQuery : IQuery<EmergencyAccessDetails>

View File

@ -2,6 +2,8 @@
using Bit.Infrastructure.EntityFramework.Repositories;
using Bit.Infrastructure.EntityFramework.Repositories.Queries;
#nullable enable
namespace Bit.Infrastructure.EntityFramework.Auth.Repositories.Queries;
public class EmergencyAccessReadCountByGrantorIdEmailQuery : IQuery<EmergencyAccess>

View File

@ -4,6 +4,8 @@ using Bit.Infrastructure.EntityFramework.Auth.Models;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
#nullable enable
namespace Bit.Infrastructure.EntityFramework.Repositories;
public class SsoConfigRepository : Repository<Core.Auth.Entities.SsoConfig, SsoConfig, long>, ISsoConfigRepository
@ -12,7 +14,7 @@ public class SsoConfigRepository : Repository<Core.Auth.Entities.SsoConfig, SsoC
: base(serviceScopeFactory, mapper, (DatabaseContext context) => context.SsoConfigs)
{ }
public async Task<Core.Auth.Entities.SsoConfig> GetByOrganizationIdAsync(Guid organizationId)
public async Task<Core.Auth.Entities.SsoConfig?> GetByOrganizationIdAsync(Guid organizationId)
{
using (var scope = ServiceScopeFactory.CreateScope())
{
@ -22,7 +24,7 @@ public class SsoConfigRepository : Repository<Core.Auth.Entities.SsoConfig, SsoC
}
}
public async Task<Core.Auth.Entities.SsoConfig> GetByIdentifierAsync(string identifier)
public async Task<Core.Auth.Entities.SsoConfig?> GetByIdentifierAsync(string identifier)
{
using (var scope = ServiceScopeFactory.CreateScope())

View File

@ -4,6 +4,8 @@ using Bit.Infrastructure.EntityFramework.Auth.Models;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
#nullable enable
namespace Bit.Infrastructure.EntityFramework.Repositories;
public class SsoUserRepository : Repository<Core.Auth.Entities.SsoUser, SsoUser, long>, ISsoUserRepository
@ -17,13 +19,13 @@ public class SsoUserRepository : Repository<Core.Auth.Entities.SsoUser, SsoUser,
using (var scope = ServiceScopeFactory.CreateScope())
{
var dbContext = GetDatabaseContext(scope);
var entity = await GetDbSet(dbContext).SingleOrDefaultAsync(su => su.UserId == userId && su.OrganizationId == organizationId);
dbContext.Entry(entity).State = EntityState.Deleted;
await dbContext.SaveChangesAsync();
await dbContext.SsoUsers
.Where(su => su.UserId == userId && su.OrganizationId == organizationId)
.ExecuteDeleteAsync();
}
}
public async Task<Core.Auth.Entities.SsoUser> GetByUserIdOrganizationIdAsync(Guid organizationId, Guid userId)
public async Task<Core.Auth.Entities.SsoUser?> GetByUserIdOrganizationIdAsync(Guid organizationId, Guid userId)
{
using (var scope = ServiceScopeFactory.CreateScope())
{

View File

@ -7,6 +7,8 @@ using Bit.Infrastructure.EntityFramework.Repositories;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
#nullable enable
namespace Bit.Infrastructure.EntityFramework.Auth.Repositories;
public class WebAuthnCredentialRepository : Repository<Core.Auth.Entities.WebAuthnCredential, WebAuthnCredential, Guid>, IWebAuthnCredentialRepository
@ -15,7 +17,7 @@ public class WebAuthnCredentialRepository : Repository<Core.Auth.Entities.WebAut
: base(serviceScopeFactory, mapper, (context) => context.WebAuthnCredentials)
{ }
public async Task<Core.Auth.Entities.WebAuthnCredential> GetByIdAsync(Guid id, Guid userId)
public async Task<Core.Auth.Entities.WebAuthnCredential?> GetByIdAsync(Guid id, Guid userId)
{
using (var scope = ServiceScopeFactory.CreateScope())
{