From 486845242fc7b314aa791b30a512893e7af613d6 Mon Sep 17 00:00:00 2001 From: Justin Baur Date: Thu, 13 Jan 2022 15:38:05 -0500 Subject: [PATCH] Fix EF bugs (#1791) --- .../Repositories/OrganizationUserRepository.cs | 13 +++++++------ .../Queries/OrganizationUserUserViewQuery.cs | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/Infrastructure.EntityFramework/Repositories/OrganizationUserRepository.cs b/src/Infrastructure.EntityFramework/Repositories/OrganizationUserRepository.cs index b6d716caa..b130cfa8f 100644 --- a/src/Infrastructure.EntityFramework/Repositories/OrganizationUserRepository.cs +++ b/src/Infrastructure.EntityFramework/Repositories/OrganizationUserRepository.cs @@ -92,7 +92,10 @@ namespace Bit.Infrastructure.EntityFramework.Repositories using (var scope = ServiceScopeFactory.CreateScope()) { var dbContext = GetDatabaseContext(scope); - var entities = dbContext.FindAsync(organizationUserIds); + var entities = await dbContext.OrganizationUsers + .Where(ou => organizationUserIds.Contains(ou.Id)) + .ToListAsync(); + var sponsorships = dbContext.OrganizationSponsorships .Where(os => os.SponsoringOrganizationUserId != default && organizationUserIds.Contains(os.SponsoringOrganizationUserId ?? default)); @@ -102,7 +105,7 @@ namespace Bit.Infrastructure.EntityFramework.Repositories sponsorship.FriendlyName = null; } - dbContext.RemoveRange(entities); + dbContext.OrganizationUsers.RemoveRange(entities); await dbContext.SaveChangesAsync(); } } @@ -358,7 +361,7 @@ namespace Bit.Infrastructure.EntityFramework.Repositories } } - public async Task> SelectKnownEmailsAsync(Guid organizationId, IEnumerable emails, bool onlyRegisteredUsers) + public async Task> SelectKnownEmailsAsync(Guid organizationId, IEnumerable emails, bool onlyRegisteredUsers) { using (var scope = ServiceScopeFactory.CreateScope()) { @@ -377,7 +380,7 @@ namespace Bit.Infrastructure.EntityFramework.Repositories (!onlyRegisteredUsers && (uEmails.Contains(e) || ouEmails.Contains(e))) || (onlyRegisteredUsers && uEmails.Contains(e)) select e; - return knownEmails; + return knownEmails.ToList(); } } @@ -421,8 +424,6 @@ namespace Bit.Infrastructure.EntityFramework.Repositories await ReplaceManyAsync(replaceUsers); } - Task> IOrganizationUserRepository.SelectKnownEmailsAsync(Guid organizationId, IEnumerable emails, bool onlyRegisteredUsers) => throw new NotImplementedException(); - public async Task> GetManyByMinimumRoleAsync(Guid organizationId, OrganizationUserType minRole) { using (var scope = ServiceScopeFactory.CreateScope()) diff --git a/src/Infrastructure.EntityFramework/Repositories/Queries/OrganizationUserUserViewQuery.cs b/src/Infrastructure.EntityFramework/Repositories/Queries/OrganizationUserUserViewQuery.cs index 26d1e3d72..5b8f49c22 100644 --- a/src/Infrastructure.EntityFramework/Repositories/Queries/OrganizationUserUserViewQuery.cs +++ b/src/Infrastructure.EntityFramework/Repositories/Queries/OrganizationUserUserViewQuery.cs @@ -29,7 +29,7 @@ namespace Bit.Infrastructure.EntityFramework.Repositories.Queries SsoExternalId = x.su.ExternalId, Permissions = x.ou.Permissions, ResetPasswordKey = x.ou.ResetPasswordKey, - UsesKeyConnector = x.u.UsesKeyConnector, + UsesKeyConnector = x.u != null && x.u.UsesKeyConnector, }); } }