1
0
mirror of https://github.com/bitwarden/server synced 2026-02-11 14:03:24 +00:00
Files
server/src/Infrastructure.EntityFramework/Auth/Repositories/Queries/EmergencyAccessDetailsViewQuery.cs
Ike 68e67e1853 [PM-26376] Emergency Access Delete Command (#6857)
* feat: Add initial DeleteEmergencyContactCommand

* chore: remove nullable enable and add comments

* test: add tests for new delete command

* test: update tests to test IMailer was called.

* feat: add delete by GranteeId and allow for multiple grantors to be contacted.

* feat: add DeleteMany stored procedure for EmergencyAccess

* test: add database tests for new SP

* feat: commands use DeleteManyById for emergencyAccessDeletes

* claude: send one email per grantor instead of a bulk email to all grantors. Modified tests to validate.

* feat: change revision dates for confirmed grantees; 

* feat: add AccountRevisionDate bump for grantee users in the confirmed status

* test: update integration test to validate only confirmed users are updated as well as proper deletion of emergency access
2026-02-03 16:43:44 -05:00

40 lines
1.6 KiB
C#

using Bit.Core.Auth.Models.Data;
using Bit.Infrastructure.EntityFramework.Repositories;
using Bit.Infrastructure.EntityFramework.Repositories.Queries;
namespace Bit.Infrastructure.EntityFramework.Auth.Repositories.Queries;
public class EmergencyAccessDetailsViewQuery : IQuery<EmergencyAccessDetails>
{
public IQueryable<EmergencyAccessDetails> Run(DatabaseContext dbContext)
{
var query = from ea in dbContext.EmergencyAccesses
join grantee in dbContext.Users
on ea.GranteeId equals grantee.Id into grantee_g
from grantee in grantee_g.DefaultIfEmpty()
join grantor in dbContext.Users
on ea.GrantorId equals grantor.Id into grantor_g
from grantor in grantor_g.DefaultIfEmpty()
select new { ea, grantee, grantor };
return query.Select(x => new EmergencyAccessDetails
{
Id = x.ea.Id,
GrantorId = x.ea.GrantorId,
GranteeId = x.ea.GranteeId,
Email = x.ea.Email,
KeyEncrypted = x.ea.KeyEncrypted,
Type = x.ea.Type,
Status = x.ea.Status,
WaitTimeDays = x.ea.WaitTimeDays,
RecoveryInitiatedDate = x.ea.RecoveryInitiatedDate,
LastNotificationDate = x.ea.LastNotificationDate,
CreationDate = x.ea.CreationDate,
RevisionDate = x.ea.RevisionDate,
GranteeName = x.grantee.Name,
GranteeEmail = x.grantee.Email ?? x.ea.Email,
GrantorName = x.grantor.Name,
GrantorEmail = x.grantor.Email,
});
}
}