1
0
mirror of https://github.com/bitwarden/server.git synced 2025-01-28 22:51:22 +01:00

[PM-14378] Formatting

This commit is contained in:
Shane Melton 2024-12-05 17:09:51 -08:00
parent df3e424aaf
commit 78ea8b5480
No known key found for this signature in database
5 changed files with 61 additions and 64 deletions

View File

@ -41,7 +41,7 @@ public class
private static bool CanListAllTasksForOrganization(CurrentContextOrganization org) private static bool CanListAllTasksForOrganization(CurrentContextOrganization org)
{ {
return org is return org is
{ Type: OrganizationUserType.Admin or OrganizationUserType.Owner } or { Type: OrganizationUserType.Admin or OrganizationUserType.Owner } or
{ Permissions.AccessReports: true }; { Permissions.AccessReports: true };
} }
} }

View File

@ -12,7 +12,7 @@ public class GetCipherPermissionsForUserQuery : IGetCipherPermissionsForUserQuer
private readonly ICurrentContext _currentContext; private readonly ICurrentContext _currentContext;
private readonly ICipherRepository _cipherRepository; private readonly ICipherRepository _cipherRepository;
private readonly IApplicationCacheService _applicationCacheService; private readonly IApplicationCacheService _applicationCacheService;
private readonly IFeatureService _featureService; private readonly IFeatureService _featureService;
public GetCipherPermissionsForUserQuery(ICurrentContext currentContext, ICipherRepository cipherRepository, IApplicationCacheService applicationCacheService, IFeatureService featureService) public GetCipherPermissionsForUserQuery(ICurrentContext currentContext, ICipherRepository cipherRepository, IApplicationCacheService applicationCacheService, IFeatureService featureService)
{ {
@ -69,7 +69,7 @@ public class GetCipherPermissionsForUserQuery : IGetCipherPermissionsForUserQuer
// Owners/Admins can only edit all ciphers if the organization has the setting enabled // Owners/Admins can only edit all ciphers if the organization has the setting enabled
if (orgAbility is { AllowAdminAccessToAllCollectionItems: true } && org is if (orgAbility is { AllowAdminAccessToAllCollectionItems: true } && org is
{ Type: OrganizationUserType.Admin or OrganizationUserType.Owner }) { Type: OrganizationUserType.Admin or OrganizationUserType.Owner })
{ {
return true; return true;
} }
@ -86,8 +86,8 @@ public class GetCipherPermissionsForUserQuery : IGetCipherPermissionsForUserQuer
private async Task<bool> CanAccessUnassignedCiphersAsync(CurrentContextOrganization org) private async Task<bool> CanAccessUnassignedCiphersAsync(CurrentContextOrganization org)
{ {
if (org is if (org is
{ Type: OrganizationUserType.Owner or OrganizationUserType.Admin } or { Type: OrganizationUserType.Owner or OrganizationUserType.Admin } or
{ Permissions.EditAnyCollection: true }) { Permissions.EditAnyCollection: true })
{ {
return true; return true;
} }

View File

@ -1,5 +1,4 @@
using System.Runtime.InteropServices; using System.Text.Json;
using System.Text.Json;
using System.Text.Json.Nodes; using System.Text.Json.Nodes;
using AutoMapper; using AutoMapper;
using Bit.Core.KeyManagement.UserKey; using Bit.Core.KeyManagement.UserKey;
@ -324,7 +323,7 @@ public class CipherRepository : Repository<Core.Vault.Entities.Cipher, Cipher, G
OrganizationId = g.Key.OrganizationId, OrganizationId = g.Key.OrganizationId,
Read = Convert.ToBoolean(g.Max(c => Convert.ToInt32(c.Read))), Read = Convert.ToBoolean(g.Max(c => Convert.ToInt32(c.Read))),
ViewPassword = Convert.ToBoolean(g.Max(c => Convert.ToInt32(c.ViewPassword))), ViewPassword = Convert.ToBoolean(g.Max(c => Convert.ToInt32(c.ViewPassword))),
Edit =Convert.ToBoolean(g.Max(c => Convert.ToInt32(c.Edit))), Edit = Convert.ToBoolean(g.Max(c => Convert.ToInt32(c.Edit))),
Manage = Convert.ToBoolean(g.Max(c => Convert.ToInt32(c.Manage))), Manage = Convert.ToBoolean(g.Max(c => Convert.ToInt32(c.Manage))),
Unassigned = Convert.ToBoolean(g.Max(c => Convert.ToInt32(c.Unassigned))), Unassigned = Convert.ToBoolean(g.Max(c => Convert.ToInt32(c.Unassigned))),
}).ToList(); }).ToList();
@ -332,18 +331,18 @@ public class CipherRepository : Repository<Core.Vault.Entities.Cipher, Cipher, G
else else
{ {
var groupByQuery = from p in query var groupByQuery = from p in query
group p by new { p.Id, p.OrganizationId } group p by new { p.Id, p.OrganizationId }
into g into g
select new OrganizationCipherPermission select new OrganizationCipherPermission
{ {
Id = g.Key.Id, Id = g.Key.Id,
OrganizationId = g.Key.OrganizationId, OrganizationId = g.Key.OrganizationId,
Read = Convert.ToBoolean(g.Max(c => Convert.ToInt32(c.Read))), Read = Convert.ToBoolean(g.Max(c => Convert.ToInt32(c.Read))),
ViewPassword = Convert.ToBoolean(g.Max(c => Convert.ToInt32(c.ViewPassword))), ViewPassword = Convert.ToBoolean(g.Max(c => Convert.ToInt32(c.ViewPassword))),
Edit =Convert.ToBoolean(g.Max(c => Convert.ToInt32(c.Edit))), Edit = Convert.ToBoolean(g.Max(c => Convert.ToInt32(c.Edit))),
Manage = Convert.ToBoolean(g.Max(c => Convert.ToInt32(c.Manage))), Manage = Convert.ToBoolean(g.Max(c => Convert.ToInt32(c.Manage))),
Unassigned = Convert.ToBoolean(g.Max(c => Convert.ToInt32(c.Unassigned))), Unassigned = Convert.ToBoolean(g.Max(c => Convert.ToInt32(c.Unassigned))),
}; };
permissions = await groupByQuery.ToListAsync(); permissions = await groupByQuery.ToListAsync();
} }

