1
0
mirror of https://github.com/bitwarden/server.git synced 2025-01-15 20:41:35 +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)
{
return org is
{ Type: OrganizationUserType.Admin or OrganizationUserType.Owner } or
{ Permissions.AccessReports: true };
{ Type: OrganizationUserType.Admin or OrganizationUserType.Owner } or
{ Permissions.AccessReports: true };
}
}

View File

@ -12,7 +12,7 @@ public class GetCipherPermissionsForUserQuery : IGetCipherPermissionsForUserQuer
private readonly ICurrentContext _currentContext;
private readonly ICipherRepository _cipherRepository;
private readonly IApplicationCacheService _applicationCacheService;
private readonly IFeatureService _featureService;
private readonly 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
if (orgAbility is { AllowAdminAccessToAllCollectionItems: true } && org is
{ Type: OrganizationUserType.Admin or OrganizationUserType.Owner })
{ Type: OrganizationUserType.Admin or OrganizationUserType.Owner })
{
return true;
}
@ -86,8 +86,8 @@ public class GetCipherPermissionsForUserQuery : IGetCipherPermissionsForUserQuer
private async Task<bool> CanAccessUnassignedCiphersAsync(CurrentContextOrganization org)
{
if (org is
{ Type: OrganizationUserType.Owner or OrganizationUserType.Admin } or
{ Permissions.EditAnyCollection: true })
{ Type: OrganizationUserType.Owner or OrganizationUserType.Admin } or
{ Permissions.EditAnyCollection: 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 AutoMapper;
using Bit.Core.KeyManagement.UserKey;
@ -324,7 +323,7 @@ public class CipherRepository : Repository<Core.Vault.Entities.Cipher, Cipher, G
OrganizationId = g.Key.OrganizationId,
Read = Convert.ToBoolean(g.Max(c => Convert.ToInt32(c.Read))),
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))),
Unassigned = Convert.ToBoolean(g.Max(c => Convert.ToInt32(c.Unassigned))),
}).ToList();
@ -332,18 +331,18 @@ public class CipherRepository : Repository<Core.Vault.Entities.Cipher, Cipher, G
else
{
var groupByQuery = from p in query
group p by new { p.Id, p.OrganizationId }
group p by new { p.Id, p.OrganizationId }
into g
select new OrganizationCipherPermission
{
Id = g.Key.Id,
OrganizationId = g.Key.OrganizationId,
Read = Convert.ToBoolean(g.Max(c => Convert.ToInt32(c.Read))),
ViewPassword = Convert.ToBoolean(g.Max(c => Convert.ToInt32(c.ViewPassword))),
Edit =Convert.ToBoolean(g.Max(c => Convert.ToInt32(c.Edit))),
Manage = Convert.ToBoolean(g.Max(c => Convert.ToInt32(c.Manage))),
Unassigned = Convert.ToBoolean(g.Max(c => Convert.ToInt32(c.Unassigned))),
};
select new OrganizationCipherPermission
{
Id = g.Key.Id,
OrganizationId = g.Key.OrganizationId,
Read = Convert.ToBoolean(g.Max(c => Convert.ToInt32(c.Read))),
ViewPassword = Convert.ToBoolean(g.Max(c => Convert.ToInt32(c.ViewPassword))),
Edit = Convert.ToBoolean(g.Max(c => Convert.ToInt32(c.Edit))),
Manage = Convert.ToBoolean(g.Max(c => Convert.ToInt32(c.Manage))),
Unassigned = Convert.ToBoolean(g.Max(c => Convert.ToInt32(c.Unassigned))),
};
permissions = await groupByQuery.ToListAsync();
}

View File

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