mirror of
https://github.com/bitwarden/server.git
synced 2025-05-20 02:54:32 -05:00
fix logic in some EF cipher queries (#2366)
* fix logic in some cipher queries * Update src/Infrastructure.EntityFramework/Repositories/Queries/UserCipherDetailsQuery.cs Co-authored-by: Justin Baur <19896123+justindbaur@users.noreply.github.com> * Update src/Infrastructure.EntityFramework/Repositories/Queries/UserCipherDetailsQuery.cs Co-authored-by: Justin Baur <19896123+justindbaur@users.noreply.github.com>
This commit is contained in:
parent
c5fb49758a
commit
d60a0f52fd
@ -261,7 +261,7 @@ public class CipherRepository : Repository<Core.Entities.Cipher, Cipher, Guid>,
|
|||||||
using (var scope = ServiceScopeFactory.CreateScope())
|
using (var scope = ServiceScopeFactory.CreateScope())
|
||||||
{
|
{
|
||||||
var dbContext = GetDatabaseContext(scope);
|
var dbContext = GetDatabaseContext(scope);
|
||||||
var query = new CipherOrganizationDetailsReadByIdQuery(organizationId);
|
var query = new CipherOrganizationDetailsReadByOrgizationIdQuery(organizationId);
|
||||||
var data = await query.Run(dbContext).ToListAsync();
|
var data = await query.Run(dbContext).ToListAsync();
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
@ -477,6 +477,16 @@ public class CipherRepository : Repository<Core.Entities.Cipher, Cipher, Guid>,
|
|||||||
|
|
||||||
private async Task<DateTime> ToggleCipherStates(IEnumerable<Guid> ids, Guid userId, CipherStateAction action)
|
private async Task<DateTime> ToggleCipherStates(IEnumerable<Guid> ids, Guid userId, CipherStateAction action)
|
||||||
{
|
{
|
||||||
|
static bool FilterDeletedDate(CipherStateAction action, CipherDetails ucd)
|
||||||
|
{
|
||||||
|
return action switch
|
||||||
|
{
|
||||||
|
CipherStateAction.Restore => ucd.DeletedDate != null,
|
||||||
|
CipherStateAction.SoftDelete => ucd.DeletedDate == null,
|
||||||
|
_ => true,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
using (var scope = ServiceScopeFactory.CreateScope())
|
using (var scope = ServiceScopeFactory.CreateScope())
|
||||||
{
|
{
|
||||||
var dbContext = GetDatabaseContext(scope);
|
var dbContext = GetDatabaseContext(scope);
|
||||||
@ -485,7 +495,7 @@ public class CipherRepository : Repository<Core.Entities.Cipher, Cipher, Guid>,
|
|||||||
var query = from ucd in await (userCipherDetailsQuery.Run(dbContext)).ToListAsync()
|
var query = from ucd in await (userCipherDetailsQuery.Run(dbContext)).ToListAsync()
|
||||||
join c in cipherEntitiesToCheck
|
join c in cipherEntitiesToCheck
|
||||||
on ucd.Id equals c.Id
|
on ucd.Id equals c.Id
|
||||||
where ucd.Edit && ucd.DeletedDate == null
|
where ucd.Edit && FilterDeletedDate(action, ucd)
|
||||||
select c;
|
select c;
|
||||||
|
|
||||||
var utcNow = DateTime.UtcNow;
|
var utcNow = DateTime.UtcNow;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
using Bit.Core.Enums;
|
using System.Text.Json;
|
||||||
|
using Bit.Core.Enums;
|
||||||
using Core.Models.Data;
|
using Core.Models.Data;
|
||||||
using Newtonsoft.Json.Linq;
|
|
||||||
|
|
||||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries;
|
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries;
|
||||||
|
|
||||||
@ -59,13 +59,24 @@ public class UserCipherDetailsQuery : IQuery<CipherDetails>
|
|||||||
RevisionDate = c.RevisionDate,
|
RevisionDate = c.RevisionDate,
|
||||||
DeletedDate = c.DeletedDate,
|
DeletedDate = c.DeletedDate,
|
||||||
Favorite = _userId.HasValue && c.Favorites != null && c.Favorites.Contains($"\"{_userId}\":true"),
|
Favorite = _userId.HasValue && c.Favorites != null && c.Favorites.Contains($"\"{_userId}\":true"),
|
||||||
FolderId = _userId.HasValue && !string.IsNullOrWhiteSpace(c.Folders) ?
|
FolderId = GetFolderId(_userId, c),
|
||||||
Guid.Parse(JObject.Parse(c.Folders)[_userId.Value.ToString()].Value<string>()) :
|
|
||||||
null,
|
|
||||||
Edit = true,
|
Edit = true,
|
||||||
ViewPassword = true,
|
ViewPassword = true,
|
||||||
OrganizationUseTotp = false,
|
OrganizationUseTotp = false,
|
||||||
});
|
});
|
||||||
return union;
|
return union;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Guid? GetFolderId(Guid? userId, Models.Cipher cipher)
|
||||||
|
{
|
||||||
|
if (userId.HasValue && !string.IsNullOrWhiteSpace(cipher.Folders))
|
||||||
|
{
|
||||||
|
var folders = JsonSerializer.Deserialize<Dictionary<Guid, Guid>>(cipher.Folders);
|
||||||
|
if (folders.TryGetValue(userId.Value, out var folder))
|
||||||
|
{
|
||||||
|
return folder;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user