View File

@ -1,12 +1,6 @@
using Bit.Core.Auth.Enums; using Bit.Core.Vault.Models.Data;
using Bit.Core.Enums;
using Bit.Core.Vault.Models.Data;
using Bit.Infrastructure.EntityFramework.Repositories; using Bit.Infrastructure.EntityFramework.Repositories;
using Bit.Infrastructure.EntityFramework.Repositories.Queries; using Bit.Infrastructure.EntityFramework.Repositories.Queries;
using Microsoft.EntityFrameworkCore;
using Org.BouncyCastle.Utilities.IO;
using Sentry.Protocol;
using Stripe.TestHelpers;
namespace Bit.Infrastructure.EntityFramework.Vault.Repositories.Queries; namespace Bit.Infrastructure.EntityFramework.Vault.Repositories.Queries;
@ -25,46 +19,46 @@ public class CipherOrganizationPermissionsQuery : IQuery<OrganizationCipherPermi
{ {
return from c in dbContext.Ciphers return from c in dbContext.Ciphers
join ou in dbContext.OrganizationUsers join ou in dbContext.OrganizationUsers
on new { CipherUserId = c.UserId, c.OrganizationId, UserId = (Guid?)_userId } equals on new { CipherUserId = c.UserId, c.OrganizationId, UserId = (Guid?)_userId } equals
new { CipherUserId = (Guid?)null, OrganizationId = (Guid?)ou.OrganizationId, ou.UserId, } new { CipherUserId = (Guid?)null, OrganizationId = (Guid?)ou.OrganizationId, ou.UserId, }
join o in dbContext.Organizations join o in dbContext.Organizations
on new { c.OrganizationId, OuOrganizationId = ou.OrganizationId, Enabled = true } equals on new { c.OrganizationId, OuOrganizationId = ou.OrganizationId, Enabled = true } equals
new { OrganizationId = (Guid?)o.Id, OuOrganizationId = o.Id, o.Enabled } new { OrganizationId = (Guid?)o.Id, OuOrganizationId = o.Id, o.Enabled }
join cc in dbContext.CollectionCiphers join cc in dbContext.CollectionCiphers
on c.Id equals cc.CipherId into cc_g on c.Id equals cc.CipherId into cc_g
from cc in cc_g.DefaultIfEmpty() from cc in cc_g.DefaultIfEmpty()
join cu in dbContext.CollectionUsers join cu in dbContext.CollectionUsers
on new { cc.CollectionId, OrganizationUserId = ou.Id } equals on new { cc.CollectionId, OrganizationUserId = ou.Id } equals
new { cu.CollectionId, cu.OrganizationUserId } into cu_g new { cu.CollectionId, cu.OrganizationUserId } into cu_g
from cu in cu_g.DefaultIfEmpty() from cu in cu_g.DefaultIfEmpty()
join gu in dbContext.GroupUsers join gu in dbContext.GroupUsers
on new { CollectionId = (Guid?)cu.CollectionId, OrganizationUserId = ou.Id } equals on new { CollectionId = (Guid?)cu.CollectionId, OrganizationUserId = ou.Id } equals
new { CollectionId = (Guid?)null, gu.OrganizationUserId } into gu_g new { CollectionId = (Guid?)null, gu.OrganizationUserId } into gu_g
from gu in gu_g.DefaultIfEmpty() from gu in gu_g.DefaultIfEmpty()
join g in dbContext.Groups join g in dbContext.Groups
on gu.GroupId equals g.Id into g_g on gu.GroupId equals g.Id into g_g
from g in g_g.DefaultIfEmpty() from g in g_g.DefaultIfEmpty()
join cg in dbContext.CollectionGroups join cg in dbContext.CollectionGroups
on new { cc.CollectionId, gu.GroupId } equals on new { cc.CollectionId, gu.GroupId } equals
new { cg.CollectionId, cg.GroupId } into cg_g new { cg.CollectionId, cg.GroupId } into cg_g
from cg in cg_g.DefaultIfEmpty() from cg in cg_g.DefaultIfEmpty()
select new OrganizationCipherPermission() select new OrganizationCipherPermission()
{ {
Id = c.Id, Id = c.Id,
OrganizationId = o.Id, OrganizationId = o.Id,
Read = cu != null || cg != null, Read = cu != null || cg != null,
ViewPassword = !((bool?)cu.HidePasswords ?? (bool?)cg.HidePasswords ?? true), ViewPassword = !((bool?)cu.HidePasswords ?? (bool?)cg.HidePasswords ?? true),
Edit = !((bool?)cu.ReadOnly ?? (bool?)cg.ReadOnly ?? true), Edit = !((bool?)cu.ReadOnly ?? (bool?)cg.ReadOnly ?? true),
Manage = (bool?)cu.Manage ?? (bool?)cg.Manage ?? false, Manage = (bool?)cu.Manage ?? (bool?)cg.Manage ?? false,
Unassigned = !dbContext.CollectionCiphers.Any(cc => cc.CipherId == c.Id) Unassigned = !dbContext.CollectionCiphers.Any(cc => cc.CipherId == c.Id)
}; };
} }
} }

