mirror of
https://github.com/bitwarden/server.git
synced 2025-07-04 09:32:48 -05:00
[PM-2943] Enable Nullable Repositories in Unowned Files (#4549)
* Enable Nullable In Unowned Repos * Update More Tests * Move to One If * Fix Collections * Format * Add Migrations * Move Pragma Annotation * Add Better Assert Message
This commit is contained in:
@ -1,5 +1,7 @@
|
||||
using Dapper;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace Bit.Infrastructure.Dapper.Repositories;
|
||||
|
||||
public abstract class BaseRepository
|
||||
|
@ -5,6 +5,8 @@ using Bit.Core.Settings;
|
||||
using Dapper;
|
||||
using Microsoft.Data.SqlClient;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace Bit.Infrastructure.Dapper.Repositories;
|
||||
|
||||
public class CollectionCipherRepository : BaseRepository, ICollectionCipherRepository
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System.Data;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json;
|
||||
using Bit.Core.Entities;
|
||||
using Bit.Core.Models.Data;
|
||||
@ -7,6 +8,8 @@ using Bit.Core.Settings;
|
||||
using Dapper;
|
||||
using Microsoft.Data.SqlClient;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace Bit.Infrastructure.Dapper.Repositories;
|
||||
|
||||
public class CollectionRepository : Repository<Collection, Guid>, ICollectionRepository
|
||||
@ -32,7 +35,7 @@ public class CollectionRepository : Repository<Collection, Guid>, ICollectionRep
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<Tuple<Collection, CollectionAccessDetails>> GetByIdWithAccessAsync(Guid id)
|
||||
public async Task<Tuple<Collection?, CollectionAccessDetails>> GetByIdWithAccessAsync(Guid id)
|
||||
{
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
@ -46,7 +49,7 @@ public class CollectionRepository : Repository<Collection, Guid>, ICollectionRep
|
||||
var users = (await results.ReadAsync<CollectionAccessSelection>()).ToList();
|
||||
var access = new CollectionAccessDetails { Groups = groups, Users = users };
|
||||
|
||||
return new Tuple<Collection, CollectionAccessDetails>(collection, access);
|
||||
return new Tuple<Collection?, CollectionAccessDetails>(collection, access);
|
||||
}
|
||||
}
|
||||
|
||||
@ -182,7 +185,7 @@ public class CollectionRepository : Repository<Collection, Guid>, ICollectionRep
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<CollectionAdminDetails> GetByIdWithPermissionsAsync(Guid collectionId, Guid? userId, bool includeAccessRelationships)
|
||||
public async Task<CollectionAdminDetails?> GetByIdWithPermissionsAsync(Guid collectionId, Guid? userId, bool includeAccessRelationships)
|
||||
{
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
@ -195,17 +198,18 @@ public class CollectionRepository : Repository<Collection, Guid>, ICollectionRep
|
||||
|
||||
if (!includeAccessRelationships || collectionDetails == null) return collectionDetails;
|
||||
|
||||
collectionDetails.Groups = (await results.ReadAsync<CollectionAccessSelection>()).ToList();
|
||||
// TODO-NRE: collectionDetails should be checked for null and probably return early
|
||||
collectionDetails!.Groups = (await results.ReadAsync<CollectionAccessSelection>()).ToList();
|
||||
collectionDetails.Users = (await results.ReadAsync<CollectionAccessSelection>()).ToList();
|
||||
|
||||
return collectionDetails;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task CreateAsync(Collection obj, IEnumerable<CollectionAccessSelection> groups, IEnumerable<CollectionAccessSelection> users)
|
||||
public async Task CreateAsync(Collection obj, IEnumerable<CollectionAccessSelection>? groups, IEnumerable<CollectionAccessSelection>? users)
|
||||
{
|
||||
obj.SetNewId();
|
||||
var objWithGroupsAndUsers = JsonSerializer.Deserialize<CollectionWithGroupsAndUsers>(JsonSerializer.Serialize(obj));
|
||||
var objWithGroupsAndUsers = JsonSerializer.Deserialize<CollectionWithGroupsAndUsers>(JsonSerializer.Serialize(obj))!;
|
||||
|
||||
objWithGroupsAndUsers.Groups = groups != null ? groups.ToArrayTVP() : Enumerable.Empty<CollectionAccessSelection>().ToArrayTVP();
|
||||
objWithGroupsAndUsers.Users = users != null ? users.ToArrayTVP() : Enumerable.Empty<CollectionAccessSelection>().ToArrayTVP();
|
||||
@ -219,9 +223,9 @@ public class CollectionRepository : Repository<Collection, Guid>, ICollectionRep
|
||||
}
|
||||
}
|
||||
|
||||
public async Task ReplaceAsync(Collection obj, IEnumerable<CollectionAccessSelection> groups, IEnumerable<CollectionAccessSelection> users)
|
||||
public async Task ReplaceAsync(Collection obj, IEnumerable<CollectionAccessSelection>? groups, IEnumerable<CollectionAccessSelection>? users)
|
||||
{
|
||||
var objWithGroupsAndUsers = JsonSerializer.Deserialize<CollectionWithGroupsAndUsers>(JsonSerializer.Serialize(obj));
|
||||
var objWithGroupsAndUsers = JsonSerializer.Deserialize<CollectionWithGroupsAndUsers>(JsonSerializer.Serialize(obj))!;
|
||||
|
||||
objWithGroupsAndUsers.Groups = groups != null ? groups.ToArrayTVP() : Enumerable.Empty<CollectionAccessSelection>().ToArrayTVP();
|
||||
objWithGroupsAndUsers.Users = users != null ? users.ToArrayTVP() : Enumerable.Empty<CollectionAccessSelection>().ToArrayTVP();
|
||||
@ -307,7 +311,9 @@ public class CollectionRepository : Repository<Collection, Guid>, ICollectionRep
|
||||
|
||||
public class CollectionWithGroupsAndUsers : Collection
|
||||
{
|
||||
public DataTable Groups { get; set; }
|
||||
public DataTable Users { get; set; }
|
||||
[DisallowNull]
|
||||
public DataTable? Groups { get; set; }
|
||||
[DisallowNull]
|
||||
public DataTable? Users { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
using System.Data;
|
||||
using Dapper;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace Bit.Infrastructure.Dapper.Repositories;
|
||||
|
||||
public class DateTimeHandler : SqlMapper.TypeHandler<DateTime>
|
||||
|
@ -5,6 +5,8 @@ using Bit.Core.Settings;
|
||||
using Dapper;
|
||||
using Microsoft.Data.SqlClient;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace Bit.Infrastructure.Dapper.Repositories;
|
||||
|
||||
public class DeviceRepository : Repository<Device, Guid>, IDeviceRepository
|
||||
@ -17,7 +19,7 @@ public class DeviceRepository : Repository<Device, Guid>, IDeviceRepository
|
||||
: base(connectionString, readOnlyConnectionString)
|
||||
{ }
|
||||
|
||||
public async Task<Device> GetByIdAsync(Guid id, Guid userId)
|
||||
public async Task<Device?> GetByIdAsync(Guid id, Guid userId)
|
||||
{
|
||||
var device = await GetByIdAsync(id);
|
||||
if (device == null || device.UserId != userId)
|
||||
@ -28,7 +30,7 @@ public class DeviceRepository : Repository<Device, Guid>, IDeviceRepository
|
||||
return device;
|
||||
}
|
||||
|
||||
public async Task<Device> GetByIdentifierAsync(string identifier)
|
||||
public async Task<Device?> GetByIdentifierAsync(string identifier)
|
||||
{
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
@ -44,7 +46,7 @@ public class DeviceRepository : Repository<Device, Guid>, IDeviceRepository
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<Device> GetByIdentifierAsync(string identifier, Guid userId)
|
||||
public async Task<Device?> GetByIdentifierAsync(string identifier, Guid userId)
|
||||
{
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
|
@ -7,6 +7,8 @@ using Bit.Core.Vault.Entities;
|
||||
using Dapper;
|
||||
using Microsoft.Data.SqlClient;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace Bit.Infrastructure.Dapper.Repositories;
|
||||
|
||||
public class EventRepository : Repository<Event, Guid>, IEventRepository
|
||||
@ -23,7 +25,7 @@ public class EventRepository : Repository<Event, Guid>, IEventRepository
|
||||
PageOptions pageOptions)
|
||||
{
|
||||
return await GetManyAsync($"[{Schema}].[Event_ReadPageByUserId]",
|
||||
new Dictionary<string, object>
|
||||
new Dictionary<string, object?>
|
||||
{
|
||||
["@UserId"] = userId
|
||||
}, startDate, endDate, pageOptions);
|
||||
@ -33,7 +35,7 @@ public class EventRepository : Repository<Event, Guid>, IEventRepository
|
||||
DateTime startDate, DateTime endDate, PageOptions pageOptions)
|
||||
{
|
||||
return await GetManyAsync($"[{Schema}].[Event_ReadPageByOrganizationId]",
|
||||
new Dictionary<string, object>
|
||||
new Dictionary<string, object?>
|
||||
{
|
||||
["@OrganizationId"] = organizationId
|
||||
}, startDate, endDate, pageOptions);
|
||||
@ -43,7 +45,7 @@ public class EventRepository : Repository<Event, Guid>, IEventRepository
|
||||
DateTime startDate, DateTime endDate, PageOptions pageOptions)
|
||||
{
|
||||
return await GetManyAsync($"[{Schema}].[Event_ReadPageByOrganizationIdActingUserId]",
|
||||
new Dictionary<string, object>
|
||||
new Dictionary<string, object?>
|
||||
{
|
||||
["@OrganizationId"] = organizationId,
|
||||
["@ActingUserId"] = actingUserId
|
||||
@ -54,7 +56,7 @@ public class EventRepository : Repository<Event, Guid>, IEventRepository
|
||||
DateTime startDate, DateTime endDate, PageOptions pageOptions)
|
||||
{
|
||||
return await GetManyAsync($"[{Schema}].[Event_ReadPageByProviderId]",
|
||||
new Dictionary<string, object>
|
||||
new Dictionary<string, object?>
|
||||
{
|
||||
["@ProviderId"] = providerId
|
||||
}, startDate, endDate, pageOptions);
|
||||
@ -64,7 +66,7 @@ public class EventRepository : Repository<Event, Guid>, IEventRepository
|
||||
DateTime startDate, DateTime endDate, PageOptions pageOptions)
|
||||
{
|
||||
return await GetManyAsync($"[{Schema}].[Event_ReadPageByProviderIdActingUserId]",
|
||||
new Dictionary<string, object>
|
||||
new Dictionary<string, object?>
|
||||
{
|
||||
["@ProviderId"] = providerId,
|
||||
["@ActingUserId"] = actingUserId
|
||||
@ -75,7 +77,7 @@ public class EventRepository : Repository<Event, Guid>, IEventRepository
|
||||
PageOptions pageOptions)
|
||||
{
|
||||
return await GetManyAsync($"[{Schema}].[Event_ReadPageByCipherId]",
|
||||
new Dictionary<string, object>
|
||||
new Dictionary<string, object?>
|
||||
{
|
||||
["@OrganizationId"] = cipher.OrganizationId,
|
||||
["@UserId"] = cipher.UserId,
|
||||
@ -93,9 +95,9 @@ public class EventRepository : Repository<Event, Guid>, IEventRepository
|
||||
await base.CreateAsync(ev);
|
||||
}
|
||||
|
||||
public async Task CreateManyAsync(IEnumerable<IEvent> entities)
|
||||
public async Task CreateManyAsync(IEnumerable<IEvent>? entities)
|
||||
{
|
||||
if (!entities?.Any() ?? true)
|
||||
if (entities is null || !entities.Any())
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -112,7 +114,7 @@ public class EventRepository : Repository<Event, Guid>, IEventRepository
|
||||
using (var bulkCopy = new SqlBulkCopy(connection, SqlBulkCopyOptions.KeepIdentity, null))
|
||||
{
|
||||
bulkCopy.DestinationTableName = "[dbo].[Event]";
|
||||
var dataTable = BuildEventsTable(bulkCopy, entities.Select(e => e is Event ? e as Event : new Event(e)));
|
||||
var dataTable = BuildEventsTable(bulkCopy, entities.Select(e => e is Event @event ? @event : new Event(e)));
|
||||
await bulkCopy.WriteToServerAsync(dataTable);
|
||||
}
|
||||
}
|
||||
@ -123,7 +125,7 @@ public class EventRepository : Repository<Event, Guid>, IEventRepository
|
||||
PageOptions pageOptions)
|
||||
{
|
||||
return await GetManyAsync($"[{Schema}].[Event_ReadPageByOrganizationIdServiceAccountId]",
|
||||
new Dictionary<string, object>
|
||||
new Dictionary<string, object?>
|
||||
{
|
||||
["@OrganizationId"] = organizationId,
|
||||
["@ServiceAccountId"] = serviceAccountId
|
||||
@ -131,7 +133,7 @@ public class EventRepository : Repository<Event, Guid>, IEventRepository
|
||||
}
|
||||
|
||||
private async Task<PagedResult<IEvent>> GetManyAsync(string sprocName,
|
||||
IDictionary<string, object> sprocParams, DateTime startDate, DateTime endDate, PageOptions pageOptions)
|
||||
IDictionary<string, object?> sprocParams, DateTime startDate, DateTime endDate, PageOptions pageOptions)
|
||||
{
|
||||
DateTime? beforeDate = null;
|
||||
if (!string.IsNullOrWhiteSpace(pageOptions.ContinuationToken) &&
|
||||
|
@ -2,6 +2,8 @@
|
||||
using Bit.Core.Repositories;
|
||||
using Bit.Core.Settings;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace Bit.Infrastructure.Dapper.Repositories;
|
||||
|
||||
public class InstallationRepository : Repository<Installation, Guid>, IInstallationRepository
|
||||
|
@ -4,6 +4,8 @@ using Bit.Core.Settings;
|
||||
using Dapper;
|
||||
using Microsoft.Data.SqlClient;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace Bit.Infrastructure.Dapper.Repositories;
|
||||
|
||||
public class MaintenanceRepository : BaseRepository, IMaintenanceRepository
|
||||
|
@ -6,6 +6,8 @@ using Bit.Core.Settings;
|
||||
using Dapper;
|
||||
using Microsoft.Data.SqlClient;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace Bit.Infrastructure.Dapper.Repositories;
|
||||
|
||||
public class OrganizationApiKeyRepository : Repository<OrganizationApiKey, Guid>, IOrganizationApiKeyRepository
|
||||
|
@ -6,6 +6,8 @@ using Bit.Core.Settings;
|
||||
using Dapper;
|
||||
using Microsoft.Data.SqlClient;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace Bit.Infrastructure.Dapper.Repositories;
|
||||
|
||||
public class OrganizationConnectionRepository : Repository<OrganizationConnection, Guid>, IOrganizationConnectionRepository
|
||||
@ -14,7 +16,7 @@ public class OrganizationConnectionRepository : Repository<OrganizationConnectio
|
||||
: base(globalSettings.SqlServer.ConnectionString, globalSettings.SqlServer.ReadOnlyConnectionString)
|
||||
{ }
|
||||
|
||||
public async Task<OrganizationConnection> GetByIdOrganizationIdAsync(Guid id, Guid organizationId)
|
||||
public async Task<OrganizationConnection?> GetByIdOrganizationIdAsync(Guid id, Guid organizationId)
|
||||
{
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
|
@ -6,6 +6,8 @@ using Bit.Core.Settings;
|
||||
using Dapper;
|
||||
using Microsoft.Data.SqlClient;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace Bit.Infrastructure.Dapper.Repositories;
|
||||
|
||||
public class OrganizationDomainRepository : Repository<OrganizationDomain, Guid>, IOrganizationDomainRepository
|
||||
@ -55,7 +57,7 @@ public class OrganizationDomainRepository : Repository<OrganizationDomain, Guid>
|
||||
return results.ToList();
|
||||
}
|
||||
|
||||
public async Task<OrganizationDomainSsoDetailsData> GetOrganizationDomainSsoDetailsAsync(string email)
|
||||
public async Task<OrganizationDomainSsoDetailsData?> GetOrganizationDomainSsoDetailsAsync(string email)
|
||||
{
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
@ -69,7 +71,7 @@ public class OrganizationDomainRepository : Repository<OrganizationDomain, Guid>
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<OrganizationDomain> GetDomainByIdOrganizationIdAsync(Guid id, Guid orgId)
|
||||
public async Task<OrganizationDomain?> GetDomainByIdOrganizationIdAsync(Guid id, Guid orgId)
|
||||
{
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
@ -83,7 +85,7 @@ public class OrganizationDomainRepository : Repository<OrganizationDomain, Guid>
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<OrganizationDomain> GetDomainByOrgIdAndDomainNameAsync(Guid orgId, string domainName)
|
||||
public async Task<OrganizationDomain?> GetDomainByOrgIdAndDomainNameAsync(Guid orgId, string domainName)
|
||||
{
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
|
@ -5,6 +5,8 @@ using Bit.Core.Settings;
|
||||
using Dapper;
|
||||
using Microsoft.Data.SqlClient;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace Bit.Infrastructure.Dapper.Repositories;
|
||||
|
||||
public class OrganizationSponsorshipRepository : Repository<OrganizationSponsorship, Guid>, IOrganizationSponsorshipRepository
|
||||
@ -17,7 +19,7 @@ public class OrganizationSponsorshipRepository : Repository<OrganizationSponsors
|
||||
: base(connectionString, readOnlyConnectionString)
|
||||
{ }
|
||||
|
||||
public async Task<ICollection<Guid>> CreateManyAsync(IEnumerable<OrganizationSponsorship> organizationSponsorships)
|
||||
public async Task<ICollection<Guid>?> CreateManyAsync(IEnumerable<OrganizationSponsorship> organizationSponsorships)
|
||||
{
|
||||
if (!organizationSponsorships.Any())
|
||||
{
|
||||
@ -87,7 +89,7 @@ public class OrganizationSponsorshipRepository : Repository<OrganizationSponsors
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<OrganizationSponsorship> GetBySponsoringOrganizationUserIdAsync(Guid sponsoringOrganizationUserId)
|
||||
public async Task<OrganizationSponsorship?> GetBySponsoringOrganizationUserIdAsync(Guid sponsoringOrganizationUserId)
|
||||
{
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
@ -103,7 +105,7 @@ public class OrganizationSponsorshipRepository : Repository<OrganizationSponsors
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<OrganizationSponsorship> GetBySponsoredOrganizationIdAsync(Guid sponsoredOrganizationId)
|
||||
public async Task<OrganizationSponsorship?> GetBySponsoredOrganizationIdAsync(Guid sponsoredOrganizationId)
|
||||
{
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
|
@ -4,6 +4,8 @@ using Bit.Core.Repositories;
|
||||
using Dapper;
|
||||
using Microsoft.Data.SqlClient;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace Bit.Infrastructure.Dapper.Repositories;
|
||||
|
||||
public abstract class Repository<T, TId> : BaseRepository, IRepository<T, TId>
|
||||
@ -11,7 +13,7 @@ public abstract class Repository<T, TId> : BaseRepository, IRepository<T, TId>
|
||||
where T : class, ITableObject<TId>
|
||||
{
|
||||
public Repository(string connectionString, string readOnlyConnectionString,
|
||||
string schema = null, string table = null)
|
||||
string? schema = null, string? table = null)
|
||||
: base(connectionString, readOnlyConnectionString)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(table))
|
||||
@ -28,7 +30,7 @@ public abstract class Repository<T, TId> : BaseRepository, IRepository<T, TId>
|
||||
protected string Schema { get; private set; } = "dbo";
|
||||
protected string Table { get; private set; } = typeof(T).Name;
|
||||
|
||||
public virtual async Task<T> GetByIdAsync(TId id)
|
||||
public virtual async Task<T?> GetByIdAsync(TId id)
|
||||
{
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
|
@ -5,6 +5,8 @@ using Bit.Core.Settings;
|
||||
using Dapper;
|
||||
using Microsoft.Data.SqlClient;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace Bit.Infrastructure.Dapper.Repositories;
|
||||
|
||||
public class TaxRateRepository : Repository<TaxRate, string>, ITaxRateRepository
|
||||
|
@ -6,6 +6,8 @@ using Bit.Core.Settings;
|
||||
using Dapper;
|
||||
using Microsoft.Data.SqlClient;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace Bit.Infrastructure.Dapper.Repositories;
|
||||
|
||||
public class TransactionRepository : Repository<Transaction, Guid>, ITransactionRepository
|
||||
@ -55,7 +57,7 @@ public class TransactionRepository : Repository<Transaction, Guid>, ITransaction
|
||||
return results.ToList();
|
||||
}
|
||||
|
||||
public async Task<Transaction> GetByGatewayIdAsync(GatewayType gatewayType, string gatewayId)
|
||||
public async Task<Transaction?> GetByGatewayIdAsync(GatewayType gatewayType, string gatewayId)
|
||||
{
|
||||
// maybe come back to this
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
|
@ -9,6 +9,8 @@ using Dapper;
|
||||
using Microsoft.AspNetCore.DataProtection;
|
||||
using Microsoft.Data.SqlClient;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace Bit.Infrastructure.Dapper.Repositories;
|
||||
|
||||
public class UserRepository : Repository<User, Guid>, IUserRepository
|
||||
@ -18,23 +20,19 @@ public class UserRepository : Repository<User, Guid>, IUserRepository
|
||||
public UserRepository(
|
||||
GlobalSettings globalSettings,
|
||||
IDataProtectionProvider dataProtectionProvider)
|
||||
: this(globalSettings.SqlServer.ConnectionString, globalSettings.SqlServer.ReadOnlyConnectionString)
|
||||
: base(globalSettings.SqlServer.ConnectionString, globalSettings.SqlServer.ReadOnlyConnectionString)
|
||||
{
|
||||
_dataProtector = dataProtectionProvider.CreateProtector(Constants.DatabaseFieldProtectorPurpose);
|
||||
}
|
||||
|
||||
public UserRepository(string connectionString, string readOnlyConnectionString)
|
||||
: base(connectionString, readOnlyConnectionString)
|
||||
{ }
|
||||
|
||||
public override async Task<User> GetByIdAsync(Guid id)
|
||||
public override async Task<User?> GetByIdAsync(Guid id)
|
||||
{
|
||||
var user = await base.GetByIdAsync(id);
|
||||
UnprotectData(user);
|
||||
return user;
|
||||
}
|
||||
|
||||
public async Task<User> GetByEmailAsync(string email)
|
||||
public async Task<User?> GetByEmailAsync(string email)
|
||||
{
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
@ -69,7 +67,7 @@ public class UserRepository : Repository<User, Guid>, IUserRepository
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<User> GetBySsoUserAsync(string externalId, Guid? organizationId)
|
||||
public async Task<User?> GetBySsoUserAsync(string externalId, Guid? organizationId)
|
||||
{
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
@ -83,7 +81,7 @@ public class UserRepository : Repository<User, Guid>, IUserRepository
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<UserKdfInformation> GetKdfInformationByEmailAsync(string email)
|
||||
public async Task<UserKdfInformation?> GetKdfInformationByEmailAsync(string email)
|
||||
{
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
@ -125,7 +123,7 @@ public class UserRepository : Repository<User, Guid>, IUserRepository
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<string> GetPublicKeyAsync(Guid id)
|
||||
public async Task<string?> GetPublicKeyAsync(Guid id)
|
||||
{
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
@ -273,13 +271,13 @@ public class UserRepository : Repository<User, Guid>, IUserRepository
|
||||
if (!user.MasterPassword?.StartsWith(Constants.DatabaseFieldProtectedPrefix) ?? false)
|
||||
{
|
||||
user.MasterPassword = string.Concat(Constants.DatabaseFieldProtectedPrefix,
|
||||
_dataProtector.Protect(user.MasterPassword));
|
||||
_dataProtector.Protect(user.MasterPassword!));
|
||||
}
|
||||
|
||||
if (!user.Key?.StartsWith(Constants.DatabaseFieldProtectedPrefix) ?? false)
|
||||
{
|
||||
user.Key = string.Concat(Constants.DatabaseFieldProtectedPrefix,
|
||||
_dataProtector.Protect(user.Key));
|
||||
_dataProtector.Protect(user.Key!));
|
||||
}
|
||||
|
||||
// Save
|
||||
@ -290,7 +288,7 @@ public class UserRepository : Repository<User, Guid>, IUserRepository
|
||||
user.Key = originalKey;
|
||||
}
|
||||
|
||||
private void UnprotectData(User user)
|
||||
private void UnprotectData(User? user)
|
||||
{
|
||||
if (user == null)
|
||||
{
|
||||
|
Reference in New Issue
Block a user