1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-05 18:12: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:
Justin Baur
2024-07-24 09:48:09 -04:00
committed by GitHub
parent b5f09c599b
commit 1e0182008b
67 changed files with 8432 additions and 119 deletions

View File

@ -7,8 +7,8 @@ namespace Bit.Core.Models.Data;
/// </summary>
public class CollectionAdminDetails : CollectionDetails
{
public IEnumerable<CollectionAccessSelection>? Groups { get; set; } = new List<CollectionAccessSelection>();
public IEnumerable<CollectionAccessSelection>? Users { get; set; } = new List<CollectionAccessSelection>();
public IEnumerable<CollectionAccessSelection> Groups { get; set; } = [];
public IEnumerable<CollectionAccessSelection> Users { get; set; } = [];
/// <summary>
/// Flag for whether the user has been explicitly assigned to the collection either directly or through a group.

View File

@ -156,4 +156,3 @@ public static class OrganizationServiceCollectionExtensions
);
}
}

View File

@ -1,5 +1,7 @@
using Bit.Core.Entities;
#nullable enable
namespace Bit.Core.Repositories;
public interface ICollectionCipherRepository

View File

@ -1,6 +1,8 @@
using Bit.Core.Entities;
using Bit.Core.Models.Data;
#nullable enable
namespace Bit.Core.Repositories;
public interface ICollectionRepository : IRepository<Collection, Guid>
@ -10,7 +12,7 @@ public interface ICollectionRepository : IRepository<Collection, Guid>
/// <summary>
/// Returns a collection and fetches group/user associations for the collection.
/// </summary>
Task<Tuple<Collection, CollectionAccessDetails>> GetByIdWithAccessAsync(Guid id);
Task<Tuple<Collection?, CollectionAccessDetails>> GetByIdWithAccessAsync(Guid id);
/// <summary>
/// Return all collections that belong to the organization. Does not include any permission details or group/user
@ -43,7 +45,7 @@ public interface ICollectionRepository : IRepository<Collection, Guid>
/// This does not perform any authorization checks internally!
/// Optionally, you can include access relationships for other Groups/Users and the collection.
/// </summary>
Task<CollectionAdminDetails> GetByIdWithPermissionsAsync(Guid collectionId, Guid? userId, bool includeAccessRelationships);
Task<CollectionAdminDetails?> GetByIdWithPermissionsAsync(Guid collectionId, Guid? userId, bool includeAccessRelationships);
Task CreateAsync(Collection obj, IEnumerable<CollectionAccessSelection> groups, IEnumerable<CollectionAccessSelection> users);
Task ReplaceAsync(Collection obj, IEnumerable<CollectionAccessSelection> groups, IEnumerable<CollectionAccessSelection> users);

View File

@ -1,12 +1,14 @@
using Bit.Core.Entities;
#nullable enable
namespace Bit.Core.Repositories;
public interface IDeviceRepository : IRepository<Device, Guid>
{
Task<Device> GetByIdAsync(Guid id, Guid userId);
Task<Device> GetByIdentifierAsync(string identifier);
Task<Device> GetByIdentifierAsync(string identifier, Guid userId);
Task<Device?> GetByIdAsync(Guid id, Guid userId);
Task<Device?> GetByIdentifierAsync(string identifier);
Task<Device?> GetByIdentifierAsync(string identifier, Guid userId);
Task<ICollection<Device>> GetManyByUserIdAsync(Guid userId);
Task ClearPushTokenAsync(Guid id);
}

View File

@ -1,6 +1,8 @@
using Bit.Core.Models.Data;
using Bit.Core.Vault.Entities;
#nullable enable
namespace Bit.Core.Repositories;
public interface IEventRepository

View File

@ -1,5 +1,7 @@
using Bit.Core.Models.Data;
#nullable enable
namespace Bit.Core.Repositories;
public interface IInstallationDeviceRepository

View File

@ -1,5 +1,7 @@
using Bit.Core.Entities;
#nullable enable
namespace Bit.Core.Repositories;
public interface IInstallationRepository : IRepository<Installation, Guid>

View File

