mirror of
https://github.com/bitwarden/server.git
synced 2025-05-20 11:04:31 -05:00
Process collections client-side (#1591)
CollectionDetails is not an entity and so cannot be processed server-side
This commit is contained in:
parent
cd321f2267
commit
62a0ca881f
@ -70,9 +70,7 @@ namespace Bit.Core.Repositories.EntityFramework
|
||||
using (var scope = ServiceScopeFactory.CreateScope())
|
||||
{
|
||||
var dbContext = GetDatabaseContext(scope);
|
||||
var query = new CollectionReadByIdUserId(id, userId).Run(dbContext);
|
||||
var collection = await query.FirstOrDefaultAsync();
|
||||
return collection;
|
||||
return (await GetManyByUserIdAsync(userId)).FirstOrDefault(c => c.Id == id);
|
||||
}
|
||||
}
|
||||
|
||||
@ -138,9 +136,19 @@ namespace Bit.Core.Repositories.EntityFramework
|
||||
using (var scope = ServiceScopeFactory.CreateScope())
|
||||
{
|
||||
var dbContext = GetDatabaseContext(scope);
|
||||
var query = new CollectionReadByUserId(userId).Run(dbContext);
|
||||
var collections = await query.ToListAsync();
|
||||
return collections;
|
||||
return (await new UserCollectionDetailsQuery(userId).Run(dbContext).ToListAsync())
|
||||
.GroupBy(c => c.Id)
|
||||
.Select(g => new CollectionDetails
|
||||
{
|
||||
Id = g.Key,
|
||||
OrganizationId = g.FirstOrDefault().OrganizationId,
|
||||
Name = g.FirstOrDefault().Name,
|
||||
ExternalId = g.FirstOrDefault().ExternalId,
|
||||
CreationDate = g.FirstOrDefault().CreationDate,
|
||||
RevisionDate = g.FirstOrDefault().RevisionDate,
|
||||
ReadOnly = g.Min(c => c.ReadOnly),
|
||||
HidePasswords = g.Min(c => c.HidePasswords)
|
||||
}).ToList();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,22 +0,0 @@
|
||||
using System.Linq;
|
||||
using System;
|
||||
using Bit.Core.Models.Data;
|
||||
|
||||
namespace Bit.Core.Repositories.EntityFramework.Queries
|
||||
{
|
||||
public class CollectionReadByIdUserId : CollectionReadByUserId
|
||||
{
|
||||
private readonly Guid _id;
|
||||
|
||||
public CollectionReadByIdUserId(Guid id, Guid userId) : base(userId)
|
||||
{
|
||||
_id = id;
|
||||
}
|
||||
|
||||
public override IQueryable<CollectionDetails> Run(DatabaseContext dbContext)
|
||||
{
|
||||
var query = base.Run(dbContext);
|
||||
return query.Where(c => c.Id == _id);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
using System.Linq;
|
||||
using System;
|
||||
using Bit.Core.Models.Data;
|
||||
|
||||
namespace Bit.Core.Repositories.EntityFramework.Queries
|
||||
{
|
||||
public class CollectionReadByUserId : UserCollectionDetailsQuery
|
||||
{
|
||||
private readonly Guid _userId;
|
||||
|
||||
public CollectionReadByUserId(Guid userId) : base(userId)
|
||||
{
|
||||
_userId = userId;
|
||||
}
|
||||
|
||||
public override IQueryable<CollectionDetails> Run(DatabaseContext dbContext)
|
||||
{
|
||||
var query = base.Run(dbContext);
|
||||
return query
|
||||
.GroupBy(c => c.Id)
|
||||
.Select(g => new CollectionDetails
|
||||
{
|
||||
Id = g.Key,
|
||||
OrganizationId = g.FirstOrDefault().OrganizationId,
|
||||
Name = g.FirstOrDefault().Name,
|
||||
ExternalId = g.FirstOrDefault().ExternalId,
|
||||
CreationDate = g.FirstOrDefault().CreationDate,
|
||||
RevisionDate = g.FirstOrDefault().RevisionDate,
|
||||
ReadOnly = g.Min(c => c.ReadOnly),
|
||||
HidePasswords = g.Min(c => c.HidePasswords)
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user