1
0
mirror of https://github.com/bitwarden/server.git synced 2024-11-21 12:05:42 +01:00

Fix EF bugs (#1791)

This commit is contained in:
Justin Baur 2022-01-13 15:38:05 -05:00 committed by GitHub
parent 2ed588d005
commit 486845242f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 7 deletions

View File

@ -92,7 +92,10 @@ namespace Bit.Infrastructure.EntityFramework.Repositories
using (var scope = ServiceScopeFactory.CreateScope())
{
var dbContext = GetDatabaseContext(scope);
var entities = dbContext.FindAsync<OrganizationUser>(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<IEnumerable<string>> SelectKnownEmailsAsync(Guid organizationId, IEnumerable<string> emails, bool onlyRegisteredUsers)
public async Task<ICollection<string>> SelectKnownEmailsAsync(Guid organizationId, IEnumerable<string> 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<ICollection<string>> IOrganizationUserRepository.SelectKnownEmailsAsync(Guid organizationId, IEnumerable<string> emails, bool onlyRegisteredUsers) => throw new NotImplementedException();
public async Task<IEnumerable<OrganizationUserUserDetails>> GetManyByMinimumRoleAsync(Guid organizationId, OrganizationUserType minRole)
{
using (var scope = ServiceScopeFactory.CreateScope())

View File

@ -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,
});
}
}