View File

@ -8,7 +8,6 @@ using Bit.Core.Vault.Entities;
using Bit.Core.Vault.Enums; using Bit.Core.Vault.Enums;
using Bit.Core.Vault.Models.Data; using Bit.Core.Vault.Models.Data;
using Bit.Core.Vault.Repositories; using Bit.Core.Vault.Repositories;
using Bit.Infrastructure.EntityFramework.Repositories;
using Xunit; using Xunit;
namespace Bit.Infrastructure.IntegrationTest.Repositories; namespace Bit.Infrastructure.IntegrationTest.Repositories;
@ -212,7 +211,10 @@ public class CipherRepositoryTests
var user = await userRepository.CreateAsync(new User var user = await userRepository.CreateAsync(new User
{ {
Name = "Test User", Email = $"test+{Guid.NewGuid()}@email.com", ApiKey = "TEST", SecurityStamp = "stamp", Name = "Test User",
Email = $"test+{Guid.NewGuid()}@email.com",
ApiKey = "TEST",
SecurityStamp = "stamp",
}); });
var organization = await organizationRepository.CreateAsync(new Organization var organization = await organizationRepository.CreateAsync(new Organization
@ -240,7 +242,9 @@ public class CipherRepositoryTests
var manageCipher = await cipherRepository.CreateAsync(new Cipher var manageCipher = await cipherRepository.CreateAsync(new Cipher
{ {
Type = CipherType.Login, OrganizationId = organization.Id, Data = "" Type = CipherType.Login,
OrganizationId = organization.Id,
Data = ""
}); });
collectionCipherRepository.UpdateCollectionsForAdminAsync(manageCipher.Id, organization.Id, collectionCipherRepository.UpdateCollectionsForAdminAsync(manageCipher.Id, organization.Id,