1
0
mirror of https://github.com/bitwarden/server synced 2026-01-03 17:14:00 +00:00

[AC-2972] AC Team ownership: Events (#4647)

* Move Event domain under AC Team ownership
This commit is contained in:
Thomas Rittson
2024-08-19 08:00:17 +10:00
committed by GitHub
parent faa9afbe5e
commit 0230013b20
20 changed files with 2 additions and 0 deletions

View File

@@ -0,0 +1,47 @@
using Bit.Core.Models.Data;
using Bit.Core.Vault.Entities;
using Event = Bit.Infrastructure.EntityFramework.Models.Event;
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries;
public class EventReadPageByCipherIdQuery : IQuery<Event>
{
private readonly Cipher _cipher;
private readonly DateTime _startDate;
private readonly DateTime _endDate;
private readonly DateTime? _beforeDate;
private readonly PageOptions _pageOptions;
public EventReadPageByCipherIdQuery(Cipher cipher, DateTime startDate, DateTime endDate, PageOptions pageOptions)
{
_cipher = cipher;
_startDate = startDate;
_endDate = endDate;
_beforeDate = null;
_pageOptions = pageOptions;
}
public EventReadPageByCipherIdQuery(Cipher cipher, DateTime startDate, DateTime endDate, DateTime? beforeDate, PageOptions pageOptions)
{
_cipher = cipher;
_startDate = startDate;
_endDate = endDate;
_beforeDate = beforeDate;
_pageOptions = pageOptions;
}
public IQueryable<Event> Run(DatabaseContext dbContext)
{
var q = from e in dbContext.Events
where e.Date >= _startDate &&
(_beforeDate == null || e.Date < _beforeDate.Value) &&
((!_cipher.OrganizationId.HasValue && !e.OrganizationId.HasValue) ||
(_cipher.OrganizationId.HasValue && _cipher.OrganizationId == e.OrganizationId)) &&
((!_cipher.UserId.HasValue && !e.UserId.HasValue) ||
(_cipher.UserId.HasValue && _cipher.UserId == e.UserId)) &&
_cipher.Id == e.CipherId
orderby e.Date descending
select e;
return q.Skip(0).Take(_pageOptions.PageSize);
}
}

View File

@@ -0,0 +1,38 @@
using Bit.Core.Models.Data;
using Bit.Infrastructure.EntityFramework.Models;
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries;
public class EventReadPageByOrganizationIdActingUserIdQuery : IQuery<Event>
{
private readonly Guid _organizationId;
private readonly Guid _actingUserId;
private readonly DateTime _startDate;
private readonly DateTime _endDate;
private readonly DateTime? _beforeDate;
private readonly PageOptions _pageOptions;
public EventReadPageByOrganizationIdActingUserIdQuery(Guid organizationId, Guid actingUserId,
DateTime startDate, DateTime endDate, DateTime? beforeDate, PageOptions pageOptions)
{
_organizationId = organizationId;
_actingUserId = actingUserId;
_startDate = startDate;
_endDate = endDate;
_beforeDate = beforeDate;
_pageOptions = pageOptions;
}
public IQueryable<Event> Run(DatabaseContext dbContext)
{
var q = from e in dbContext.Events
where e.Date >= _startDate &&
(_beforeDate != null || e.Date <= _endDate) &&
(_beforeDate == null || e.Date < _beforeDate.Value) &&
e.OrganizationId == _organizationId &&
e.ActingUserId == _actingUserId
orderby e.Date descending
select e;
return q.Skip(0).Take(_pageOptions.PageSize);
}
}

View File

@@ -0,0 +1,35 @@
using Bit.Core.Models.Data;
using Bit.Infrastructure.EntityFramework.Models;
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries;
public class EventReadPageByOrganizationIdQuery : IQuery<Event>
{
private readonly Guid _organizationId;
private readonly DateTime _startDate;
private readonly DateTime _endDate;
private readonly DateTime? _beforeDate;
private readonly PageOptions _pageOptions;
public EventReadPageByOrganizationIdQuery(Guid organizationId, DateTime startDate,
DateTime endDate, DateTime? beforeDate, PageOptions pageOptions)
{
_organizationId = organizationId;
_startDate = startDate;
_endDate = endDate;
_beforeDate = beforeDate;
_pageOptions = pageOptions;
}
public IQueryable<Event> Run(DatabaseContext dbContext)
{
var q = from e in dbContext.Events
where e.Date >= _startDate &&
(_beforeDate != null || e.Date <= _endDate) &&
(_beforeDate == null || e.Date < _beforeDate.Value) &&
e.OrganizationId == _organizationId
orderby e.Date descending
select e;
return q.Skip(0).Take(_pageOptions.PageSize);
}
}

View File

@@ -0,0 +1,38 @@
using Bit.Core.Models.Data;
using Bit.Infrastructure.EntityFramework.Models;
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries;
public class EventReadPageByOrganizationIdServiceAccountIdQuery : IQuery<Event>
{
private readonly Guid _organizationId;
private readonly Guid _serviceAccountId;
private readonly DateTime _startDate;
private readonly DateTime _endDate;
private readonly DateTime? _beforeDate;
private readonly PageOptions _pageOptions;
public EventReadPageByOrganizationIdServiceAccountIdQuery(Guid organizationId, Guid serviceAccountId,
DateTime startDate, DateTime endDate, DateTime? beforeDate, PageOptions pageOptions)
{
_organizationId = organizationId;
_serviceAccountId = serviceAccountId;
_startDate = startDate;
_endDate = endDate;
_beforeDate = beforeDate;
_pageOptions = pageOptions;
}
public IQueryable<Event> Run(DatabaseContext dbContext)
{
var q = from e in dbContext.Events
where e.Date >= _startDate &&
(_beforeDate != null || e.Date <= _endDate) &&
(_beforeDate == null || e.Date < _beforeDate.Value) &&
e.OrganizationId == _organizationId &&
e.ServiceAccountId == _serviceAccountId
orderby e.Date descending
select e;
return q.Skip(0).Take(_pageOptions.PageSize);
}
}

View File

@@ -0,0 +1,38 @@
using Bit.Core.Models.Data;
using Bit.Infrastructure.EntityFramework.Models;
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries;
public class EventReadPageByProviderIdActingUserIdQuery : IQuery<Event>
{
private readonly Guid _providerId;
private readonly Guid _actingUserId;
private readonly DateTime _startDate;
private readonly DateTime _endDate;
private readonly DateTime? _beforeDate;
private readonly PageOptions _pageOptions;
public EventReadPageByProviderIdActingUserIdQuery(Guid providerId, Guid actingUserId,
DateTime startDate, DateTime endDate, DateTime? beforeDate, PageOptions pageOptions)
{
_providerId = providerId;
_actingUserId = actingUserId;
_startDate = startDate;
_endDate = endDate;
_beforeDate = beforeDate;
_pageOptions = pageOptions;
}
public IQueryable<Event> Run(DatabaseContext dbContext)
{
var q = from e in dbContext.Events
where e.Date >= _startDate &&
(_beforeDate != null || e.Date <= _endDate) &&
(_beforeDate == null || e.Date < _beforeDate.Value) &&
e.ProviderId == _providerId &&
e.ActingUserId == _actingUserId
orderby e.Date descending
select e;
return q.Skip(0).Take(_pageOptions.PageSize);
}
}

View File

@@ -0,0 +1,35 @@
using Bit.Core.Models.Data;
using Bit.Infrastructure.EntityFramework.Models;
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries;
public class EventReadPageByProviderIdQuery : IQuery<Event>
{
private readonly Guid _providerId;
private readonly DateTime _startDate;
private readonly DateTime _endDate;
private readonly DateTime? _beforeDate;
private readonly PageOptions _pageOptions;
public EventReadPageByProviderIdQuery(Guid providerId, DateTime startDate,
DateTime endDate, DateTime? beforeDate, PageOptions pageOptions)
{
_providerId = providerId;
_startDate = startDate;
_endDate = endDate;
_beforeDate = beforeDate;
_pageOptions = pageOptions;
}
public IQueryable<Event> Run(DatabaseContext dbContext)
{
var q = from e in dbContext.Events
where e.Date >= _startDate &&
(_beforeDate != null || e.Date <= _endDate) &&
(_beforeDate == null || e.Date < _beforeDate.Value) &&
e.ProviderId == _providerId && e.OrganizationId == null
orderby e.Date descending
select e;
return q.Skip(0).Take(_pageOptions.PageSize);
}
}

View File

@@ -0,0 +1,36 @@
using Bit.Core.Models.Data;
using Bit.Infrastructure.EntityFramework.Models;
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries;
public class EventReadPageByUserIdQuery : IQuery<Event>
{
private readonly Guid _userId;
private readonly DateTime _startDate;
private readonly DateTime _endDate;
private readonly DateTime? _beforeDate;
private readonly PageOptions _pageOptions;
public EventReadPageByUserIdQuery(Guid userId, DateTime startDate,
DateTime endDate, DateTime? beforeDate, PageOptions pageOptions)
{
_userId = userId;
_startDate = startDate;
_endDate = endDate;
_beforeDate = beforeDate;
_pageOptions = pageOptions;
}
public IQueryable<Event> Run(DatabaseContext dbContext)
{
var q = from e in dbContext.Events
where e.Date >= _startDate &&
(_beforeDate != null || e.Date <= _endDate) &&
(_beforeDate == null || e.Date < _beforeDate.Value) &&
!e.OrganizationId.HasValue &&
e.ActingUserId == _userId
orderby e.Date descending
select e;
return q.Skip(0).Take(_pageOptions.PageSize);
}
}