mirror of
https://github.com/bitwarden/server
synced 2025-12-17 16:53:23 +00:00
Run formatting (#2230)
This commit is contained in:
@@ -1,37 +1,36 @@
|
||||
using Bit.Core.Utilities;
|
||||
using Core.Models.Data;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries;
|
||||
|
||||
public class CipherDetailsQuery : IQuery<CipherDetails>
|
||||
{
|
||||
public class CipherDetailsQuery : IQuery<CipherDetails>
|
||||
private readonly Guid? _userId;
|
||||
private readonly bool _ignoreFolders;
|
||||
public CipherDetailsQuery(Guid? userId, bool ignoreFolders = false)
|
||||
{
|
||||
private readonly Guid? _userId;
|
||||
private readonly bool _ignoreFolders;
|
||||
public CipherDetailsQuery(Guid? userId, bool ignoreFolders = false)
|
||||
{
|
||||
_userId = userId;
|
||||
_ignoreFolders = ignoreFolders;
|
||||
}
|
||||
public virtual IQueryable<CipherDetails> Run(DatabaseContext dbContext)
|
||||
{
|
||||
var query = from c in dbContext.Ciphers
|
||||
select new CipherDetails
|
||||
{
|
||||
Id = c.Id,
|
||||
UserId = c.UserId,
|
||||
OrganizationId = c.OrganizationId,
|
||||
Type = c.Type,
|
||||
Data = c.Data,
|
||||
Attachments = c.Attachments,
|
||||
CreationDate = c.CreationDate,
|
||||
RevisionDate = c.RevisionDate,
|
||||
DeletedDate = c.DeletedDate,
|
||||
Favorite = _userId.HasValue && c.Favorites != null && c.Favorites.Contains($"\"{_userId}\":true"),
|
||||
FolderId = (_ignoreFolders || !_userId.HasValue || c.Folders == null || !c.Folders.Contains(_userId.Value.ToString())) ?
|
||||
null :
|
||||
CoreHelpers.LoadClassFromJsonData<Dictionary<Guid, Guid>>(c.Folders)[_userId.Value],
|
||||
};
|
||||
return query;
|
||||
}
|
||||
_userId = userId;
|
||||
_ignoreFolders = ignoreFolders;
|
||||
}
|
||||
public virtual IQueryable<CipherDetails> Run(DatabaseContext dbContext)
|
||||
{
|
||||
var query = from c in dbContext.Ciphers
|
||||
select new CipherDetails
|
||||
{
|
||||
Id = c.Id,
|
||||
UserId = c.UserId,
|
||||
OrganizationId = c.OrganizationId,
|
||||
Type = c.Type,
|
||||
Data = c.Data,
|
||||
Attachments = c.Attachments,
|
||||
CreationDate = c.CreationDate,
|
||||
RevisionDate = c.RevisionDate,
|
||||
DeletedDate = c.DeletedDate,
|
||||
Favorite = _userId.HasValue && c.Favorites != null && c.Favorites.Contains($"\"{_userId}\":true"),
|
||||
FolderId = (_ignoreFolders || !_userId.HasValue || c.Folders == null || !c.Folders.Contains(_userId.Value.ToString())) ?
|
||||
null :
|
||||
CoreHelpers.LoadClassFromJsonData<Dictionary<Guid, Guid>>(c.Folders)[_userId.Value],
|
||||
};
|
||||
return query;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,39 +1,38 @@
|
||||
using Core.Models.Data;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries;
|
||||
|
||||
public class CipherOrganizationDetailsReadByIdQuery : IQuery<CipherOrganizationDetails>
|
||||
{
|
||||
public class CipherOrganizationDetailsReadByIdQuery : IQuery<CipherOrganizationDetails>
|
||||
private readonly Guid _cipherId;
|
||||
|
||||
public CipherOrganizationDetailsReadByIdQuery(Guid cipherId)
|
||||
{
|
||||
private readonly Guid _cipherId;
|
||||
_cipherId = cipherId;
|
||||
}
|
||||
|
||||
public CipherOrganizationDetailsReadByIdQuery(Guid cipherId)
|
||||
{
|
||||
_cipherId = cipherId;
|
||||
}
|
||||
|
||||
public virtual IQueryable<CipherOrganizationDetails> Run(DatabaseContext dbContext)
|
||||
{
|
||||
var query = from c in dbContext.Ciphers
|
||||
join o in dbContext.Organizations
|
||||
on c.OrganizationId equals o.Id into o_g
|
||||
from o in o_g.DefaultIfEmpty()
|
||||
where c.Id == _cipherId
|
||||
select new CipherOrganizationDetails
|
||||
{
|
||||
Id = c.Id,
|
||||
UserId = c.UserId,
|
||||
OrganizationId = c.OrganizationId,
|
||||
Type = c.Type,
|
||||
Data = c.Data,
|
||||
Favorites = c.Favorites,
|
||||
Folders = c.Folders,
|
||||
Attachments = c.Attachments,
|
||||
CreationDate = c.CreationDate,
|
||||
RevisionDate = c.RevisionDate,
|
||||
DeletedDate = c.DeletedDate,
|
||||
OrganizationUseTotp = o.UseTotp,
|
||||
};
|
||||
return query;
|
||||
}
|
||||
public virtual IQueryable<CipherOrganizationDetails> Run(DatabaseContext dbContext)
|
||||
{
|
||||
var query = from c in dbContext.Ciphers
|
||||
join o in dbContext.Organizations
|
||||
on c.OrganizationId equals o.Id into o_g
|
||||
from o in o_g.DefaultIfEmpty()
|
||||
where c.Id == _cipherId
|
||||
select new CipherOrganizationDetails
|
||||
{
|
||||
Id = c.Id,
|
||||
UserId = c.UserId,
|
||||
OrganizationId = c.OrganizationId,
|
||||
Type = c.Type,
|
||||
Data = c.Data,
|
||||
Favorites = c.Favorites,
|
||||
Folders = c.Folders,
|
||||
Attachments = c.Attachments,
|
||||
CreationDate = c.CreationDate,
|
||||
RevisionDate = c.RevisionDate,
|
||||
DeletedDate = c.DeletedDate,
|
||||
OrganizationUseTotp = o.UseTotp,
|
||||
};
|
||||
return query;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,38 +1,37 @@
|
||||
using Core.Models.Data;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries
|
||||
{
|
||||
public class CipherOrganizationDetailsReadByOrgizationIdQuery : IQuery<CipherOrganizationDetails>
|
||||
{
|
||||
private readonly Guid _organizationId;
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries;
|
||||
|
||||
public CipherOrganizationDetailsReadByOrgizationIdQuery(Guid organizationId)
|
||||
{
|
||||
_organizationId = organizationId;
|
||||
}
|
||||
public virtual IQueryable<CipherOrganizationDetails> Run(DatabaseContext dbContext)
|
||||
{
|
||||
var query = from c in dbContext.Ciphers
|
||||
join o in dbContext.Organizations
|
||||
on c.OrganizationId equals o.Id into o_g
|
||||
from o in o_g.DefaultIfEmpty()
|
||||
where c.OrganizationId == _organizationId
|
||||
select new CipherOrganizationDetails
|
||||
{
|
||||
Id = c.Id,
|
||||
UserId = c.UserId,
|
||||
OrganizationId = c.OrganizationId,
|
||||
Type = c.Type,
|
||||
Data = c.Data,
|
||||
Favorites = c.Favorites,
|
||||
Folders = c.Folders,
|
||||
Attachments = c.Attachments,
|
||||
CreationDate = c.CreationDate,
|
||||
RevisionDate = c.RevisionDate,
|
||||
DeletedDate = c.DeletedDate,
|
||||
OrganizationUseTotp = o.UseTotp,
|
||||
};
|
||||
return query;
|
||||
}
|
||||
public class CipherOrganizationDetailsReadByOrgizationIdQuery : IQuery<CipherOrganizationDetails>
|
||||
{
|
||||
private readonly Guid _organizationId;
|
||||
|
||||
public CipherOrganizationDetailsReadByOrgizationIdQuery(Guid organizationId)
|
||||
{
|
||||
_organizationId = organizationId;
|
||||
}
|
||||
public virtual IQueryable<CipherOrganizationDetails> Run(DatabaseContext dbContext)
|
||||
{
|
||||
var query = from c in dbContext.Ciphers
|
||||
join o in dbContext.Organizations
|
||||
on c.OrganizationId equals o.Id into o_g
|
||||
from o in o_g.DefaultIfEmpty()
|
||||
where c.OrganizationId == _organizationId
|
||||
select new CipherOrganizationDetails
|
||||
{
|
||||
Id = c.Id,
|
||||
UserId = c.UserId,
|
||||
OrganizationId = c.OrganizationId,
|
||||
Type = c.Type,
|
||||
Data = c.Data,
|
||||
Favorites = c.Favorites,
|
||||
Folders = c.Folders,
|
||||
Attachments = c.Attachments,
|
||||
CreationDate = c.CreationDate,
|
||||
RevisionDate = c.RevisionDate,
|
||||
DeletedDate = c.DeletedDate,
|
||||
OrganizationUseTotp = o.UseTotp,
|
||||
};
|
||||
return query;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,56 +1,55 @@
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Infrastructure.EntityFramework.Models;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries;
|
||||
|
||||
public class CipherReadCanEditByIdUserIdQuery : IQuery<Cipher>
|
||||
{
|
||||
public class CipherReadCanEditByIdUserIdQuery : IQuery<Cipher>
|
||||
private readonly Guid _userId;
|
||||
private readonly Guid _cipherId;
|
||||
|
||||
public CipherReadCanEditByIdUserIdQuery(Guid userId, Guid cipherId)
|
||||
{
|
||||
private readonly Guid _userId;
|
||||
private readonly Guid _cipherId;
|
||||
_userId = userId;
|
||||
_cipherId = cipherId;
|
||||
}
|
||||
|
||||
public CipherReadCanEditByIdUserIdQuery(Guid userId, Guid cipherId)
|
||||
{
|
||||
_userId = userId;
|
||||
_cipherId = cipherId;
|
||||
}
|
||||
|
||||
public virtual IQueryable<Cipher> Run(DatabaseContext dbContext)
|
||||
{
|
||||
var query = from c in dbContext.Ciphers
|
||||
join o in dbContext.Organizations
|
||||
on c.OrganizationId equals o.Id into o_g
|
||||
from o in o_g.DefaultIfEmpty()
|
||||
where !c.UserId.HasValue
|
||||
join ou in dbContext.OrganizationUsers
|
||||
on o.Id equals ou.OrganizationId into ou_g
|
||||
from ou in ou_g.DefaultIfEmpty()
|
||||
where ou.UserId == _userId
|
||||
join cc in dbContext.CollectionCiphers
|
||||
on c.Id equals cc.CipherId into cc_g
|
||||
from cc in cc_g.DefaultIfEmpty()
|
||||
where !c.UserId.HasValue && !ou.AccessAll
|
||||
join cu in dbContext.CollectionUsers
|
||||
on cc.CollectionId equals cu.CollectionId into cu_g
|
||||
from cu in cu_g.DefaultIfEmpty()
|
||||
where ou.Id == cu.OrganizationUserId
|
||||
join gu in dbContext.GroupUsers
|
||||
on ou.Id equals gu.OrganizationUserId into gu_g
|
||||
from gu in gu_g.DefaultIfEmpty()
|
||||
where !c.UserId.HasValue && cu.CollectionId == null && !ou.AccessAll
|
||||
join g in dbContext.Groups
|
||||
on gu.GroupId equals g.Id into g_g
|
||||
from g in g_g.DefaultIfEmpty()
|
||||
join cg in dbContext.CollectionGroups
|
||||
on gu.GroupId equals cg.GroupId into cg_g
|
||||
from cg in cg_g.DefaultIfEmpty()
|
||||
where !g.AccessAll && cg.CollectionId == cc.CollectionId &&
|
||||
(c.Id == _cipherId &&
|
||||
(c.UserId == _userId ||
|
||||
(!c.UserId.HasValue && ou.Status == OrganizationUserStatusType.Confirmed && o.Enabled &&
|
||||
(ou.AccessAll || cu.CollectionId != null || g.AccessAll || cg.CollectionId != null)))) &&
|
||||
(c.UserId.HasValue || ou.AccessAll || !cu.ReadOnly || g.AccessAll || !cg.ReadOnly)
|
||||
select c;
|
||||
return query;
|
||||
}
|
||||
public virtual IQueryable<Cipher> Run(DatabaseContext dbContext)
|
||||
{
|
||||
var query = from c in dbContext.Ciphers
|
||||
join o in dbContext.Organizations
|
||||
on c.OrganizationId equals o.Id into o_g
|
||||
from o in o_g.DefaultIfEmpty()
|
||||
where !c.UserId.HasValue
|
||||
join ou in dbContext.OrganizationUsers
|
||||
on o.Id equals ou.OrganizationId into ou_g
|
||||
from ou in ou_g.DefaultIfEmpty()
|
||||
where ou.UserId == _userId
|
||||
join cc in dbContext.CollectionCiphers
|
||||
on c.Id equals cc.CipherId into cc_g
|
||||
from cc in cc_g.DefaultIfEmpty()
|
||||
where !c.UserId.HasValue && !ou.AccessAll
|
||||
join cu in dbContext.CollectionUsers
|
||||
on cc.CollectionId equals cu.CollectionId into cu_g
|
||||
from cu in cu_g.DefaultIfEmpty()
|
||||
where ou.Id == cu.OrganizationUserId
|
||||
join gu in dbContext.GroupUsers
|
||||
on ou.Id equals gu.OrganizationUserId into gu_g
|
||||
from gu in gu_g.DefaultIfEmpty()
|
||||
where !c.UserId.HasValue && cu.CollectionId == null && !ou.AccessAll
|
||||
join g in dbContext.Groups
|
||||
on gu.GroupId equals g.Id into g_g
|
||||
from g in g_g.DefaultIfEmpty()
|
||||
join cg in dbContext.CollectionGroups
|
||||
on gu.GroupId equals cg.GroupId into cg_g
|
||||
from cg in cg_g.DefaultIfEmpty()
|
||||
where !g.AccessAll && cg.CollectionId == cc.CollectionId &&
|
||||
(c.Id == _cipherId &&
|
||||
(c.UserId == _userId ||
|
||||
(!c.UserId.HasValue && ou.Status == OrganizationUserStatusType.Confirmed && o.Enabled &&
|
||||
(ou.AccessAll || cu.CollectionId != null || g.AccessAll || cg.CollectionId != null)))) &&
|
||||
(c.UserId.HasValue || ou.AccessAll || !cu.ReadOnly || g.AccessAll || !cg.ReadOnly)
|
||||
select c;
|
||||
return query;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,65 +2,64 @@
|
||||
using Bit.Core.Enums;
|
||||
using CollectionCipher = Bit.Infrastructure.EntityFramework.Models.CollectionCipher;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries;
|
||||
|
||||
public class CipherUpdateCollectionsQuery : IQuery<CollectionCipher>
|
||||
{
|
||||
public class CipherUpdateCollectionsQuery : IQuery<CollectionCipher>
|
||||
private readonly Cipher _cipher;
|
||||
private readonly IEnumerable<Guid> _collectionIds;
|
||||
|
||||
public CipherUpdateCollectionsQuery(Cipher cipher, IEnumerable<Guid> collectionIds)
|
||||
{
|
||||
private readonly Cipher _cipher;
|
||||
private readonly IEnumerable<Guid> _collectionIds;
|
||||
_cipher = cipher;
|
||||
_collectionIds = collectionIds;
|
||||
}
|
||||
|
||||
public CipherUpdateCollectionsQuery(Cipher cipher, IEnumerable<Guid> collectionIds)
|
||||
public virtual IQueryable<CollectionCipher> Run(DatabaseContext dbContext)
|
||||
{
|
||||
if (!_cipher.OrganizationId.HasValue || !_collectionIds.Any())
|
||||
{
|
||||
_cipher = cipher;
|
||||
_collectionIds = collectionIds;
|
||||
return null;
|
||||
}
|
||||
|
||||
public virtual IQueryable<CollectionCipher> Run(DatabaseContext dbContext)
|
||||
var availibleCollections = !_cipher.UserId.HasValue ?
|
||||
from c in dbContext.Collections
|
||||
where c.OrganizationId == _cipher.OrganizationId
|
||||
select c.Id :
|
||||
from c in dbContext.Collections
|
||||
join o in dbContext.Organizations
|
||||
on c.OrganizationId equals o.Id
|
||||
join ou in dbContext.OrganizationUsers
|
||||
on o.Id equals ou.OrganizationId
|
||||
where ou.UserId == _cipher.UserId
|
||||
join cu in dbContext.CollectionUsers
|
||||
on c.Id equals cu.CollectionId into cu_g
|
||||
from cu in cu_g.DefaultIfEmpty()
|
||||
where !ou.AccessAll && cu.OrganizationUserId == ou.Id
|
||||
join gu in dbContext.GroupUsers
|
||||
on ou.Id equals gu.OrganizationUserId into gu_g
|
||||
from gu in gu_g.DefaultIfEmpty()
|
||||
where cu.CollectionId == null && !ou.AccessAll
|
||||
join g in dbContext.Groups
|
||||
on gu.GroupId equals g.Id into g_g
|
||||
from g in g_g.DefaultIfEmpty()
|
||||
join cg in dbContext.CollectionGroups
|
||||
on c.Id equals cg.CollectionId into cg_g
|
||||
from cg in cg_g.DefaultIfEmpty()
|
||||
where !g.AccessAll && gu.GroupId == cg.GroupId &&
|
||||
o.Id == _cipher.OrganizationId &&
|
||||
o.Enabled &&
|
||||
ou.Status == OrganizationUserStatusType.Confirmed &&
|
||||
(ou.AccessAll || !cu.ReadOnly || g.AccessAll || !cg.ReadOnly)
|
||||
select c.Id;
|
||||
|
||||
if (!availibleCollections.Any())
|
||||
{
|
||||
if (!_cipher.OrganizationId.HasValue || !_collectionIds.Any())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var availibleCollections = !_cipher.UserId.HasValue ?
|
||||
from c in dbContext.Collections
|
||||
where c.OrganizationId == _cipher.OrganizationId
|
||||
select c.Id :
|
||||
from c in dbContext.Collections
|
||||
join o in dbContext.Organizations
|
||||
on c.OrganizationId equals o.Id
|
||||
join ou in dbContext.OrganizationUsers
|
||||
on o.Id equals ou.OrganizationId
|
||||
where ou.UserId == _cipher.UserId
|
||||
join cu in dbContext.CollectionUsers
|
||||
on c.Id equals cu.CollectionId into cu_g
|
||||
from cu in cu_g.DefaultIfEmpty()
|
||||
where !ou.AccessAll && cu.OrganizationUserId == ou.Id
|
||||
join gu in dbContext.GroupUsers
|
||||
on ou.Id equals gu.OrganizationUserId into gu_g
|
||||
from gu in gu_g.DefaultIfEmpty()
|
||||
where cu.CollectionId == null && !ou.AccessAll
|
||||
join g in dbContext.Groups
|
||||
on gu.GroupId equals g.Id into g_g
|
||||
from g in g_g.DefaultIfEmpty()
|
||||
join cg in dbContext.CollectionGroups
|
||||
on c.Id equals cg.CollectionId into cg_g
|
||||
from cg in cg_g.DefaultIfEmpty()
|
||||
where !g.AccessAll && gu.GroupId == cg.GroupId &&
|
||||
o.Id == _cipher.OrganizationId &&
|
||||
o.Enabled &&
|
||||
ou.Status == OrganizationUserStatusType.Confirmed &&
|
||||
(ou.AccessAll || !cu.ReadOnly || g.AccessAll || !cg.ReadOnly)
|
||||
select c.Id;
|
||||
|
||||
if (!availibleCollections.Any())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var query = from c in availibleCollections
|
||||
select new CollectionCipher { CollectionId = c, CipherId = _cipher.Id };
|
||||
return query;
|
||||
return null;
|
||||
}
|
||||
|
||||
var query = from c in availibleCollections
|
||||
select new CollectionCipher { CollectionId = c, CipherId = _cipher.Id };
|
||||
return query;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +1,19 @@
|
||||
using Bit.Infrastructure.EntityFramework.Models;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries;
|
||||
|
||||
public class CollectionCipherReadByUserIdCipherIdQuery : CollectionCipherReadByUserIdQuery
|
||||
{
|
||||
public class CollectionCipherReadByUserIdCipherIdQuery : CollectionCipherReadByUserIdQuery
|
||||
private readonly Guid _cipherId;
|
||||
|
||||
public CollectionCipherReadByUserIdCipherIdQuery(Guid userId, Guid cipherId) : base(userId)
|
||||
{
|
||||
private readonly Guid _cipherId;
|
||||
_cipherId = cipherId;
|
||||
}
|
||||
|
||||
public CollectionCipherReadByUserIdCipherIdQuery(Guid userId, Guid cipherId) : base(userId)
|
||||
{
|
||||
_cipherId = cipherId;
|
||||
}
|
||||
|
||||
public override IQueryable<CollectionCipher> Run(DatabaseContext dbContext)
|
||||
{
|
||||
var query = base.Run(dbContext);
|
||||
return query.Where(x => x.CipherId == _cipherId);
|
||||
}
|
||||
public override IQueryable<CollectionCipher> Run(DatabaseContext dbContext)
|
||||
{
|
||||
var query = base.Run(dbContext);
|
||||
return query.Where(x => x.CipherId == _cipherId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,44 +1,43 @@
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Infrastructure.EntityFramework.Models;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries;
|
||||
|
||||
public class CollectionCipherReadByUserIdQuery : IQuery<CollectionCipher>
|
||||
{
|
||||
public class CollectionCipherReadByUserIdQuery : IQuery<CollectionCipher>
|
||||
private readonly Guid _userId;
|
||||
|
||||
public CollectionCipherReadByUserIdQuery(Guid userId)
|
||||
{
|
||||
private readonly Guid _userId;
|
||||
_userId = userId;
|
||||
}
|
||||
|
||||
public CollectionCipherReadByUserIdQuery(Guid userId)
|
||||
{
|
||||
_userId = userId;
|
||||
}
|
||||
|
||||
public virtual IQueryable<CollectionCipher> Run(DatabaseContext dbContext)
|
||||
{
|
||||
var query = from cc in dbContext.CollectionCiphers
|
||||
join c in dbContext.Collections
|
||||
on cc.CollectionId equals c.Id
|
||||
join ou in dbContext.OrganizationUsers
|
||||
on c.OrganizationId equals ou.OrganizationId
|
||||
where ou.UserId == _userId
|
||||
join cu in dbContext.CollectionUsers
|
||||
on c.Id equals cu.CollectionId into cu_g
|
||||
from cu in cu_g
|
||||
where ou.AccessAll && cu.OrganizationUserId == ou.Id
|
||||
join gu in dbContext.GroupUsers
|
||||
on ou.Id equals gu.OrganizationUserId into gu_g
|
||||
from gu in gu_g
|
||||
where cu.CollectionId == null && !ou.AccessAll
|
||||
join g in dbContext.Groups
|
||||
on gu.GroupId equals g.Id into g_g
|
||||
from g in g_g
|
||||
join cg in dbContext.CollectionGroups
|
||||
on cc.CollectionId equals cg.CollectionId into cg_g
|
||||
from cg in cg_g
|
||||
where g.AccessAll && cg.GroupId == gu.GroupId &&
|
||||
ou.Status == OrganizationUserStatusType.Confirmed &&
|
||||
(ou.AccessAll || cu.CollectionId != null || g.AccessAll || cg.CollectionId != null)
|
||||
select cc;
|
||||
return query;
|
||||
}
|
||||
public virtual IQueryable<CollectionCipher> Run(DatabaseContext dbContext)
|
||||
{
|
||||
var query = from cc in dbContext.CollectionCiphers
|
||||
join c in dbContext.Collections
|
||||
on cc.CollectionId equals c.Id
|
||||
join ou in dbContext.OrganizationUsers
|
||||
on c.OrganizationId equals ou.OrganizationId
|
||||
where ou.UserId == _userId
|
||||
join cu in dbContext.CollectionUsers
|
||||
on c.Id equals cu.CollectionId into cu_g
|
||||
from cu in cu_g
|
||||
where ou.AccessAll && cu.OrganizationUserId == ou.Id
|
||||
join gu in dbContext.GroupUsers
|
||||
on ou.Id equals gu.OrganizationUserId into gu_g
|
||||
from gu in gu_g
|
||||
where cu.CollectionId == null && !ou.AccessAll
|
||||
join g in dbContext.Groups
|
||||
on gu.GroupId equals g.Id into g_g
|
||||
from g in g_g
|
||||
join cg in dbContext.CollectionGroups
|
||||
on cc.CollectionId equals cg.CollectionId into cg_g
|
||||
from cg in cg_g
|
||||
where g.AccessAll && cg.GroupId == gu.GroupId &&
|
||||
ou.Status == OrganizationUserStatusType.Confirmed &&
|
||||
(ou.AccessAll || cu.CollectionId != null || g.AccessAll || cg.CollectionId != null)
|
||||
select cc;
|
||||
return query;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,22 +1,21 @@
|
||||
using Bit.Infrastructure.EntityFramework.Models;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries;
|
||||
|
||||
public class CollectionReadCountByOrganizationIdQuery : IQuery<Collection>
|
||||
{
|
||||
public class CollectionReadCountByOrganizationIdQuery : IQuery<Collection>
|
||||
private readonly Guid _organizationId;
|
||||
|
||||
public CollectionReadCountByOrganizationIdQuery(Guid organizationId)
|
||||
{
|
||||
private readonly Guid _organizationId;
|
||||
_organizationId = organizationId;
|
||||
}
|
||||
|
||||
public CollectionReadCountByOrganizationIdQuery(Guid organizationId)
|
||||
{
|
||||
_organizationId = organizationId;
|
||||
}
|
||||
|
||||
public IQueryable<Collection> Run(DatabaseContext dbContext)
|
||||
{
|
||||
var query = from c in dbContext.Collections
|
||||
where c.OrganizationId == _organizationId
|
||||
select c;
|
||||
return query;
|
||||
}
|
||||
public IQueryable<Collection> Run(DatabaseContext dbContext)
|
||||
{
|
||||
var query = from c in dbContext.Collections
|
||||
where c.OrganizationId == _organizationId
|
||||
select c;
|
||||
return query;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,116 +2,115 @@
|
||||
using Bit.Infrastructure.EntityFramework.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries;
|
||||
|
||||
public class CollectionUserUpdateUsersQuery
|
||||
{
|
||||
public class CollectionUserUpdateUsersQuery
|
||||
public readonly CollectionUserUpdateUsersInsertQuery Insert;
|
||||
public readonly CollectionUserUpdateUsersUpdateQuery Update;
|
||||
public readonly CollectionUserUpdateUsersDeleteQuery Delete;
|
||||
|
||||
public CollectionUserUpdateUsersQuery(Guid collectionId, IEnumerable<SelectionReadOnly> users)
|
||||
{
|
||||
public readonly CollectionUserUpdateUsersInsertQuery Insert;
|
||||
public readonly CollectionUserUpdateUsersUpdateQuery Update;
|
||||
public readonly CollectionUserUpdateUsersDeleteQuery Delete;
|
||||
|
||||
public CollectionUserUpdateUsersQuery(Guid collectionId, IEnumerable<SelectionReadOnly> users)
|
||||
{
|
||||
Insert = new CollectionUserUpdateUsersInsertQuery(collectionId, users);
|
||||
Update = new CollectionUserUpdateUsersUpdateQuery(collectionId, users);
|
||||
Delete = new CollectionUserUpdateUsersDeleteQuery(collectionId, users);
|
||||
}
|
||||
}
|
||||
|
||||
public class CollectionUserUpdateUsersInsertQuery : IQuery<OrganizationUser>
|
||||
{
|
||||
private readonly Guid _collectionId;
|
||||
private readonly IEnumerable<SelectionReadOnly> _users;
|
||||
|
||||
public CollectionUserUpdateUsersInsertQuery(Guid collectionId, IEnumerable<SelectionReadOnly> users)
|
||||
{
|
||||
_collectionId = collectionId;
|
||||
_users = users;
|
||||
}
|
||||
|
||||
public IQueryable<OrganizationUser> Run(DatabaseContext dbContext)
|
||||
{
|
||||
var orgId = dbContext.Collections.FirstOrDefault(c => c.Id == _collectionId)?.OrganizationId;
|
||||
var organizationUserIds = _users.Select(u => u.Id);
|
||||
var insertQuery = from ou in dbContext.OrganizationUsers
|
||||
where
|
||||
organizationUserIds.Contains(ou.Id) &&
|
||||
ou.OrganizationId == orgId &&
|
||||
!dbContext.CollectionUsers.Any(
|
||||
x => x.CollectionId != _collectionId && x.OrganizationUserId == ou.Id)
|
||||
select ou;
|
||||
return insertQuery;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<CollectionUser>> BuildInMemory(DatabaseContext dbContext)
|
||||
{
|
||||
var data = await Run(dbContext).ToListAsync();
|
||||
var collectionUsers = data.Select(x => new CollectionUser()
|
||||
{
|
||||
CollectionId = _collectionId,
|
||||
OrganizationUserId = x.Id,
|
||||
ReadOnly = _users.FirstOrDefault(u => u.Id.Equals(x.Id)).ReadOnly,
|
||||
HidePasswords = _users.FirstOrDefault(u => u.Id.Equals(x.Id)).HidePasswords,
|
||||
});
|
||||
return collectionUsers;
|
||||
}
|
||||
}
|
||||
|
||||
public class CollectionUserUpdateUsersUpdateQuery : IQuery<CollectionUser>
|
||||
{
|
||||
private readonly Guid _collectionId;
|
||||
private readonly IEnumerable<SelectionReadOnly> _users;
|
||||
|
||||
public CollectionUserUpdateUsersUpdateQuery(Guid collectionId, IEnumerable<SelectionReadOnly> users)
|
||||
{
|
||||
_collectionId = collectionId;
|
||||
_users = users;
|
||||
}
|
||||
|
||||
public IQueryable<CollectionUser> Run(DatabaseContext dbContext)
|
||||
{
|
||||
var orgId = dbContext.Collections.FirstOrDefault(c => c.Id == _collectionId)?.OrganizationId;
|
||||
var ids = _users.Select(x => x.Id);
|
||||
var updateQuery = from target in dbContext.CollectionUsers
|
||||
where target.CollectionId == _collectionId &&
|
||||
ids.Contains(target.OrganizationUserId)
|
||||
select target;
|
||||
return updateQuery;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<CollectionUser>> BuildInMemory(DatabaseContext dbContext)
|
||||
{
|
||||
var data = await Run(dbContext).ToListAsync();
|
||||
var collectionUsers = data.Select(x => new CollectionUser
|
||||
{
|
||||
CollectionId = _collectionId,
|
||||
OrganizationUserId = x.OrganizationUserId,
|
||||
ReadOnly = _users.FirstOrDefault(u => u.Id.Equals(x.OrganizationUserId)).ReadOnly,
|
||||
HidePasswords = _users.FirstOrDefault(u => u.Id.Equals(x.OrganizationUserId)).HidePasswords,
|
||||
});
|
||||
return collectionUsers;
|
||||
}
|
||||
}
|
||||
|
||||
public class CollectionUserUpdateUsersDeleteQuery : IQuery<CollectionUser>
|
||||
{
|
||||
private readonly Guid _collectionId;
|
||||
private readonly IEnumerable<SelectionReadOnly> _users;
|
||||
|
||||
public CollectionUserUpdateUsersDeleteQuery(Guid collectionId, IEnumerable<SelectionReadOnly> users)
|
||||
{
|
||||
_collectionId = collectionId;
|
||||
_users = users;
|
||||
}
|
||||
|
||||
public IQueryable<CollectionUser> Run(DatabaseContext dbContext)
|
||||
{
|
||||
var orgId = dbContext.Collections.FirstOrDefault(c => c.Id == _collectionId)?.OrganizationId;
|
||||
var deleteQuery = from cu in dbContext.CollectionUsers
|
||||
where !dbContext.Users.Any(
|
||||
u => u.Id == cu.OrganizationUserId)
|
||||
select cu;
|
||||
return deleteQuery;
|
||||
}
|
||||
Insert = new CollectionUserUpdateUsersInsertQuery(collectionId, users);
|
||||
Update = new CollectionUserUpdateUsersUpdateQuery(collectionId, users);
|
||||
Delete = new CollectionUserUpdateUsersDeleteQuery(collectionId, users);
|
||||
}
|
||||
}
|
||||
|
||||
public class CollectionUserUpdateUsersInsertQuery : IQuery<OrganizationUser>
|
||||
{
|
||||
private readonly Guid _collectionId;
|
||||
private readonly IEnumerable<SelectionReadOnly> _users;
|
||||
|
||||
public CollectionUserUpdateUsersInsertQuery(Guid collectionId, IEnumerable<SelectionReadOnly> users)
|
||||
{
|
||||
_collectionId = collectionId;
|
||||
_users = users;
|
||||
}
|
||||
|
||||
public IQueryable<OrganizationUser> Run(DatabaseContext dbContext)
|
||||
{
|
||||
var orgId = dbContext.Collections.FirstOrDefault(c => c.Id == _collectionId)?.OrganizationId;
|
||||
var organizationUserIds = _users.Select(u => u.Id);
|
||||
var insertQuery = from ou in dbContext.OrganizationUsers
|
||||
where
|
||||
organizationUserIds.Contains(ou.Id) &&
|
||||
ou.OrganizationId == orgId &&
|
||||
!dbContext.CollectionUsers.Any(
|
||||
x => x.CollectionId != _collectionId && x.OrganizationUserId == ou.Id)
|
||||
select ou;
|
||||
return insertQuery;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<CollectionUser>> BuildInMemory(DatabaseContext dbContext)
|
||||
{
|
||||
var data = await Run(dbContext).ToListAsync();
|
||||
var collectionUsers = data.Select(x => new CollectionUser()
|
||||
{
|
||||
CollectionId = _collectionId,
|
||||
OrganizationUserId = x.Id,
|
||||
ReadOnly = _users.FirstOrDefault(u => u.Id.Equals(x.Id)).ReadOnly,
|
||||
HidePasswords = _users.FirstOrDefault(u => u.Id.Equals(x.Id)).HidePasswords,
|
||||
});
|
||||
return collectionUsers;
|
||||
}
|
||||
}
|
||||
|
||||
public class CollectionUserUpdateUsersUpdateQuery : IQuery<CollectionUser>
|
||||
{
|
||||
private readonly Guid _collectionId;
|
||||
private readonly IEnumerable<SelectionReadOnly> _users;
|
||||
|
||||
public CollectionUserUpdateUsersUpdateQuery(Guid collectionId, IEnumerable<SelectionReadOnly> users)
|
||||
{
|
||||
_collectionId = collectionId;
|
||||
_users = users;
|
||||
}
|
||||
|
||||
public IQueryable<CollectionUser> Run(DatabaseContext dbContext)
|
||||
{
|
||||
var orgId = dbContext.Collections.FirstOrDefault(c => c.Id == _collectionId)?.OrganizationId;
|
||||
var ids = _users.Select(x => x.Id);
|
||||
var updateQuery = from target in dbContext.CollectionUsers
|
||||
where target.CollectionId == _collectionId &&
|
||||
ids.Contains(target.OrganizationUserId)
|
||||
select target;
|
||||
return updateQuery;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<CollectionUser>> BuildInMemory(DatabaseContext dbContext)
|
||||
{
|
||||
var data = await Run(dbContext).ToListAsync();
|
||||
var collectionUsers = data.Select(x => new CollectionUser
|
||||
{
|
||||
CollectionId = _collectionId,
|
||||
OrganizationUserId = x.OrganizationUserId,
|
||||
ReadOnly = _users.FirstOrDefault(u => u.Id.Equals(x.OrganizationUserId)).ReadOnly,
|
||||
HidePasswords = _users.FirstOrDefault(u => u.Id.Equals(x.OrganizationUserId)).HidePasswords,
|
||||
});
|
||||
return collectionUsers;
|
||||
}
|
||||
}
|
||||
|
||||
public class CollectionUserUpdateUsersDeleteQuery : IQuery<CollectionUser>
|
||||
{
|
||||
private readonly Guid _collectionId;
|
||||
private readonly IEnumerable<SelectionReadOnly> _users;
|
||||
|
||||
public CollectionUserUpdateUsersDeleteQuery(Guid collectionId, IEnumerable<SelectionReadOnly> users)
|
||||
{
|
||||
_collectionId = collectionId;
|
||||
_users = users;
|
||||
}
|
||||
|
||||
public IQueryable<CollectionUser> Run(DatabaseContext dbContext)
|
||||
{
|
||||
var orgId = dbContext.Collections.FirstOrDefault(c => c.Id == _collectionId)?.OrganizationId;
|
||||
var deleteQuery = from cu in dbContext.CollectionUsers
|
||||
where !dbContext.Users.Any(
|
||||
u => u.Id == cu.OrganizationUserId)
|
||||
select cu;
|
||||
return deleteQuery;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,38 +1,37 @@
|
||||
using Bit.Core.Models.Data;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries;
|
||||
|
||||
public class EmergencyAccessDetailsViewQuery : IQuery<EmergencyAccessDetails>
|
||||
{
|
||||
public class EmergencyAccessDetailsViewQuery : IQuery<EmergencyAccessDetails>
|
||||
public IQueryable<EmergencyAccessDetails> Run(DatabaseContext dbContext)
|
||||
{
|
||||
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
|
||||
{
|
||||
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,
|
||||
GrantorName = x.grantor.Name,
|
||||
GrantorEmail = x.grantor.Email,
|
||||
});
|
||||
}
|
||||
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,
|
||||
GrantorName = x.grantor.Name,
|
||||
GrantorEmail = x.grantor.Email,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,31 +1,30 @@
|
||||
using Bit.Infrastructure.EntityFramework.Models;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries;
|
||||
|
||||
public class EmergencyAccessReadCountByGrantorIdEmailQuery : IQuery<EmergencyAccess>
|
||||
{
|
||||
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)
|
||||
{
|
||||
private readonly Guid _grantorId;
|
||||
private readonly string _email;
|
||||
private readonly bool _onlyRegisteredUsers;
|
||||
_grantorId = grantorId;
|
||||
_email = email;
|
||||
_onlyRegisteredUsers = 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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,47 +2,46 @@
|
||||
using Bit.Core.Models.Data;
|
||||
using Event = Bit.Infrastructure.EntityFramework.Models.Event;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries;
|
||||
|
||||
public class EventReadPageByCipherIdQuery : IQuery<Event>
|
||||
{
|
||||
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)
|
||||
{
|
||||
private readonly Cipher _cipher;
|
||||
private readonly DateTime _startDate;
|
||||
private readonly DateTime _endDate;
|
||||
private readonly DateTime? _beforeDate;
|
||||
private readonly PageOptions _pageOptions;
|
||||
_cipher = cipher;
|
||||
_startDate = startDate;
|
||||
_endDate = endDate;
|
||||
_beforeDate = null;
|
||||
_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 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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,39 +1,38 @@
|
||||
using Bit.Core.Models.Data;
|
||||
using Bit.Infrastructure.EntityFramework.Models;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries;
|
||||
|
||||
public class EventReadPageByOrganizationIdActingUserIdQuery : IQuery<Event>
|
||||
{
|
||||
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)
|
||||
{
|
||||
private readonly Guid _organizationId;
|
||||
private readonly Guid _actingUserId;
|
||||
private readonly DateTime _startDate;
|
||||
private readonly DateTime _endDate;
|
||||
private readonly DateTime? _beforeDate;
|
||||
private readonly PageOptions _pageOptions;
|
||||
_organizationId = organizationId;
|
||||
_actingUserId = actingUserId;
|
||||
_startDate = startDate;
|
||||
_endDate = endDate;
|
||||
_beforeDate = beforeDate;
|
||||
_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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,36 +1,35 @@
|
||||
using Bit.Core.Models.Data;
|
||||
using Bit.Infrastructure.EntityFramework.Models;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries;
|
||||
|
||||
public class EventReadPageByOrganizationIdQuery : IQuery<Event>
|
||||
{
|
||||
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)
|
||||
{
|
||||
private readonly Guid _organizationId;
|
||||
private readonly DateTime _startDate;
|
||||
private readonly DateTime _endDate;
|
||||
private readonly DateTime? _beforeDate;
|
||||
private readonly PageOptions _pageOptions;
|
||||
_organizationId = organizationId;
|
||||
_startDate = startDate;
|
||||
_endDate = endDate;
|
||||
_beforeDate = beforeDate;
|
||||
_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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,39 +1,38 @@
|
||||
using Bit.Core.Models.Data;
|
||||
using Bit.Infrastructure.EntityFramework.Models;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries;
|
||||
|
||||
public class EventReadPageByProviderIdActingUserIdQuery : IQuery<Event>
|
||||
{
|
||||
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)
|
||||
{
|
||||
private readonly Guid _providerId;
|
||||
private readonly Guid _actingUserId;
|
||||
private readonly DateTime _startDate;
|
||||
private readonly DateTime _endDate;
|
||||
private readonly DateTime? _beforeDate;
|
||||
private readonly PageOptions _pageOptions;
|
||||
_providerId = providerId;
|
||||
_actingUserId = actingUserId;
|
||||
_startDate = startDate;
|
||||
_endDate = endDate;
|
||||
_beforeDate = beforeDate;
|
||||
_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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,36 +1,35 @@
|
||||
using Bit.Core.Models.Data;
|
||||
using Bit.Infrastructure.EntityFramework.Models;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries;
|
||||
|
||||
public class EventReadPageByProviderIdQuery : IQuery<Event>
|
||||
{
|
||||
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)
|
||||
{
|
||||
private readonly Guid _providerId;
|
||||
private readonly DateTime _startDate;
|
||||
private readonly DateTime _endDate;
|
||||
private readonly DateTime? _beforeDate;
|
||||
private readonly PageOptions _pageOptions;
|
||||
_providerId = providerId;
|
||||
_startDate = startDate;
|
||||
_endDate = endDate;
|
||||
_beforeDate = beforeDate;
|
||||
_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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,37 +1,36 @@
|
||||
using Bit.Core.Models.Data;
|
||||
using Bit.Infrastructure.EntityFramework.Models;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries;
|
||||
|
||||
public class EventReadPageByUserIdQuery : IQuery<Event>
|
||||
{
|
||||
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)
|
||||
{
|
||||
private readonly Guid _userId;
|
||||
private readonly DateTime _startDate;
|
||||
private readonly DateTime _endDate;
|
||||
private readonly DateTime? _beforeDate;
|
||||
private readonly PageOptions _pageOptions;
|
||||
_userId = userId;
|
||||
_startDate = startDate;
|
||||
_endDate = endDate;
|
||||
_beforeDate = beforeDate;
|
||||
_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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,69 +1,68 @@
|
||||
using Bit.Infrastructure.EntityFramework.Models;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries;
|
||||
|
||||
public class GroupUserUpdateGroupsQuery
|
||||
{
|
||||
public class GroupUserUpdateGroupsQuery
|
||||
public readonly GroupUserUpdateGroupsInsertQuery Insert;
|
||||
public readonly GroupUserUpdateGroupsDeleteQuery Delete;
|
||||
|
||||
public GroupUserUpdateGroupsQuery(Guid organizationUserId, IEnumerable<Guid> groupIds)
|
||||
{
|
||||
public readonly GroupUserUpdateGroupsInsertQuery Insert;
|
||||
public readonly GroupUserUpdateGroupsDeleteQuery Delete;
|
||||
|
||||
public GroupUserUpdateGroupsQuery(Guid organizationUserId, IEnumerable<Guid> groupIds)
|
||||
{
|
||||
Insert = new GroupUserUpdateGroupsInsertQuery(organizationUserId, groupIds);
|
||||
Delete = new GroupUserUpdateGroupsDeleteQuery(organizationUserId, groupIds);
|
||||
}
|
||||
}
|
||||
|
||||
public class GroupUserUpdateGroupsInsertQuery : IQuery<GroupUser>
|
||||
{
|
||||
private readonly Guid _organizationUserId;
|
||||
private readonly IEnumerable<Guid> _groupIds;
|
||||
|
||||
public GroupUserUpdateGroupsInsertQuery(Guid organizationUserId, IEnumerable<Guid> collections)
|
||||
{
|
||||
_organizationUserId = organizationUserId;
|
||||
_groupIds = collections;
|
||||
}
|
||||
|
||||
public IQueryable<GroupUser> Run(DatabaseContext dbContext)
|
||||
{
|
||||
var orgUser = from ou in dbContext.OrganizationUsers
|
||||
where ou.Id == _organizationUserId
|
||||
select ou;
|
||||
var groupIdEntities = dbContext.Groups.Where(x => _groupIds.Contains(x.Id));
|
||||
var query = from g in dbContext.Groups
|
||||
join ou in orgUser
|
||||
on g.OrganizationId equals ou.OrganizationId
|
||||
join gie in groupIdEntities
|
||||
on g.Id equals gie.Id
|
||||
where !dbContext.GroupUsers.Any(gu => _groupIds.Contains(gu.GroupId) && gu.OrganizationUserId == _organizationUserId)
|
||||
select g;
|
||||
return query.Select(x => new GroupUser
|
||||
{
|
||||
GroupId = x.Id,
|
||||
OrganizationUserId = _organizationUserId,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public class GroupUserUpdateGroupsDeleteQuery : IQuery<GroupUser>
|
||||
{
|
||||
private readonly Guid _organizationUserId;
|
||||
private readonly IEnumerable<Guid> _groupIds;
|
||||
|
||||
public GroupUserUpdateGroupsDeleteQuery(Guid organizationUserId, IEnumerable<Guid> groupIds)
|
||||
{
|
||||
_organizationUserId = organizationUserId;
|
||||
_groupIds = groupIds;
|
||||
}
|
||||
|
||||
public IQueryable<GroupUser> Run(DatabaseContext dbContext)
|
||||
{
|
||||
var deleteQuery = from gu in dbContext.GroupUsers
|
||||
where gu.OrganizationUserId == _organizationUserId &&
|
||||
!_groupIds.Any(x => gu.GroupId == x)
|
||||
select gu;
|
||||
return deleteQuery;
|
||||
}
|
||||
Insert = new GroupUserUpdateGroupsInsertQuery(organizationUserId, groupIds);
|
||||
Delete = new GroupUserUpdateGroupsDeleteQuery(organizationUserId, groupIds);
|
||||
}
|
||||
}
|
||||
|
||||
public class GroupUserUpdateGroupsInsertQuery : IQuery<GroupUser>
|
||||
{
|
||||
private readonly Guid _organizationUserId;
|
||||
private readonly IEnumerable<Guid> _groupIds;
|
||||
|
||||
public GroupUserUpdateGroupsInsertQuery(Guid organizationUserId, IEnumerable<Guid> collections)
|
||||
{
|
||||
_organizationUserId = organizationUserId;
|
||||
_groupIds = collections;
|
||||
}
|
||||
|
||||
public IQueryable<GroupUser> Run(DatabaseContext dbContext)
|
||||
{
|
||||
var orgUser = from ou in dbContext.OrganizationUsers
|
||||
where ou.Id == _organizationUserId
|
||||
select ou;
|
||||
var groupIdEntities = dbContext.Groups.Where(x => _groupIds.Contains(x.Id));
|
||||
var query = from g in dbContext.Groups
|
||||
join ou in orgUser
|
||||
on g.OrganizationId equals ou.OrganizationId
|
||||
join gie in groupIdEntities
|
||||
on g.Id equals gie.Id
|
||||
where !dbContext.GroupUsers.Any(gu => _groupIds.Contains(gu.GroupId) && gu.OrganizationUserId == _organizationUserId)
|
||||
select g;
|
||||
return query.Select(x => new GroupUser
|
||||
{
|
||||
GroupId = x.Id,
|
||||
OrganizationUserId = _organizationUserId,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public class GroupUserUpdateGroupsDeleteQuery : IQuery<GroupUser>
|
||||
{
|
||||
private readonly Guid _organizationUserId;
|
||||
private readonly IEnumerable<Guid> _groupIds;
|
||||
|
||||
public GroupUserUpdateGroupsDeleteQuery(Guid organizationUserId, IEnumerable<Guid> groupIds)
|
||||
{
|
||||
_organizationUserId = organizationUserId;
|
||||
_groupIds = groupIds;
|
||||
}
|
||||
|
||||
public IQueryable<GroupUser> Run(DatabaseContext dbContext)
|
||||
{
|
||||
var deleteQuery = from gu in dbContext.GroupUsers
|
||||
where gu.OrganizationUserId == _organizationUserId &&
|
||||
!_groupIds.Any(x => gu.GroupId == x)
|
||||
select gu;
|
||||
return deleteQuery;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries;
|
||||
|
||||
public interface IQuery<TOut>
|
||||
{
|
||||
public interface IQuery<TOut>
|
||||
{
|
||||
IQueryable<TOut> Run(DatabaseContext dbContext);
|
||||
}
|
||||
IQueryable<TOut> Run(DatabaseContext dbContext);
|
||||
}
|
||||
|
||||
@@ -1,65 +1,64 @@
|
||||
using Bit.Core.Models.Data.Organizations.OrganizationUsers;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries
|
||||
{
|
||||
public class OrganizationUserOrganizationDetailsViewQuery : IQuery<OrganizationUserOrganizationDetails>
|
||||
{
|
||||
public IQueryable<OrganizationUserOrganizationDetails> Run(DatabaseContext dbContext)
|
||||
{
|
||||
var query = from ou in dbContext.OrganizationUsers
|
||||
join o in dbContext.Organizations on ou.OrganizationId equals o.Id
|
||||
join su in dbContext.SsoUsers on ou.UserId equals su.UserId into su_g
|
||||
from su in su_g.DefaultIfEmpty()
|
||||
join po in dbContext.ProviderOrganizations on o.Id equals po.OrganizationId into po_g
|
||||
from po in po_g.DefaultIfEmpty()
|
||||
join p in dbContext.Providers on po.ProviderId equals p.Id into p_g
|
||||
from p in p_g.DefaultIfEmpty()
|
||||
join os in dbContext.OrganizationSponsorships on ou.Id equals os.SponsoringOrganizationUserId into os_g
|
||||
from os in os_g.DefaultIfEmpty()
|
||||
join ss in dbContext.SsoConfigs on ou.OrganizationId equals ss.OrganizationId into ss_g
|
||||
from ss in ss_g.DefaultIfEmpty()
|
||||
where ((su == null || !su.OrganizationId.HasValue) || su.OrganizationId == ou.OrganizationId)
|
||||
select new { ou, o, su, p, ss, os };
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries;
|
||||
|
||||
return query.Select(x => new OrganizationUserOrganizationDetails
|
||||
{
|
||||
OrganizationId = x.ou.OrganizationId,
|
||||
UserId = x.ou.UserId,
|
||||
Name = x.o.Name,
|
||||
Enabled = x.o.Enabled,
|
||||
PlanType = x.o.PlanType,
|
||||
UsePolicies = x.o.UsePolicies,
|
||||
UseSso = x.o.UseSso,
|
||||
UseKeyConnector = x.o.UseKeyConnector,
|
||||
UseScim = x.o.UseScim,
|
||||
UseGroups = x.o.UseGroups,
|
||||
UseDirectory = x.o.UseDirectory,
|
||||
UseEvents = x.o.UseEvents,
|
||||
UseTotp = x.o.UseTotp,
|
||||
Use2fa = x.o.Use2fa,
|
||||
UseApi = x.o.UseApi,
|
||||
SelfHost = x.o.SelfHost,
|
||||
UsersGetPremium = x.o.UsersGetPremium,
|
||||
Seats = x.o.Seats,
|
||||
MaxCollections = x.o.MaxCollections,
|
||||
MaxStorageGb = x.o.MaxStorageGb,
|
||||
Identifier = x.o.Identifier,
|
||||
Key = x.ou.Key,
|
||||
ResetPasswordKey = x.ou.ResetPasswordKey,
|
||||
Status = x.ou.Status,
|
||||
Type = x.ou.Type,
|
||||
SsoExternalId = x.su.ExternalId,
|
||||
Permissions = x.ou.Permissions,
|
||||
PublicKey = x.o.PublicKey,
|
||||
PrivateKey = x.o.PrivateKey,
|
||||
ProviderId = x.p.Id,
|
||||
ProviderName = x.p.Name,
|
||||
SsoConfig = x.ss.Data,
|
||||
FamilySponsorshipFriendlyName = x.os.FriendlyName,
|
||||
FamilySponsorshipLastSyncDate = x.os.LastSyncDate,
|
||||
FamilySponsorshipToDelete = x.os.ToDelete,
|
||||
FamilySponsorshipValidUntil = x.os.ValidUntil
|
||||
});
|
||||
}
|
||||
public class OrganizationUserOrganizationDetailsViewQuery : IQuery<OrganizationUserOrganizationDetails>
|
||||
{
|
||||
public IQueryable<OrganizationUserOrganizationDetails> Run(DatabaseContext dbContext)
|
||||
{
|
||||
var query = from ou in dbContext.OrganizationUsers
|
||||
join o in dbContext.Organizations on ou.OrganizationId equals o.Id
|
||||
join su in dbContext.SsoUsers on ou.UserId equals su.UserId into su_g
|
||||
from su in su_g.DefaultIfEmpty()
|
||||
join po in dbContext.ProviderOrganizations on o.Id equals po.OrganizationId into po_g
|
||||
from po in po_g.DefaultIfEmpty()
|
||||
join p in dbContext.Providers on po.ProviderId equals p.Id into p_g
|
||||
from p in p_g.DefaultIfEmpty()
|
||||
join os in dbContext.OrganizationSponsorships on ou.Id equals os.SponsoringOrganizationUserId into os_g
|
||||
from os in os_g.DefaultIfEmpty()
|
||||
join ss in dbContext.SsoConfigs on ou.OrganizationId equals ss.OrganizationId into ss_g
|
||||
from ss in ss_g.DefaultIfEmpty()
|
||||
where ((su == null || !su.OrganizationId.HasValue) || su.OrganizationId == ou.OrganizationId)
|
||||
select new { ou, o, su, p, ss, os };
|
||||
|
||||
return query.Select(x => new OrganizationUserOrganizationDetails
|
||||
{
|
||||
OrganizationId = x.ou.OrganizationId,
|
||||
UserId = x.ou.UserId,
|
||||
Name = x.o.Name,
|
||||
Enabled = x.o.Enabled,
|
||||
PlanType = x.o.PlanType,
|
||||
UsePolicies = x.o.UsePolicies,
|
||||
UseSso = x.o.UseSso,
|
||||
UseKeyConnector = x.o.UseKeyConnector,
|
||||
UseScim = x.o.UseScim,
|
||||
UseGroups = x.o.UseGroups,
|
||||
UseDirectory = x.o.UseDirectory,
|
||||
UseEvents = x.o.UseEvents,
|
||||
UseTotp = x.o.UseTotp,
|
||||
Use2fa = x.o.Use2fa,
|
||||
UseApi = x.o.UseApi,
|
||||
SelfHost = x.o.SelfHost,
|
||||
UsersGetPremium = x.o.UsersGetPremium,
|
||||
Seats = x.o.Seats,
|
||||
MaxCollections = x.o.MaxCollections,
|
||||
MaxStorageGb = x.o.MaxStorageGb,
|
||||
Identifier = x.o.Identifier,
|
||||
Key = x.ou.Key,
|
||||
ResetPasswordKey = x.ou.ResetPasswordKey,
|
||||
Status = x.ou.Status,
|
||||
Type = x.ou.Type,
|
||||
SsoExternalId = x.su.ExternalId,
|
||||
Permissions = x.ou.Permissions,
|
||||
PublicKey = x.o.PublicKey,
|
||||
PrivateKey = x.o.PrivateKey,
|
||||
ProviderId = x.p.Id,
|
||||
ProviderName = x.p.Name,
|
||||
SsoConfig = x.ss.Data,
|
||||
FamilySponsorshipFriendlyName = x.os.FriendlyName,
|
||||
FamilySponsorshipLastSyncDate = x.os.LastSyncDate,
|
||||
FamilySponsorshipToDelete = x.os.ToDelete,
|
||||
FamilySponsorshipValidUntil = x.os.ValidUntil
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,29 +1,28 @@
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Infrastructure.EntityFramework.Models;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries;
|
||||
|
||||
public class OrganizationUserReadCountByFreeOrganizationAdminUserQuery : IQuery<OrganizationUser>
|
||||
{
|
||||
public class OrganizationUserReadCountByFreeOrganizationAdminUserQuery : IQuery<OrganizationUser>
|
||||
private readonly Guid _userId;
|
||||
|
||||
public OrganizationUserReadCountByFreeOrganizationAdminUserQuery(Guid userId)
|
||||
{
|
||||
private readonly Guid _userId;
|
||||
_userId = userId;
|
||||
}
|
||||
|
||||
public OrganizationUserReadCountByFreeOrganizationAdminUserQuery(Guid userId)
|
||||
{
|
||||
_userId = userId;
|
||||
}
|
||||
public IQueryable<OrganizationUser> Run(DatabaseContext dbContext)
|
||||
{
|
||||
var query = from ou in dbContext.OrganizationUsers
|
||||
join o in dbContext.Organizations
|
||||
on ou.OrganizationId equals o.Id
|
||||
where ou.UserId == _userId &&
|
||||
(ou.Type == OrganizationUserType.Owner || ou.Type == OrganizationUserType.Admin) &&
|
||||
o.PlanType == PlanType.Free &&
|
||||
ou.Status == OrganizationUserStatusType.Confirmed
|
||||
select ou;
|
||||
|
||||
public IQueryable<OrganizationUser> Run(DatabaseContext dbContext)
|
||||
{
|
||||
var query = from ou in dbContext.OrganizationUsers
|
||||
join o in dbContext.Organizations
|
||||
on ou.OrganizationId equals o.Id
|
||||
where ou.UserId == _userId &&
|
||||
(ou.Type == OrganizationUserType.Owner || ou.Type == OrganizationUserType.Admin) &&
|
||||
o.PlanType == PlanType.Free &&
|
||||
ou.Status == OrganizationUserStatusType.Confirmed
|
||||
select ou;
|
||||
|
||||
return query;
|
||||
}
|
||||
return query;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,37 +1,36 @@
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Infrastructure.EntityFramework.Models;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries;
|
||||
|
||||
public class OrganizationUserReadCountByOnlyOwnerQuery : IQuery<OrganizationUser>
|
||||
{
|
||||
public class OrganizationUserReadCountByOnlyOwnerQuery : IQuery<OrganizationUser>
|
||||
private readonly Guid _userId;
|
||||
|
||||
public OrganizationUserReadCountByOnlyOwnerQuery(Guid userId)
|
||||
{
|
||||
private readonly Guid _userId;
|
||||
_userId = userId;
|
||||
}
|
||||
|
||||
public OrganizationUserReadCountByOnlyOwnerQuery(Guid userId)
|
||||
{
|
||||
_userId = userId;
|
||||
}
|
||||
public IQueryable<OrganizationUser> Run(DatabaseContext dbContext)
|
||||
{
|
||||
var owners = from ou in dbContext.OrganizationUsers
|
||||
where ou.Type == OrganizationUserType.Owner &&
|
||||
ou.Status == OrganizationUserStatusType.Confirmed
|
||||
group ou by ou.OrganizationId into g
|
||||
select new
|
||||
{
|
||||
OrgUser = g.Select(x => new { x.UserId, x.Id }).FirstOrDefault(),
|
||||
ConfirmedOwnerCount = g.Count(),
|
||||
};
|
||||
|
||||
public IQueryable<OrganizationUser> Run(DatabaseContext dbContext)
|
||||
{
|
||||
var owners = from ou in dbContext.OrganizationUsers
|
||||
where ou.Type == OrganizationUserType.Owner &&
|
||||
ou.Status == OrganizationUserStatusType.Confirmed
|
||||
group ou by ou.OrganizationId into g
|
||||
select new
|
||||
{
|
||||
OrgUser = g.Select(x => new { x.UserId, x.Id }).FirstOrDefault(),
|
||||
ConfirmedOwnerCount = g.Count(),
|
||||
};
|
||||
var query = from owner in owners
|
||||
join ou in dbContext.OrganizationUsers
|
||||
on owner.OrgUser.Id equals ou.Id
|
||||
where owner.OrgUser.UserId == _userId &&
|
||||
owner.ConfirmedOwnerCount == 1
|
||||
select ou;
|
||||
|
||||
var query = from owner in owners
|
||||
join ou in dbContext.OrganizationUsers
|
||||
on owner.OrgUser.Id equals ou.Id
|
||||
where owner.OrgUser.UserId == _userId &&
|
||||
owner.ConfirmedOwnerCount == 1
|
||||
select ou;
|
||||
|
||||
return query;
|
||||
}
|
||||
return query;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,31 +1,30 @@
|
||||
using Bit.Infrastructure.EntityFramework.Models;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries;
|
||||
|
||||
public class OrganizationUserReadCountByOrganizationIdEmailQuery : IQuery<OrganizationUser>
|
||||
{
|
||||
public class OrganizationUserReadCountByOrganizationIdEmailQuery : IQuery<OrganizationUser>
|
||||
private readonly Guid _organizationId;
|
||||
private readonly string _email;
|
||||
private readonly bool _onlyUsers;
|
||||
|
||||
public OrganizationUserReadCountByOrganizationIdEmailQuery(Guid organizationId, string email, bool onlyUsers)
|
||||
{
|
||||
private readonly Guid _organizationId;
|
||||
private readonly string _email;
|
||||
private readonly bool _onlyUsers;
|
||||
_organizationId = organizationId;
|
||||
_email = email;
|
||||
_onlyUsers = onlyUsers;
|
||||
}
|
||||
|
||||
public OrganizationUserReadCountByOrganizationIdEmailQuery(Guid organizationId, string email, bool onlyUsers)
|
||||
{
|
||||
_organizationId = organizationId;
|
||||
_email = email;
|
||||
_onlyUsers = onlyUsers;
|
||||
}
|
||||
|
||||
public IQueryable<OrganizationUser> Run(DatabaseContext dbContext)
|
||||
{
|
||||
var query = from ou in dbContext.OrganizationUsers
|
||||
join u in dbContext.Users
|
||||
on ou.UserId equals u.Id into u_g
|
||||
from u in u_g.DefaultIfEmpty()
|
||||
where ou.OrganizationId == _organizationId &&
|
||||
((!_onlyUsers && (ou.Email == _email || u.Email == _email))
|
||||
|| (_onlyUsers && u.Email == _email))
|
||||
select ou;
|
||||
return query;
|
||||
}
|
||||
public IQueryable<OrganizationUser> Run(DatabaseContext dbContext)
|
||||
{
|
||||
var query = from ou in dbContext.OrganizationUsers
|
||||
join u in dbContext.Users
|
||||
on ou.UserId equals u.Id into u_g
|
||||
from u in u_g.DefaultIfEmpty()
|
||||
where ou.OrganizationId == _organizationId &&
|
||||
((!_onlyUsers && (ou.Email == _email || u.Email == _email))
|
||||
|| (_onlyUsers && u.Email == _email))
|
||||
select ou;
|
||||
return query;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,22 +1,21 @@
|
||||
using Bit.Infrastructure.EntityFramework.Models;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries;
|
||||
|
||||
public class OrganizationUserReadCountByOrganizationIdQuery : IQuery<OrganizationUser>
|
||||
{
|
||||
public class OrganizationUserReadCountByOrganizationIdQuery : IQuery<OrganizationUser>
|
||||
private readonly Guid _organizationId;
|
||||
|
||||
public OrganizationUserReadCountByOrganizationIdQuery(Guid organizationId)
|
||||
{
|
||||
private readonly Guid _organizationId;
|
||||
_organizationId = organizationId;
|
||||
}
|
||||
|
||||
public OrganizationUserReadCountByOrganizationIdQuery(Guid organizationId)
|
||||
{
|
||||
_organizationId = organizationId;
|
||||
}
|
||||
|
||||
public IQueryable<OrganizationUser> Run(DatabaseContext dbContext)
|
||||
{
|
||||
var query = from ou in dbContext.OrganizationUsers
|
||||
where ou.OrganizationId == _organizationId
|
||||
select ou;
|
||||
return query;
|
||||
}
|
||||
public IQueryable<OrganizationUser> Run(DatabaseContext dbContext)
|
||||
{
|
||||
var query = from ou in dbContext.OrganizationUsers
|
||||
where ou.OrganizationId == _organizationId
|
||||
select ou;
|
||||
return query;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,105 +2,104 @@
|
||||
using Bit.Core.Models.Data;
|
||||
using CollectionUser = Bit.Infrastructure.EntityFramework.Models.CollectionUser;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries;
|
||||
|
||||
public class OrganizationUserUpdateWithCollectionsQuery
|
||||
{
|
||||
public class OrganizationUserUpdateWithCollectionsQuery
|
||||
public OrganizationUserUpdateWithCollectionsInsertQuery Insert { get; set; }
|
||||
public OrganizationUserUpdateWithCollectionsUpdateQuery Update { get; set; }
|
||||
public OrganizationUserUpdateWithCollectionsDeleteQuery Delete { get; set; }
|
||||
|
||||
public OrganizationUserUpdateWithCollectionsQuery(OrganizationUser organizationUser,
|
||||
IEnumerable<SelectionReadOnly> collections)
|
||||
{
|
||||
public OrganizationUserUpdateWithCollectionsInsertQuery Insert { get; set; }
|
||||
public OrganizationUserUpdateWithCollectionsUpdateQuery Update { get; set; }
|
||||
public OrganizationUserUpdateWithCollectionsDeleteQuery Delete { get; set; }
|
||||
|
||||
public OrganizationUserUpdateWithCollectionsQuery(OrganizationUser organizationUser,
|
||||
IEnumerable<SelectionReadOnly> collections)
|
||||
{
|
||||
Insert = new OrganizationUserUpdateWithCollectionsInsertQuery(organizationUser, collections);
|
||||
Update = new OrganizationUserUpdateWithCollectionsUpdateQuery(organizationUser, collections);
|
||||
Delete = new OrganizationUserUpdateWithCollectionsDeleteQuery(organizationUser, collections);
|
||||
}
|
||||
}
|
||||
|
||||
public class OrganizationUserUpdateWithCollectionsInsertQuery : IQuery<CollectionUser>
|
||||
{
|
||||
private readonly OrganizationUser _organizationUser;
|
||||
private readonly IEnumerable<SelectionReadOnly> _collections;
|
||||
|
||||
public OrganizationUserUpdateWithCollectionsInsertQuery(OrganizationUser organizationUser, IEnumerable<SelectionReadOnly> collections)
|
||||
{
|
||||
_organizationUser = organizationUser;
|
||||
_collections = collections;
|
||||
}
|
||||
|
||||
public IQueryable<CollectionUser> Run(DatabaseContext dbContext)
|
||||
{
|
||||
var collectionIds = _collections.Select(c => c.Id).ToArray();
|
||||
var t = (from cu in dbContext.CollectionUsers
|
||||
where collectionIds.Contains(cu.CollectionId) &&
|
||||
cu.OrganizationUserId == _organizationUser.Id
|
||||
select cu).AsEnumerable();
|
||||
var insertQuery = (from c in dbContext.Collections
|
||||
where collectionIds.Contains(c.Id) &&
|
||||
c.OrganizationId == _organizationUser.OrganizationId &&
|
||||
!t.Any()
|
||||
select c).AsEnumerable();
|
||||
return insertQuery.Select(x => new CollectionUser
|
||||
{
|
||||
CollectionId = x.Id,
|
||||
OrganizationUserId = _organizationUser.Id,
|
||||
ReadOnly = _collections.FirstOrDefault(c => c.Id == x.Id).ReadOnly,
|
||||
HidePasswords = _collections.FirstOrDefault(c => c.Id == x.Id).HidePasswords,
|
||||
}).AsQueryable();
|
||||
}
|
||||
}
|
||||
|
||||
public class OrganizationUserUpdateWithCollectionsUpdateQuery : IQuery<CollectionUser>
|
||||
{
|
||||
private readonly OrganizationUser _organizationUser;
|
||||
private readonly IEnumerable<SelectionReadOnly> _collections;
|
||||
|
||||
public OrganizationUserUpdateWithCollectionsUpdateQuery(OrganizationUser organizationUser, IEnumerable<SelectionReadOnly> collections)
|
||||
{
|
||||
_organizationUser = organizationUser;
|
||||
_collections = collections;
|
||||
}
|
||||
|
||||
public IQueryable<CollectionUser> Run(DatabaseContext dbContext)
|
||||
{
|
||||
var collectionIds = _collections.Select(c => c.Id).ToArray();
|
||||
var updateQuery = (from target in dbContext.CollectionUsers
|
||||
where collectionIds.Contains(target.CollectionId) &&
|
||||
target.OrganizationUserId == _organizationUser.Id
|
||||
select new { target }).AsEnumerable();
|
||||
updateQuery = updateQuery.Where(cu =>
|
||||
cu.target.ReadOnly == _collections.FirstOrDefault(u => u.Id == cu.target.CollectionId).ReadOnly &&
|
||||
cu.target.HidePasswords == _collections.FirstOrDefault(u => u.Id == cu.target.CollectionId).HidePasswords);
|
||||
return updateQuery.Select(x => new CollectionUser
|
||||
{
|
||||
CollectionId = x.target.CollectionId,
|
||||
OrganizationUserId = _organizationUser.Id,
|
||||
ReadOnly = x.target.ReadOnly,
|
||||
HidePasswords = x.target.HidePasswords,
|
||||
}).AsQueryable();
|
||||
}
|
||||
}
|
||||
|
||||
public class OrganizationUserUpdateWithCollectionsDeleteQuery : IQuery<CollectionUser>
|
||||
{
|
||||
private readonly OrganizationUser _organizationUser;
|
||||
private readonly IEnumerable<SelectionReadOnly> _collections;
|
||||
|
||||
public OrganizationUserUpdateWithCollectionsDeleteQuery(OrganizationUser organizationUser, IEnumerable<SelectionReadOnly> collections)
|
||||
{
|
||||
_organizationUser = organizationUser;
|
||||
_collections = collections;
|
||||
}
|
||||
|
||||
public IQueryable<CollectionUser> Run(DatabaseContext dbContext)
|
||||
{
|
||||
var deleteQuery = from cu in dbContext.CollectionUsers
|
||||
where !_collections.Any(
|
||||
c => c.Id == cu.CollectionId)
|
||||
select cu;
|
||||
return deleteQuery;
|
||||
}
|
||||
Insert = new OrganizationUserUpdateWithCollectionsInsertQuery(organizationUser, collections);
|
||||
Update = new OrganizationUserUpdateWithCollectionsUpdateQuery(organizationUser, collections);
|
||||
Delete = new OrganizationUserUpdateWithCollectionsDeleteQuery(organizationUser, collections);
|
||||
}
|
||||
}
|
||||
|
||||
public class OrganizationUserUpdateWithCollectionsInsertQuery : IQuery<CollectionUser>
|
||||
{
|
||||
private readonly OrganizationUser _organizationUser;
|
||||
private readonly IEnumerable<SelectionReadOnly> _collections;
|
||||
|
||||
public OrganizationUserUpdateWithCollectionsInsertQuery(OrganizationUser organizationUser, IEnumerable<SelectionReadOnly> collections)
|
||||
{
|
||||
_organizationUser = organizationUser;
|
||||
_collections = collections;
|
||||
}
|
||||
|
||||
public IQueryable<CollectionUser> Run(DatabaseContext dbContext)
|
||||
{
|
||||
var collectionIds = _collections.Select(c => c.Id).ToArray();
|
||||
var t = (from cu in dbContext.CollectionUsers
|
||||
where collectionIds.Contains(cu.CollectionId) &&
|
||||
cu.OrganizationUserId == _organizationUser.Id
|
||||
select cu).AsEnumerable();
|
||||
var insertQuery = (from c in dbContext.Collections
|
||||
where collectionIds.Contains(c.Id) &&
|
||||
c.OrganizationId == _organizationUser.OrganizationId &&
|
||||
!t.Any()
|
||||
select c).AsEnumerable();
|
||||
return insertQuery.Select(x => new CollectionUser
|
||||
{
|
||||
CollectionId = x.Id,
|
||||
OrganizationUserId = _organizationUser.Id,
|
||||
ReadOnly = _collections.FirstOrDefault(c => c.Id == x.Id).ReadOnly,
|
||||
HidePasswords = _collections.FirstOrDefault(c => c.Id == x.Id).HidePasswords,
|
||||
}).AsQueryable();
|
||||
}
|
||||
}
|
||||
|
||||
public class OrganizationUserUpdateWithCollectionsUpdateQuery : IQuery<CollectionUser>
|
||||
{
|
||||
private readonly OrganizationUser _organizationUser;
|
||||
private readonly IEnumerable<SelectionReadOnly> _collections;
|
||||
|
||||
public OrganizationUserUpdateWithCollectionsUpdateQuery(OrganizationUser organizationUser, IEnumerable<SelectionReadOnly> collections)
|
||||
{
|
||||
_organizationUser = organizationUser;
|
||||
_collections = collections;
|
||||
}
|
||||
|
||||
public IQueryable<CollectionUser> Run(DatabaseContext dbContext)
|
||||
{
|
||||
var collectionIds = _collections.Select(c => c.Id).ToArray();
|
||||
var updateQuery = (from target in dbContext.CollectionUsers
|
||||
where collectionIds.Contains(target.CollectionId) &&
|
||||
target.OrganizationUserId == _organizationUser.Id
|
||||
select new { target }).AsEnumerable();
|
||||
updateQuery = updateQuery.Where(cu =>
|
||||
cu.target.ReadOnly == _collections.FirstOrDefault(u => u.Id == cu.target.CollectionId).ReadOnly &&
|
||||
cu.target.HidePasswords == _collections.FirstOrDefault(u => u.Id == cu.target.CollectionId).HidePasswords);
|
||||
return updateQuery.Select(x => new CollectionUser
|
||||
{
|
||||
CollectionId = x.target.CollectionId,
|
||||
OrganizationUserId = _organizationUser.Id,
|
||||
ReadOnly = x.target.ReadOnly,
|
||||
HidePasswords = x.target.HidePasswords,
|
||||
}).AsQueryable();
|
||||
}
|
||||
}
|
||||
|
||||
public class OrganizationUserUpdateWithCollectionsDeleteQuery : IQuery<CollectionUser>
|
||||
{
|
||||
private readonly OrganizationUser _organizationUser;
|
||||
private readonly IEnumerable<SelectionReadOnly> _collections;
|
||||
|
||||
public OrganizationUserUpdateWithCollectionsDeleteQuery(OrganizationUser organizationUser, IEnumerable<SelectionReadOnly> collections)
|
||||
{
|
||||
_organizationUser = organizationUser;
|
||||
_collections = collections;
|
||||
}
|
||||
|
||||
public IQueryable<CollectionUser> Run(DatabaseContext dbContext)
|
||||
{
|
||||
var deleteQuery = from cu in dbContext.CollectionUsers
|
||||
where !_collections.Any(
|
||||
c => c.Id == cu.CollectionId)
|
||||
select cu;
|
||||
return deleteQuery;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,35 +1,34 @@
|
||||
using Bit.Core.Models.Data.Organizations.OrganizationUsers;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries;
|
||||
|
||||
public class OrganizationUserUserDetailsViewQuery : IQuery<OrganizationUserUserDetails>
|
||||
{
|
||||
public class OrganizationUserUserDetailsViewQuery : IQuery<OrganizationUserUserDetails>
|
||||
public IQueryable<OrganizationUserUserDetails> Run(DatabaseContext dbContext)
|
||||
{
|
||||
public IQueryable<OrganizationUserUserDetails> Run(DatabaseContext dbContext)
|
||||
var query = from ou in dbContext.OrganizationUsers
|
||||
join u in dbContext.Users on ou.UserId equals u.Id into u_g
|
||||
from u in u_g.DefaultIfEmpty()
|
||||
join su in dbContext.SsoUsers on u.Id equals su.UserId into su_g
|
||||
from su in su_g.DefaultIfEmpty()
|
||||
select new { ou, u, su };
|
||||
return query.Select(x => new OrganizationUserUserDetails
|
||||
{
|
||||
var query = from ou in dbContext.OrganizationUsers
|
||||
join u in dbContext.Users on ou.UserId equals u.Id into u_g
|
||||
from u in u_g.DefaultIfEmpty()
|
||||
join su in dbContext.SsoUsers on u.Id equals su.UserId into su_g
|
||||
from su in su_g.DefaultIfEmpty()
|
||||
select new { ou, u, su };
|
||||
return query.Select(x => new OrganizationUserUserDetails
|
||||
{
|
||||
Id = x.ou.Id,
|
||||
OrganizationId = x.ou.OrganizationId,
|
||||
UserId = x.ou.UserId,
|
||||
Name = x.u.Name,
|
||||
Email = x.u.Email ?? x.ou.Email,
|
||||
TwoFactorProviders = x.u.TwoFactorProviders,
|
||||
Premium = x.u.Premium,
|
||||
Status = x.ou.Status,
|
||||
Type = x.ou.Type,
|
||||
AccessAll = x.ou.AccessAll,
|
||||
ExternalId = x.ou.ExternalId,
|
||||
SsoExternalId = x.su.ExternalId,
|
||||
Permissions = x.ou.Permissions,
|
||||
ResetPasswordKey = x.ou.ResetPasswordKey,
|
||||
UsesKeyConnector = x.u != null && x.u.UsesKeyConnector,
|
||||
});
|
||||
}
|
||||
Id = x.ou.Id,
|
||||
OrganizationId = x.ou.OrganizationId,
|
||||
UserId = x.ou.UserId,
|
||||
Name = x.u.Name,
|
||||
Email = x.u.Email ?? x.ou.Email,
|
||||
TwoFactorProviders = x.u.TwoFactorProviders,
|
||||
Premium = x.u.Premium,
|
||||
Status = x.ou.Status,
|
||||
Type = x.ou.Type,
|
||||
AccessAll = x.ou.AccessAll,
|
||||
ExternalId = x.ou.ExternalId,
|
||||
SsoExternalId = x.su.ExternalId,
|
||||
Permissions = x.ou.Permissions,
|
||||
ResetPasswordKey = x.ou.ResetPasswordKey,
|
||||
UsesKeyConnector = x.u != null && x.u.UsesKeyConnector,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,51 +1,50 @@
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Infrastructure.EntityFramework.Models;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries;
|
||||
|
||||
public class PolicyReadByTypeApplicableToUserQuery : IQuery<Policy>
|
||||
{
|
||||
public class PolicyReadByTypeApplicableToUserQuery : IQuery<Policy>
|
||||
private readonly Guid _userId;
|
||||
private readonly PolicyType _policyType;
|
||||
private readonly OrganizationUserStatusType _minimumStatus;
|
||||
|
||||
public PolicyReadByTypeApplicableToUserQuery(Guid userId, PolicyType policyType, OrganizationUserStatusType minimumStatus)
|
||||
{
|
||||
private readonly Guid _userId;
|
||||
private readonly PolicyType _policyType;
|
||||
private readonly OrganizationUserStatusType _minimumStatus;
|
||||
_userId = userId;
|
||||
_policyType = policyType;
|
||||
_minimumStatus = minimumStatus;
|
||||
}
|
||||
|
||||
public PolicyReadByTypeApplicableToUserQuery(Guid userId, PolicyType policyType, OrganizationUserStatusType minimumStatus)
|
||||
public IQueryable<Policy> Run(DatabaseContext dbContext)
|
||||
{
|
||||
var providerOrganizations = from pu in dbContext.ProviderUsers
|
||||
where pu.UserId == _userId
|
||||
join po in dbContext.ProviderOrganizations
|
||||
on pu.ProviderId equals po.ProviderId
|
||||
select po;
|
||||
|
||||
string userEmail = null;
|
||||
if (_minimumStatus == OrganizationUserStatusType.Invited)
|
||||
{
|
||||
_userId = userId;
|
||||
_policyType = policyType;
|
||||
_minimumStatus = minimumStatus;
|
||||
// Invited orgUsers do not have a UserId associated with them, so we have to match up their email
|
||||
userEmail = dbContext.Users.Find(_userId)?.Email;
|
||||
}
|
||||
|
||||
public IQueryable<Policy> Run(DatabaseContext dbContext)
|
||||
{
|
||||
var providerOrganizations = from pu in dbContext.ProviderUsers
|
||||
where pu.UserId == _userId
|
||||
join po in dbContext.ProviderOrganizations
|
||||
on pu.ProviderId equals po.ProviderId
|
||||
select po;
|
||||
|
||||
string userEmail = null;
|
||||
if (_minimumStatus == OrganizationUserStatusType.Invited)
|
||||
{
|
||||
// Invited orgUsers do not have a UserId associated with them, so we have to match up their email
|
||||
userEmail = dbContext.Users.Find(_userId)?.Email;
|
||||
}
|
||||
|
||||
var query = from p in dbContext.Policies
|
||||
join ou in dbContext.OrganizationUsers
|
||||
on p.OrganizationId equals ou.OrganizationId
|
||||
where
|
||||
((_minimumStatus > OrganizationUserStatusType.Invited && ou.UserId == _userId) ||
|
||||
(_minimumStatus == OrganizationUserStatusType.Invited && ou.Email == userEmail)) &&
|
||||
p.Type == _policyType &&
|
||||
p.Enabled &&
|
||||
ou.Status >= _minimumStatus &&
|
||||
ou.Type >= OrganizationUserType.User &&
|
||||
(ou.Permissions == null ||
|
||||
ou.Permissions.Contains($"\"managePolicies\":false")) &&
|
||||
!providerOrganizations.Any(po => po.OrganizationId == p.OrganizationId)
|
||||
select p;
|
||||
return query;
|
||||
}
|
||||
var query = from p in dbContext.Policies
|
||||
join ou in dbContext.OrganizationUsers
|
||||
on p.OrganizationId equals ou.OrganizationId
|
||||
where
|
||||
((_minimumStatus > OrganizationUserStatusType.Invited && ou.UserId == _userId) ||
|
||||
(_minimumStatus == OrganizationUserStatusType.Invited && ou.Email == userEmail)) &&
|
||||
p.Type == _policyType &&
|
||||
p.Enabled &&
|
||||
ou.Status >= _minimumStatus &&
|
||||
ou.Type >= OrganizationUserType.User &&
|
||||
(ou.Permissions == null ||
|
||||
ou.Permissions.Contains($"\"managePolicies\":false")) &&
|
||||
!providerOrganizations.Any(po => po.OrganizationId == p.OrganizationId)
|
||||
select p;
|
||||
return query;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,30 +1,29 @@
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Infrastructure.EntityFramework.Models;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries;
|
||||
|
||||
public class PolicyReadByUserIdQuery : IQuery<Policy>
|
||||
{
|
||||
public class PolicyReadByUserIdQuery : IQuery<Policy>
|
||||
private readonly Guid _userId;
|
||||
|
||||
public PolicyReadByUserIdQuery(Guid userId)
|
||||
{
|
||||
private readonly Guid _userId;
|
||||
_userId = userId;
|
||||
}
|
||||
|
||||
public PolicyReadByUserIdQuery(Guid userId)
|
||||
{
|
||||
_userId = userId;
|
||||
}
|
||||
public IQueryable<Policy> Run(DatabaseContext dbContext)
|
||||
{
|
||||
var query = from p in dbContext.Policies
|
||||
join ou in dbContext.OrganizationUsers
|
||||
on p.OrganizationId equals ou.OrganizationId
|
||||
join o in dbContext.Organizations
|
||||
on ou.OrganizationId equals o.Id
|
||||
where ou.UserId == _userId &&
|
||||
ou.Status == OrganizationUserStatusType.Confirmed &&
|
||||
o.Enabled == true
|
||||
select p;
|
||||
|
||||
public IQueryable<Policy> Run(DatabaseContext dbContext)
|
||||
{
|
||||
var query = from p in dbContext.Policies
|
||||
join ou in dbContext.OrganizationUsers
|
||||
on p.OrganizationId equals ou.OrganizationId
|
||||
join o in dbContext.Organizations
|
||||
on ou.OrganizationId equals o.Id
|
||||
where ou.UserId == _userId &&
|
||||
ou.Status == OrganizationUserStatusType.Confirmed &&
|
||||
o.Enabled == true
|
||||
select p;
|
||||
|
||||
return query;
|
||||
}
|
||||
return query;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,38 +1,37 @@
|
||||
using Bit.Core.Models.Data;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries
|
||||
{
|
||||
public class ProviderOrganizationOrganizationDetailsReadByProviderIdQuery : IQuery<ProviderOrganizationOrganizationDetails>
|
||||
{
|
||||
private readonly Guid _providerId;
|
||||
public ProviderOrganizationOrganizationDetailsReadByProviderIdQuery(Guid providerId)
|
||||
{
|
||||
_providerId = providerId;
|
||||
}
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries;
|
||||
|
||||
public IQueryable<ProviderOrganizationOrganizationDetails> Run(DatabaseContext dbContext)
|
||||
public class ProviderOrganizationOrganizationDetailsReadByProviderIdQuery : IQuery<ProviderOrganizationOrganizationDetails>
|
||||
{
|
||||
private readonly Guid _providerId;
|
||||
public ProviderOrganizationOrganizationDetailsReadByProviderIdQuery(Guid providerId)
|
||||
{
|
||||
_providerId = providerId;
|
||||
}
|
||||
|
||||
public IQueryable<ProviderOrganizationOrganizationDetails> Run(DatabaseContext dbContext)
|
||||
{
|
||||
var query = from po in dbContext.ProviderOrganizations
|
||||
join o in dbContext.Organizations
|
||||
on po.OrganizationId equals o.Id
|
||||
join ou in dbContext.OrganizationUsers
|
||||
on po.OrganizationId equals ou.OrganizationId
|
||||
where po.ProviderId == _providerId
|
||||
select new { po, o };
|
||||
return query.Select(x => new ProviderOrganizationOrganizationDetails()
|
||||
{
|
||||
var query = from po in dbContext.ProviderOrganizations
|
||||
join o in dbContext.Organizations
|
||||
on po.OrganizationId equals o.Id
|
||||
join ou in dbContext.OrganizationUsers
|
||||
on po.OrganizationId equals ou.OrganizationId
|
||||
where po.ProviderId == _providerId
|
||||
select new { po, o };
|
||||
return query.Select(x => new ProviderOrganizationOrganizationDetails()
|
||||
{
|
||||
Id = x.po.Id,
|
||||
ProviderId = x.po.ProviderId,
|
||||
OrganizationId = x.po.OrganizationId,
|
||||
OrganizationName = x.o.Name,
|
||||
Key = x.po.Key,
|
||||
Settings = x.po.Settings,
|
||||
CreationDate = x.po.CreationDate,
|
||||
RevisionDate = x.po.RevisionDate,
|
||||
UserCount = x.o.OrganizationUsers.Count(ou => ou.Status == Core.Enums.OrganizationUserStatusType.Confirmed),
|
||||
Seats = x.o.Seats,
|
||||
Plan = x.o.Plan
|
||||
});
|
||||
}
|
||||
Id = x.po.Id,
|
||||
ProviderId = x.po.ProviderId,
|
||||
OrganizationId = x.po.OrganizationId,
|
||||
OrganizationName = x.o.Name,
|
||||
Key = x.po.Key,
|
||||
Settings = x.po.Settings,
|
||||
CreationDate = x.po.CreationDate,
|
||||
RevisionDate = x.po.RevisionDate,
|
||||
UserCount = x.o.OrganizationUsers.Count(ou => ou.Status == Core.Enums.OrganizationUserStatusType.Confirmed),
|
||||
Seats = x.o.Seats,
|
||||
Plan = x.o.Plan
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,46 +1,45 @@
|
||||
using Bit.Core.Models.Data;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries;
|
||||
|
||||
public class ProviderUserOrganizationDetailsViewQuery : IQuery<ProviderUserOrganizationDetails>
|
||||
{
|
||||
public class ProviderUserOrganizationDetailsViewQuery : IQuery<ProviderUserOrganizationDetails>
|
||||
public IQueryable<ProviderUserOrganizationDetails> Run(DatabaseContext dbContext)
|
||||
{
|
||||
public IQueryable<ProviderUserOrganizationDetails> Run(DatabaseContext dbContext)
|
||||
var query = from pu in dbContext.ProviderUsers
|
||||
join po in dbContext.ProviderOrganizations on pu.ProviderId equals po.ProviderId
|
||||
join o in dbContext.Organizations on po.OrganizationId equals o.Id
|
||||
join p in dbContext.Providers on pu.ProviderId equals p.Id
|
||||
select new { pu, po, o, p };
|
||||
return query.Select(x => new ProviderUserOrganizationDetails
|
||||
{
|
||||
var query = from pu in dbContext.ProviderUsers
|
||||
join po in dbContext.ProviderOrganizations on pu.ProviderId equals po.ProviderId
|
||||
join o in dbContext.Organizations on po.OrganizationId equals o.Id
|
||||
join p in dbContext.Providers on pu.ProviderId equals p.Id
|
||||
select new { pu, po, o, p };
|
||||
return query.Select(x => new ProviderUserOrganizationDetails
|
||||
{
|
||||
OrganizationId = x.po.OrganizationId,
|
||||
UserId = x.pu.UserId,
|
||||
Name = x.o.Name,
|
||||
Enabled = x.o.Enabled,
|
||||
UsePolicies = x.o.UsePolicies,
|
||||
UseSso = x.o.UseSso,
|
||||
UseKeyConnector = x.o.UseKeyConnector,
|
||||
UseScim = x.o.UseScim,
|
||||
UseGroups = x.o.UseGroups,
|
||||
UseDirectory = x.o.UseDirectory,
|
||||
UseEvents = x.o.UseEvents,
|
||||
UseTotp = x.o.UseTotp,
|
||||
Use2fa = x.o.Use2fa,
|
||||
UseApi = x.o.UseApi,
|
||||
SelfHost = x.o.SelfHost,
|
||||
UsersGetPremium = x.o.UsersGetPremium,
|
||||
Seats = x.o.Seats,
|
||||
MaxCollections = x.o.MaxCollections,
|
||||
MaxStorageGb = x.o.MaxStorageGb,
|
||||
Identifier = x.o.Identifier,
|
||||
Key = x.po.Key,
|
||||
Status = x.pu.Status,
|
||||
Type = x.pu.Type,
|
||||
PublicKey = x.o.PublicKey,
|
||||
PrivateKey = x.o.PrivateKey,
|
||||
ProviderId = x.p.Id,
|
||||
ProviderName = x.p.Name,
|
||||
});
|
||||
}
|
||||
OrganizationId = x.po.OrganizationId,
|
||||
UserId = x.pu.UserId,
|
||||
Name = x.o.Name,
|
||||
Enabled = x.o.Enabled,
|
||||
UsePolicies = x.o.UsePolicies,
|
||||
UseSso = x.o.UseSso,
|
||||
UseKeyConnector = x.o.UseKeyConnector,
|
||||
UseScim = x.o.UseScim,
|
||||
UseGroups = x.o.UseGroups,
|
||||
UseDirectory = x.o.UseDirectory,
|
||||
UseEvents = x.o.UseEvents,
|
||||
UseTotp = x.o.UseTotp,
|
||||
Use2fa = x.o.Use2fa,
|
||||
UseApi = x.o.UseApi,
|
||||
SelfHost = x.o.SelfHost,
|
||||
UsersGetPremium = x.o.UsersGetPremium,
|
||||
Seats = x.o.Seats,
|
||||
MaxCollections = x.o.MaxCollections,
|
||||
MaxStorageGb = x.o.MaxStorageGb,
|
||||
Identifier = x.o.Identifier,
|
||||
Key = x.po.Key,
|
||||
Status = x.pu.Status,
|
||||
Type = x.pu.Type,
|
||||
PublicKey = x.o.PublicKey,
|
||||
PrivateKey = x.o.PrivateKey,
|
||||
ProviderId = x.p.Id,
|
||||
ProviderName = x.p.Name,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,39 +1,38 @@
|
||||
using Bit.Core.Enums.Provider;
|
||||
using Bit.Core.Models.Data;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries
|
||||
{
|
||||
public class ProviderUserProviderDetailsReadByUserIdStatusQuery : IQuery<ProviderUserProviderDetails>
|
||||
{
|
||||
private readonly Guid _userId;
|
||||
private readonly ProviderUserStatusType? _status;
|
||||
public ProviderUserProviderDetailsReadByUserIdStatusQuery(Guid userId, ProviderUserStatusType? status)
|
||||
{
|
||||
_userId = userId;
|
||||
_status = status;
|
||||
}
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries;
|
||||
|
||||
public IQueryable<ProviderUserProviderDetails> Run(DatabaseContext dbContext)
|
||||
public class ProviderUserProviderDetailsReadByUserIdStatusQuery : IQuery<ProviderUserProviderDetails>
|
||||
{
|
||||
private readonly Guid _userId;
|
||||
private readonly ProviderUserStatusType? _status;
|
||||
public ProviderUserProviderDetailsReadByUserIdStatusQuery(Guid userId, ProviderUserStatusType? status)
|
||||
{
|
||||
_userId = userId;
|
||||
_status = status;
|
||||
}
|
||||
|
||||
public IQueryable<ProviderUserProviderDetails> Run(DatabaseContext dbContext)
|
||||
{
|
||||
var query = from pu in dbContext.ProviderUsers
|
||||
join p in dbContext.Providers
|
||||
on pu.ProviderId equals p.Id into p_g
|
||||
from p in p_g.DefaultIfEmpty()
|
||||
where pu.UserId == _userId && p.Status != ProviderStatusType.Pending && (_status == null || pu.Status == _status)
|
||||
select new { pu, p };
|
||||
return query.Select(x => new ProviderUserProviderDetails()
|
||||
{
|
||||
var query = from pu in dbContext.ProviderUsers
|
||||
join p in dbContext.Providers
|
||||
on pu.ProviderId equals p.Id into p_g
|
||||
from p in p_g.DefaultIfEmpty()
|
||||
where pu.UserId == _userId && p.Status != ProviderStatusType.Pending && (_status == null || pu.Status == _status)
|
||||
select new { pu, p };
|
||||
return query.Select(x => new ProviderUserProviderDetails()
|
||||
{
|
||||
UserId = x.pu.UserId,
|
||||
ProviderId = x.pu.ProviderId,
|
||||
Name = x.p.Name,
|
||||
Key = x.pu.Key,
|
||||
Status = x.pu.Status,
|
||||
Type = x.pu.Type,
|
||||
Enabled = x.p.Enabled,
|
||||
Permissions = x.pu.Permissions,
|
||||
UseEvents = x.p.UseEvents,
|
||||
ProviderStatus = x.p.Status,
|
||||
});
|
||||
}
|
||||
UserId = x.pu.UserId,
|
||||
ProviderId = x.pu.ProviderId,
|
||||
Name = x.p.Name,
|
||||
Key = x.pu.Key,
|
||||
Status = x.pu.Status,
|
||||
Type = x.pu.Type,
|
||||
Enabled = x.p.Enabled,
|
||||
Permissions = x.pu.Permissions,
|
||||
UseEvents = x.p.UseEvents,
|
||||
ProviderStatus = x.p.Status,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,37 +1,36 @@
|
||||
using Bit.Core.Enums.Provider;
|
||||
using Bit.Infrastructure.EntityFramework.Models;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries;
|
||||
|
||||
public class ProviderUserReadCountByOnlyOwnerQuery : IQuery<ProviderUser>
|
||||
{
|
||||
public class ProviderUserReadCountByOnlyOwnerQuery : IQuery<ProviderUser>
|
||||
private readonly Guid _userId;
|
||||
|
||||
public ProviderUserReadCountByOnlyOwnerQuery(Guid userId)
|
||||
{
|
||||
private readonly Guid _userId;
|
||||
_userId = userId;
|
||||
}
|
||||
|
||||
public ProviderUserReadCountByOnlyOwnerQuery(Guid userId)
|
||||
{
|
||||
_userId = userId;
|
||||
}
|
||||
public IQueryable<ProviderUser> Run(DatabaseContext dbContext)
|
||||
{
|
||||
var owners = from pu in dbContext.ProviderUsers
|
||||
where pu.Type == ProviderUserType.ProviderAdmin &&
|
||||
pu.Status == ProviderUserStatusType.Confirmed
|
||||
group pu by pu.ProviderId into g
|
||||
select new
|
||||
{
|
||||
ProviderUser = g.Select(x => new { x.UserId, x.Id }).FirstOrDefault(),
|
||||
ConfirmedOwnerCount = g.Count(),
|
||||
};
|
||||
|
||||
public IQueryable<ProviderUser> Run(DatabaseContext dbContext)
|
||||
{
|
||||
var owners = from pu in dbContext.ProviderUsers
|
||||
where pu.Type == ProviderUserType.ProviderAdmin &&
|
||||
pu.Status == ProviderUserStatusType.Confirmed
|
||||
group pu by pu.ProviderId into g
|
||||
select new
|
||||
{
|
||||
ProviderUser = g.Select(x => new { x.UserId, x.Id }).FirstOrDefault(),
|
||||
ConfirmedOwnerCount = g.Count(),
|
||||
};
|
||||
var query = from owner in owners
|
||||
join pu in dbContext.ProviderUsers
|
||||
on owner.ProviderUser.Id equals pu.Id
|
||||
where owner.ProviderUser.UserId == _userId &&
|
||||
owner.ConfirmedOwnerCount == 1
|
||||
select pu;
|
||||
|
||||
var query = from owner in owners
|
||||
join pu in dbContext.ProviderUsers
|
||||
on owner.ProviderUser.Id equals pu.Id
|
||||
where owner.ProviderUser.UserId == _userId &&
|
||||
owner.ConfirmedOwnerCount == 1
|
||||
select pu;
|
||||
|
||||
return query;
|
||||
}
|
||||
return query;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,51 +2,50 @@
|
||||
using Bit.Core.Enums;
|
||||
using User = Bit.Infrastructure.EntityFramework.Models.User;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries;
|
||||
|
||||
public class UserBumpAccountRevisionDateByCipherIdQuery : IQuery<User>
|
||||
{
|
||||
public class UserBumpAccountRevisionDateByCipherIdQuery : IQuery<User>
|
||||
private readonly Cipher _cipher;
|
||||
|
||||
public UserBumpAccountRevisionDateByCipherIdQuery(Cipher cipher)
|
||||
{
|
||||
private readonly Cipher _cipher;
|
||||
_cipher = cipher;
|
||||
}
|
||||
|
||||
public UserBumpAccountRevisionDateByCipherIdQuery(Cipher cipher)
|
||||
{
|
||||
_cipher = cipher;
|
||||
}
|
||||
|
||||
public IQueryable<User> Run(DatabaseContext dbContext)
|
||||
{
|
||||
var query = from u in dbContext.Users
|
||||
join ou in dbContext.OrganizationUsers
|
||||
on u.Id equals ou.UserId
|
||||
join collectionCipher in dbContext.CollectionCiphers
|
||||
on _cipher.Id equals collectionCipher.CipherId into cc_g
|
||||
from cc in cc_g.DefaultIfEmpty()
|
||||
join collectionUser in dbContext.CollectionUsers
|
||||
on cc.CollectionId equals collectionUser.CollectionId into cu_g
|
||||
from cu in cu_g.DefaultIfEmpty()
|
||||
where ou.AccessAll &&
|
||||
cu.OrganizationUserId == ou.Id
|
||||
join groupUser in dbContext.GroupUsers
|
||||
on ou.Id equals groupUser.OrganizationUserId into gu_g
|
||||
from gu in gu_g.DefaultIfEmpty()
|
||||
where cu.CollectionId == null &&
|
||||
!ou.AccessAll
|
||||
join grp in dbContext.Groups
|
||||
on gu.GroupId equals grp.Id into g_g
|
||||
from g in g_g.DefaultIfEmpty()
|
||||
join collectionGroup in dbContext.CollectionGroups
|
||||
on cc.CollectionId equals collectionGroup.CollectionId into cg_g
|
||||
from cg in cg_g.DefaultIfEmpty()
|
||||
where !g.AccessAll &&
|
||||
cg.GroupId == gu.GroupId
|
||||
where ou.OrganizationId == _cipher.OrganizationId &&
|
||||
ou.Status == OrganizationUserStatusType.Confirmed &&
|
||||
(cu.CollectionId != null ||
|
||||
cg.CollectionId != null ||
|
||||
ou.AccessAll ||
|
||||
g.AccessAll)
|
||||
select u;
|
||||
return query;
|
||||
}
|
||||
public IQueryable<User> Run(DatabaseContext dbContext)
|
||||
{
|
||||
var query = from u in dbContext.Users
|
||||
join ou in dbContext.OrganizationUsers
|
||||
on u.Id equals ou.UserId
|
||||
join collectionCipher in dbContext.CollectionCiphers
|
||||
on _cipher.Id equals collectionCipher.CipherId into cc_g
|
||||
from cc in cc_g.DefaultIfEmpty()
|
||||
join collectionUser in dbContext.CollectionUsers
|
||||
on cc.CollectionId equals collectionUser.CollectionId into cu_g
|
||||
from cu in cu_g.DefaultIfEmpty()
|
||||
where ou.AccessAll &&
|
||||
cu.OrganizationUserId == ou.Id
|
||||
join groupUser in dbContext.GroupUsers
|
||||
on ou.Id equals groupUser.OrganizationUserId into gu_g
|
||||
from gu in gu_g.DefaultIfEmpty()
|
||||
where cu.CollectionId == null &&
|
||||
!ou.AccessAll
|
||||
join grp in dbContext.Groups
|
||||
on gu.GroupId equals grp.Id into g_g
|
||||
from g in g_g.DefaultIfEmpty()
|
||||
join collectionGroup in dbContext.CollectionGroups
|
||||
on cc.CollectionId equals collectionGroup.CollectionId into cg_g
|
||||
from cg in cg_g.DefaultIfEmpty()
|
||||
where !g.AccessAll &&
|
||||
cg.GroupId == gu.GroupId
|
||||
where ou.OrganizationId == _cipher.OrganizationId &&
|
||||
ou.Status == OrganizationUserStatusType.Confirmed &&
|
||||
(cu.CollectionId != null ||
|
||||
cg.CollectionId != null ||
|
||||
ou.AccessAll ||
|
||||
g.AccessAll)
|
||||
select u;
|
||||
return query;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,27 +1,26 @@
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Infrastructure.EntityFramework.Models;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries;
|
||||
|
||||
public class UserBumpAccountRevisionDateByOrganizationIdQuery : IQuery<User>
|
||||
{
|
||||
public class UserBumpAccountRevisionDateByOrganizationIdQuery : IQuery<User>
|
||||
private readonly Guid _organizationId;
|
||||
|
||||
public UserBumpAccountRevisionDateByOrganizationIdQuery(Guid organizationId)
|
||||
{
|
||||
private readonly Guid _organizationId;
|
||||
_organizationId = organizationId;
|
||||
}
|
||||
|
||||
public UserBumpAccountRevisionDateByOrganizationIdQuery(Guid organizationId)
|
||||
{
|
||||
_organizationId = organizationId;
|
||||
}
|
||||
public IQueryable<User> Run(DatabaseContext dbContext)
|
||||
{
|
||||
var query = from u in dbContext.Users
|
||||
join ou in dbContext.OrganizationUsers
|
||||
on u.Id equals ou.UserId
|
||||
where ou.OrganizationId == _organizationId &&
|
||||
ou.Status == OrganizationUserStatusType.Confirmed
|
||||
select u;
|
||||
|
||||
public IQueryable<User> Run(DatabaseContext dbContext)
|
||||
{
|
||||
var query = from u in dbContext.Users
|
||||
join ou in dbContext.OrganizationUsers
|
||||
on u.Id equals ou.UserId
|
||||
where ou.OrganizationId == _organizationId &&
|
||||
ou.Status == OrganizationUserStatusType.Confirmed
|
||||
select u;
|
||||
|
||||
return query;
|
||||
}
|
||||
return query;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,71 +2,70 @@
|
||||
using Core.Models.Data;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries;
|
||||
|
||||
public class UserCipherDetailsQuery : IQuery<CipherDetails>
|
||||
{
|
||||
public class UserCipherDetailsQuery : IQuery<CipherDetails>
|
||||
private readonly Guid? _userId;
|
||||
public UserCipherDetailsQuery(Guid? userId)
|
||||
{
|
||||
private readonly Guid? _userId;
|
||||
public UserCipherDetailsQuery(Guid? userId)
|
||||
{
|
||||
_userId = userId;
|
||||
}
|
||||
public virtual IQueryable<CipherDetails> Run(DatabaseContext dbContext)
|
||||
{
|
||||
var query = from c in dbContext.Ciphers
|
||||
join ou in dbContext.OrganizationUsers
|
||||
on c.OrganizationId equals ou.OrganizationId
|
||||
where ou.UserId == _userId &&
|
||||
ou.Status == OrganizationUserStatusType.Confirmed
|
||||
join o in dbContext.Organizations
|
||||
on c.OrganizationId equals o.Id
|
||||
where o.Id == ou.OrganizationId && o.Enabled
|
||||
join cc in dbContext.CollectionCiphers
|
||||
on c.Id equals cc.CipherId into cc_g
|
||||
from cc in cc_g.DefaultIfEmpty()
|
||||
where ou.AccessAll
|
||||
join cu in dbContext.CollectionUsers
|
||||
on cc.CollectionId equals cu.CollectionId into cu_g
|
||||
from cu in cu_g.DefaultIfEmpty()
|
||||
where cu.OrganizationUserId == ou.Id
|
||||
join gu in dbContext.GroupUsers
|
||||
on ou.Id equals gu.OrganizationUserId into gu_g
|
||||
from gu in gu_g.DefaultIfEmpty()
|
||||
where cu.CollectionId == null && !ou.AccessAll
|
||||
join g in dbContext.Groups
|
||||
on gu.GroupId equals g.Id into g_g
|
||||
from g in g_g.DefaultIfEmpty()
|
||||
join cg in dbContext.CollectionGroups
|
||||
on cc.CollectionId equals cg.CollectionId into cg_g
|
||||
from cg in cg_g.DefaultIfEmpty()
|
||||
where !g.AccessAll && cg.GroupId == gu.GroupId &&
|
||||
ou.AccessAll || cu.CollectionId != null || g.AccessAll || cg.CollectionId != null
|
||||
select new { c, ou, o, cc, cu, gu, g, cg }.c;
|
||||
_userId = userId;
|
||||
}
|
||||
public virtual IQueryable<CipherDetails> Run(DatabaseContext dbContext)
|
||||
{
|
||||
var query = from c in dbContext.Ciphers
|
||||
join ou in dbContext.OrganizationUsers
|
||||
on c.OrganizationId equals ou.OrganizationId
|
||||
where ou.UserId == _userId &&
|
||||
ou.Status == OrganizationUserStatusType.Confirmed
|
||||
join o in dbContext.Organizations
|
||||
on c.OrganizationId equals o.Id
|
||||
where o.Id == ou.OrganizationId && o.Enabled
|
||||
join cc in dbContext.CollectionCiphers
|
||||
on c.Id equals cc.CipherId into cc_g
|
||||
from cc in cc_g.DefaultIfEmpty()
|
||||
where ou.AccessAll
|
||||
join cu in dbContext.CollectionUsers
|
||||
on cc.CollectionId equals cu.CollectionId into cu_g
|
||||
from cu in cu_g.DefaultIfEmpty()
|
||||
where cu.OrganizationUserId == ou.Id
|
||||
join gu in dbContext.GroupUsers
|
||||
on ou.Id equals gu.OrganizationUserId into gu_g
|
||||
from gu in gu_g.DefaultIfEmpty()
|
||||
where cu.CollectionId == null && !ou.AccessAll
|
||||
join g in dbContext.Groups
|
||||
on gu.GroupId equals g.Id into g_g
|
||||
from g in g_g.DefaultIfEmpty()
|
||||
join cg in dbContext.CollectionGroups
|
||||
on cc.CollectionId equals cg.CollectionId into cg_g
|
||||
from cg in cg_g.DefaultIfEmpty()
|
||||
where !g.AccessAll && cg.GroupId == gu.GroupId &&
|
||||
ou.AccessAll || cu.CollectionId != null || g.AccessAll || cg.CollectionId != null
|
||||
select new { c, ou, o, cc, cu, gu, g, cg }.c;
|
||||
|
||||
var query2 = from c in dbContext.Ciphers
|
||||
where c.UserId == _userId
|
||||
select c;
|
||||
var query2 = from c in dbContext.Ciphers
|
||||
where c.UserId == _userId
|
||||
select c;
|
||||
|
||||
var union = query.Union(query2).Select(c => new CipherDetails
|
||||
{
|
||||
Id = c.Id,
|
||||
UserId = c.UserId,
|
||||
OrganizationId = c.OrganizationId,
|
||||
Type = c.Type,
|
||||
Data = c.Data,
|
||||
Attachments = c.Attachments,
|
||||
CreationDate = c.CreationDate,
|
||||
RevisionDate = c.RevisionDate,
|
||||
DeletedDate = c.DeletedDate,
|
||||
Favorite = _userId.HasValue && c.Favorites != null && c.Favorites.Contains($"\"{_userId}\":true"),
|
||||
FolderId = _userId.HasValue && !string.IsNullOrWhiteSpace(c.Folders) ?
|
||||
Guid.Parse(JObject.Parse(c.Folders)[_userId.Value.ToString()].Value<string>()) :
|
||||
null,
|
||||
Edit = true,
|
||||
ViewPassword = true,
|
||||
OrganizationUseTotp = false,
|
||||
});
|
||||
return union;
|
||||
}
|
||||
var union = query.Union(query2).Select(c => new CipherDetails
|
||||
{
|
||||
Id = c.Id,
|
||||
UserId = c.UserId,
|
||||
OrganizationId = c.OrganizationId,
|
||||
Type = c.Type,
|
||||
Data = c.Data,
|
||||
Attachments = c.Attachments,
|
||||
CreationDate = c.CreationDate,
|
||||
RevisionDate = c.RevisionDate,
|
||||
DeletedDate = c.DeletedDate,
|
||||
Favorite = _userId.HasValue && c.Favorites != null && c.Favorites.Contains($"\"{_userId}\":true"),
|
||||
FolderId = _userId.HasValue && !string.IsNullOrWhiteSpace(c.Folders) ?
|
||||
Guid.Parse(JObject.Parse(c.Folders)[_userId.Value.ToString()].Value<string>()) :
|
||||
null,
|
||||
Edit = true,
|
||||
ViewPassword = true,
|
||||
OrganizationUseTotp = false,
|
||||
});
|
||||
return union;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,53 +1,52 @@
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.Models.Data;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries;
|
||||
|
||||
public class UserCollectionDetailsQuery : IQuery<CollectionDetails>
|
||||
{
|
||||
public class UserCollectionDetailsQuery : IQuery<CollectionDetails>
|
||||
private readonly Guid? _userId;
|
||||
public UserCollectionDetailsQuery(Guid? userId)
|
||||
{
|
||||
private readonly Guid? _userId;
|
||||
public UserCollectionDetailsQuery(Guid? userId)
|
||||
_userId = userId;
|
||||
}
|
||||
public virtual IQueryable<CollectionDetails> Run(DatabaseContext dbContext)
|
||||
{
|
||||
var query = from c in dbContext.Collections
|
||||
join ou in dbContext.OrganizationUsers
|
||||
on c.OrganizationId equals ou.OrganizationId
|
||||
join o in dbContext.Organizations
|
||||
on c.OrganizationId equals o.Id
|
||||
join cu in dbContext.CollectionUsers
|
||||
on c.Id equals cu.CollectionId into cu_g
|
||||
from cu in cu_g.DefaultIfEmpty()
|
||||
where ou.AccessAll && cu.OrganizationUserId == ou.Id
|
||||
join gu in dbContext.GroupUsers
|
||||
on ou.Id equals gu.OrganizationUserId into gu_g
|
||||
from gu in gu_g.DefaultIfEmpty()
|
||||
where cu.CollectionId == null && !ou.AccessAll
|
||||
join g in dbContext.Groups
|
||||
on gu.GroupId equals g.Id into g_g
|
||||
from g in g_g.DefaultIfEmpty()
|
||||
join cg in dbContext.CollectionGroups
|
||||
on gu.GroupId equals cg.GroupId into cg_g
|
||||
from cg in cg_g.DefaultIfEmpty()
|
||||
where !g.AccessAll && cg.CollectionId == c.Id &&
|
||||
ou.UserId == _userId &&
|
||||
ou.Status == OrganizationUserStatusType.Confirmed &&
|
||||
o.Enabled &&
|
||||
(ou.AccessAll || cu.CollectionId != null || g.AccessAll || cg.CollectionId != null)
|
||||
select new { c, ou, o, cu, gu, g, cg };
|
||||
return query.Select(x => new CollectionDetails
|
||||
{
|
||||
_userId = userId;
|
||||
}
|
||||
public virtual IQueryable<CollectionDetails> Run(DatabaseContext dbContext)
|
||||
{
|
||||
var query = from c in dbContext.Collections
|
||||
join ou in dbContext.OrganizationUsers
|
||||
on c.OrganizationId equals ou.OrganizationId
|
||||
join o in dbContext.Organizations
|
||||
on c.OrganizationId equals o.Id
|
||||
join cu in dbContext.CollectionUsers
|
||||
on c.Id equals cu.CollectionId into cu_g
|
||||
from cu in cu_g.DefaultIfEmpty()
|
||||
where ou.AccessAll && cu.OrganizationUserId == ou.Id
|
||||
join gu in dbContext.GroupUsers
|
||||
on ou.Id equals gu.OrganizationUserId into gu_g
|
||||
from gu in gu_g.DefaultIfEmpty()
|
||||
where cu.CollectionId == null && !ou.AccessAll
|
||||
join g in dbContext.Groups
|
||||
on gu.GroupId equals g.Id into g_g
|
||||
from g in g_g.DefaultIfEmpty()
|
||||
join cg in dbContext.CollectionGroups
|
||||
on gu.GroupId equals cg.GroupId into cg_g
|
||||
from cg in cg_g.DefaultIfEmpty()
|
||||
where !g.AccessAll && cg.CollectionId == c.Id &&
|
||||
ou.UserId == _userId &&
|
||||
ou.Status == OrganizationUserStatusType.Confirmed &&
|
||||
o.Enabled &&
|
||||
(ou.AccessAll || cu.CollectionId != null || g.AccessAll || cg.CollectionId != null)
|
||||
select new { c, ou, o, cu, gu, g, cg };
|
||||
return query.Select(x => new CollectionDetails
|
||||
{
|
||||
Id = x.c.Id,
|
||||
OrganizationId = x.c.OrganizationId,
|
||||
Name = x.c.Name,
|
||||
ExternalId = x.c.ExternalId,
|
||||
CreationDate = x.c.CreationDate,
|
||||
RevisionDate = x.c.RevisionDate,
|
||||
ReadOnly = !x.ou.AccessAll || !x.g.AccessAll || (x.cu.ReadOnly || x.cg.ReadOnly),
|
||||
HidePasswords = !x.ou.AccessAll || !x.g.AccessAll || (x.cu.HidePasswords || x.cg.HidePasswords),
|
||||
});
|
||||
}
|
||||
Id = x.c.Id,
|
||||
OrganizationId = x.c.OrganizationId,
|
||||
Name = x.c.Name,
|
||||
ExternalId = x.c.ExternalId,
|
||||
CreationDate = x.c.CreationDate,
|
||||
RevisionDate = x.c.RevisionDate,
|
||||
ReadOnly = !x.ou.AccessAll || !x.g.AccessAll || (x.cu.ReadOnly || x.cg.ReadOnly),
|
||||
HidePasswords = !x.ou.AccessAll || !x.g.AccessAll || (x.cu.HidePasswords || x.cg.HidePasswords),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,33 +1,32 @@
|
||||
using Bit.Core.Enums.Provider;
|
||||
using Bit.Core.Models.Data;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries;
|
||||
|
||||
public class UserReadPublicKeysByProviderUserIdsQuery : IQuery<ProviderUserPublicKey>
|
||||
{
|
||||
public class UserReadPublicKeysByProviderUserIdsQuery : IQuery<ProviderUserPublicKey>
|
||||
private readonly Guid _providerId;
|
||||
private readonly IEnumerable<Guid> _ids;
|
||||
|
||||
public UserReadPublicKeysByProviderUserIdsQuery(Guid providerId, IEnumerable<Guid> Ids)
|
||||
{
|
||||
private readonly Guid _providerId;
|
||||
private readonly IEnumerable<Guid> _ids;
|
||||
_providerId = providerId;
|
||||
_ids = Ids;
|
||||
}
|
||||
|
||||
public UserReadPublicKeysByProviderUserIdsQuery(Guid providerId, IEnumerable<Guid> Ids)
|
||||
public virtual IQueryable<ProviderUserPublicKey> Run(DatabaseContext dbContext)
|
||||
{
|
||||
var query = from pu in dbContext.ProviderUsers
|
||||
join u in dbContext.Users
|
||||
on pu.UserId equals u.Id
|
||||
where _ids.Contains(pu.Id) &&
|
||||
pu.Status == ProviderUserStatusType.Accepted &&
|
||||
pu.ProviderId == _providerId
|
||||
select new { pu, u };
|
||||
return query.Select(x => new ProviderUserPublicKey
|
||||
{
|
||||
_providerId = providerId;
|
||||
_ids = Ids;
|
||||
}
|
||||
|
||||
public virtual IQueryable<ProviderUserPublicKey> Run(DatabaseContext dbContext)
|
||||
{
|
||||
var query = from pu in dbContext.ProviderUsers
|
||||
join u in dbContext.Users
|
||||
on pu.UserId equals u.Id
|
||||
where _ids.Contains(pu.Id) &&
|
||||
pu.Status == ProviderUserStatusType.Accepted &&
|
||||
pu.ProviderId == _providerId
|
||||
select new { pu, u };
|
||||
return query.Select(x => new ProviderUserPublicKey
|
||||
{
|
||||
Id = x.pu.Id,
|
||||
PublicKey = x.u.PublicKey,
|
||||
});
|
||||
}
|
||||
Id = x.pu.Id,
|
||||
PublicKey = x.u.PublicKey,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user