1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-03 00:52:49 -05:00
Files
bitwarden/src/Infrastructure.EntityFramework/Repositories/Queries/EmergencyAccessReadCountByGrantorIdEmailQuery.cs
2022-08-29 16:06:55 -04:00

31 lines
1.1 KiB
C#

using Bit.Infrastructure.EntityFramework.Models;
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries;
public class EmergencyAccessReadCountByGrantorIdEmailQuery : IQuery<EmergencyAccess>
{
private readonly Guid _grantorId;
private readonly string _email;
private readonly bool _onlyRegisteredUsers;
public EmergencyAccessReadCountByGrantorIdEmailQuery(Guid grantorId, string email, bool onlyRegisteredUsers)
{
_grantorId = grantorId;
_email = email;
_onlyRegisteredUsers = onlyRegisteredUsers;
}
public IQueryable<EmergencyAccess> Run(DatabaseContext dbContext)
{
var query = from ea in dbContext.EmergencyAccesses
join u in dbContext.Users
on ea.GranteeId equals u.Id into u_g
from u in u_g.DefaultIfEmpty()
where ea.GrantorId == _grantorId &&
((!_onlyRegisteredUsers && (ea.Email == _email || u.Email == _email))
|| (_onlyRegisteredUsers && u.Email == _email))
select ea;
return query;
}
}