@ -1,5 +1,7 @@
namespace Bit.Core.Repositories;
#nullable enable
public interface IMaintenanceRepository
{
Task UpdateStatisticsAsync();

View File

@ -1,6 +1,8 @@
using Bit.Core.Entities;
using Bit.Core.Enums;
#nullable enable
namespace Bit.Core.Repositories;
public interface IOrganizationApiKeyRepository : IRepository<OrganizationApiKey, Guid>

View File

@ -1,11 +1,13 @@
using Bit.Core.Entities;
using Bit.Core.Enums;
#nullable enable
namespace Bit.Core.Repositories;
public interface IOrganizationConnectionRepository : IRepository<OrganizationConnection, Guid>
{
Task<OrganizationConnection> GetByIdOrganizationIdAsync(Guid id, Guid organizationId);
Task<OrganizationConnection?> GetByIdOrganizationIdAsync(Guid id, Guid organizationId);
Task<ICollection<OrganizationConnection>> GetByOrganizationIdTypeAsync(Guid organizationId, OrganizationConnectionType type);
Task<ICollection<OrganizationConnection>> GetEnabledByOrganizationIdTypeAsync(Guid organizationId, OrganizationConnectionType type);
}

View File

@ -1,6 +1,8 @@
using Bit.Core.Entities;
using Bit.Core.Models.Data.Organizations;
#nullable enable
namespace Bit.Core.Repositories;
public interface IOrganizationDomainRepository : IRepository<OrganizationDomain, Guid>
@ -8,9 +10,9 @@ public interface IOrganizationDomainRepository : IRepository<OrganizationDomain,
Task<ICollection<OrganizationDomain>> GetClaimedDomainsByDomainNameAsync(string domainName);
Task<ICollection<OrganizationDomain>> GetDomainsByOrganizationIdAsync(Guid orgId);
Task<ICollection<OrganizationDomain>> GetManyByNextRunDateAsync(DateTime date);
Task<OrganizationDomainSsoDetailsData> GetOrganizationDomainSsoDetailsAsync(string email);
Task<OrganizationDomain> GetDomainByIdOrganizationIdAsync(Guid id, Guid organizationId);
Task<OrganizationDomain> GetDomainByOrgIdAndDomainNameAsync(Guid orgId, string domainName);
Task<OrganizationDomainSsoDetailsData?> GetOrganizationDomainSsoDetailsAsync(string email);
Task<OrganizationDomain?> GetDomainByIdOrganizationIdAsync(Guid id, Guid organizationId);
Task<OrganizationDomain?> GetDomainByOrgIdAndDomainNameAsync(Guid orgId, string domainName);
Task<ICollection<OrganizationDomain>> GetExpiredOrganizationDomainsAsync();
Task<bool> DeleteExpiredAsync(int expirationPeriod);
}

View File

@ -1,15 +1,17 @@
using Bit.Core.Entities;
#nullable enable
namespace Bit.Core.Repositories;
public interface IOrganizationSponsorshipRepository : IRepository<OrganizationSponsorship, Guid>
{
Task<ICollection<Guid>> CreateManyAsync(IEnumerable<OrganizationSponsorship> organizationSponsorships);
Task<ICollection<Guid>?> CreateManyAsync(IEnumerable<OrganizationSponsorship> organizationSponsorships);
Task ReplaceManyAsync(IEnumerable<OrganizationSponsorship> organizationSponsorships);
Task UpsertManyAsync(IEnumerable<OrganizationSponsorship> organizationSponsorships);
Task DeleteManyAsync(IEnumerable<Guid> organizationSponsorshipIds);
Task<ICollection<OrganizationSponsorship>> GetManyBySponsoringOrganizationAsync(Guid sponsoringOrganizationId);
Task<OrganizationSponsorship> GetBySponsoringOrganizationUserIdAsync(Guid sponsoringOrganizationUserId);
Task<OrganizationSponsorship> GetBySponsoredOrganizationIdAsync(Guid sponsoredOrganizationId);
Task<OrganizationSponsorship?> GetBySponsoringOrganizationUserIdAsync(Guid sponsoringOrganizationUserId);
Task<OrganizationSponsorship?> GetBySponsoredOrganizationIdAsync(Guid sponsoredOrganizationId);
Task<DateTime?> GetLatestSyncDateBySponsoringOrganizationIdAsync(Guid sponsoringOrganizationId);
}

View File

@ -1,10 +1,12 @@
using Bit.Core.Entities;
#nullable enable
namespace Bit.Core.Repositories;
public interface IRepository<T, TId> where TId : IEquatable<TId> where T : class, ITableObject<TId>
{
Task<T> GetByIdAsync(TId id);
Task<T?> GetByIdAsync(TId id);
Task<T> CreateAsync(T obj);
Task ReplaceAsync(T obj);
Task UpsertAsync(T obj);

View File

@ -1,5 +1,7 @@
using Bit.Core.Entities;
#nullable enable
namespace Bit.Core.Repositories;
public interface ITaxRateRepository : IRepository<TaxRate, string>

View File

@ -1,6 +1,8 @@
using Bit.Core.Entities;
using Bit.Core.Enums;
#nullable enable
namespace Bit.Core.Repositories;
public interface ITransactionRepository : IRepository<Transaction, Guid>
@ -8,5 +10,5 @@ public interface ITransactionRepository : IRepository<Transaction, Guid>
Task<ICollection<Transaction>> GetManyByUserIdAsync(Guid userId, int? limit = null);
Task<ICollection<Transaction>> GetManyByOrganizationIdAsync(Guid organizationId, int? limit = null);
Task<ICollection<Transaction>> GetManyByProviderIdAsync(Guid providerId, int? limit = null);
Task<Transaction> GetByGatewayIdAsync(GatewayType gatewayType, string gatewayId);
Task<Transaction?> GetByGatewayIdAsync(GatewayType gatewayType, string gatewayId);
}

View File

@ -2,17 +2,19 @@
using Bit.Core.Entities;
using Bit.Core.Models.Data;
#nullable enable
namespace Bit.Core.Repositories;
public interface IUserRepository : IRepository<User, Guid>
{
Task<User> GetByEmailAsync(string email);
Task<User?> GetByEmailAsync(string email);
Task<IEnumerable<User>> GetManyByEmailsAsync(IEnumerable<string> emails);
Task<User> GetBySsoUserAsync(string externalId, Guid? organizationId);
Task<UserKdfInformation> GetKdfInformationByEmailAsync(string email);
Task<User?> GetBySsoUserAsync(string externalId, Guid? organizationId);
Task<UserKdfInformation?> GetKdfInformationByEmailAsync(string email);
Task<ICollection<User>> SearchAsync(string email, int skip, int take);
Task<ICollection<User>> GetManyByPremiumAsync(bool premium);
Task<string> GetPublicKeyAsync(Guid id);
Task<string?> GetPublicKeyAsync(Guid id);
Task<DateTime> GetAccountRevisionDateAsync(Guid id);
Task UpdateStorageAsync(Guid id);
Task UpdateRenewalReminderDateAsync(Guid id, DateTime renewalReminderDate);

View File

@ -1,5 +1,7 @@
using Bit.Core.Models.Data;
#nullable enable
namespace Bit.Core.Repositories.Noop;
public class InstallationDeviceRepository : IInstallationDeviceRepository

View File

@ -4,6 +4,8 @@ using Bit.Core.Settings;
using Bit.Core.Utilities;
using Bit.Core.Vault.Entities;
#nullable enable
namespace Bit.Core.Repositories.TableStorage;
public class EventRepository : IEventRepository
@ -78,9 +80,9 @@ public class EventRepository : IEventRepository
await CreateEventAsync(entity);
}
public async Task CreateManyAsync(IEnumerable<IEvent> e)
public async Task CreateManyAsync(IEnumerable<IEvent>? e)
{
if (!e?.Any() ?? true)
if (e is null || !e.Any())
{
return;
}
@ -91,7 +93,7 @@ public class EventRepository : IEventRepository
return;
}
var entities = e.Where(ev => ev is EventTableEntity).Select(ev => ev as EventTableEntity);
var entities = e.OfType<EventTableEntity>();
var entityGroups = entities.GroupBy(ent => ent.PartitionKey);
foreach (var group in entityGroups)
{
@ -134,7 +136,7 @@ public class EventRepository : IEventRepository
var result = new PagedResult<IEvent>();
var query = _tableClient.QueryAsync<AzureEvent>(filter, pageOptions.PageSize);
await using (var enumerator = query.AsPages(pageOptions?.ContinuationToken,
await using (var enumerator = query.AsPages(pageOptions.ContinuationToken,
pageOptions.PageSize).GetAsyncEnumerator())
{
await enumerator.MoveNextAsync();

View File

@ -2,6 +2,8 @@
using Bit.Core.Models.Data;
using Bit.Core.Settings;
#nullable enable
namespace Bit.Core.Repositories.TableStorage;
public class InstallationDeviceRepository : IInstallationDeviceRepository
@ -23,9 +25,9 @@ public class InstallationDeviceRepository : IInstallationDeviceRepository
await _tableClient.UpsertEntityAsync(entity);
}
public async Task UpsertManyAsync(IList<InstallationDeviceEntity> entities)
public async Task UpsertManyAsync(IList<InstallationDeviceEntity>? entities)
{
if (!entities?.Any() ?? true)
if (entities is null || !entities.Any())
{
return;
}