1
0
mirror of https://github.com/bitwarden/server synced 2025-12-27 21:53:24 +00:00

Merge branch 'master' into feature/billing-obfuscation

This commit is contained in:
Rui Tome
2023-02-03 10:15:41 +00:00
154 changed files with 17081 additions and 1370 deletions

View File

@@ -128,7 +128,9 @@ public abstract class BaseEntityFrameworkRepository
entity.SecurityStamp = user.SecurityStamp;
entity.Key = user.Key;
entity.PrivateKey = user.PrivateKey;
entity.RevisionDate = DateTime.UtcNow;
entity.LastKeyRotationDate = user.LastKeyRotationDate;
entity.AccountRevisionDate = user.AccountRevisionDate;
entity.RevisionDate = user.RevisionDate;
await dbContext.SaveChangesAsync();
}
}

View File

@@ -29,7 +29,7 @@ public class CipherRepository : Repository<Core.Entities.Cipher, Cipher, Guid>,
var dbContext = GetDatabaseContext(scope);
if (cipher.OrganizationId.HasValue)
{
await dbContext.UserBumpAccountRevisionDateByCipherIdAsync(cipher.Id, cipher.OrganizationId);
await dbContext.UserBumpAccountRevisionDateByCipherIdAsync(cipher.Id, cipher.OrganizationId.Value);
}
else if (cipher.UserId.HasValue)
{
@@ -59,7 +59,7 @@ public class CipherRepository : Repository<Core.Entities.Cipher, Cipher, Guid>,
await OrganizationUpdateStorage(cipherInfo.OrganizationId.Value);
}
await dbContext.UserBumpAccountRevisionDateByCipherIdAsync(cipher.Id, cipherInfo.OrganizationId);
await dbContext.UserBumpAccountRevisionDateByCipherIdAsync(cipher.Id, cipherInfo.OrganizationId.Value);
}
else if (cipherInfo?.UserId != null)
{
@@ -107,7 +107,16 @@ public class CipherRepository : Repository<Core.Entities.Cipher, Cipher, Guid>,
null;
var entity = Mapper.Map<Cipher>((Core.Entities.Cipher)cipher);
await dbContext.AddAsync(entity);
await dbContext.UserBumpAccountRevisionDateByCipherIdAsync(cipher.Id, cipher.OrganizationId.GetValueOrDefault());
if (cipher.OrganizationId.HasValue)
{
await dbContext.UserBumpAccountRevisionDateByCipherIdAsync(cipher.Id, cipher.OrganizationId.Value);
}
else if (cipher.UserId.HasValue)
{
await dbContext.UserBumpAccountRevisionDateAsync(cipher.UserId.Value);
}
await dbContext.SaveChangesAsync();
}
return cipher;
@@ -458,7 +467,16 @@ public class CipherRepository : Repository<Core.Entities.Cipher, Cipher, Guid>,
}
var mappedEntity = Mapper.Map<Cipher>((Core.Entities.Cipher)cipher);
dbContext.Entry(entity).CurrentValues.SetValues(mappedEntity);
await dbContext.UserBumpAccountRevisionDateByCipherIdAsync(cipher.Id, cipher.OrganizationId.GetValueOrDefault());
if (cipher.OrganizationId.HasValue)
{
await dbContext.UserBumpAccountRevisionDateByCipherIdAsync(cipher.Id, cipher.OrganizationId.Value);
}
else if (cipher.UserId.HasValue)
{
await dbContext.UserBumpAccountRevisionDateAsync(cipher.UserId.Value);
}
await dbContext.SaveChangesAsync();
}
}
@@ -566,7 +584,15 @@ public class CipherRepository : Repository<Core.Entities.Cipher, Cipher, Guid>,
}
}
await dbContext.UserBumpAccountRevisionDateByCipherIdAsync(cipher.Id, cipher.OrganizationId.GetValueOrDefault());
if (cipher.OrganizationId.HasValue)
{
await dbContext.UserBumpAccountRevisionDateByCipherIdAsync(cipher.Id, cipher.OrganizationId.Value);
}
else if (cipher.UserId.HasValue)
{
await dbContext.UserBumpAccountRevisionDateAsync(cipher.UserId.Value);
}
await dbContext.SaveChangesAsync();
return true;
}
@@ -677,7 +703,7 @@ public class CipherRepository : Repository<Core.Entities.Cipher, Cipher, Guid>,
if (attachment.OrganizationId.HasValue)
{
await OrganizationUpdateStorage(cipher.OrganizationId.Value);
await dbContext.UserBumpAccountRevisionDateByCipherIdAsync(cipher.Id, cipher.OrganizationId);
await dbContext.UserBumpAccountRevisionDateByCipherIdAsync(cipher.Id, cipher.OrganizationId.Value);
}
else if (attachment.UserId.HasValue)
{

View File

@@ -34,7 +34,7 @@ public static class DatabaseContextExtensions
UpdateUserRevisionDate(users);
}
public static async Task UserBumpAccountRevisionDateByCipherIdAsync(this DatabaseContext context, Guid cipherId, Guid? organizationId)
public static async Task UserBumpAccountRevisionDateByCipherIdAsync(this DatabaseContext context, Guid cipherId, Guid organizationId)
{
var query = new UserBumpAccountRevisionDateByCipherIdQuery(cipherId, organizationId);
var users = await query.Run(context).ToListAsync();

View File

@@ -103,7 +103,7 @@ public class ProviderUserRepository :
return await query.FirstOrDefaultAsync();
}
}
public async Task<ICollection<ProviderUserUserDetails>> GetManyDetailsByProviderAsync(Guid providerId)
public async Task<ICollection<ProviderUserUserDetails>> GetManyDetailsByProviderAsync(Guid providerId, ProviderUserStatusType? status)
{
using (var scope = ServiceScopeFactory.CreateScope())
{
@@ -113,17 +113,19 @@ public class ProviderUserRepository :
on pu.UserId equals u.Id into u_g
from u in u_g.DefaultIfEmpty()
select new { pu, u };
var data = await view.Where(e => e.pu.ProviderId == providerId).Select(e => new ProviderUserUserDetails
{
Id = e.pu.Id,
UserId = e.pu.UserId,
ProviderId = e.pu.ProviderId,
Name = e.u.Name,
Email = e.u.Email ?? e.pu.Email,
Status = e.pu.Status,
Type = e.pu.Type,
Permissions = e.pu.Permissions,
}).ToArrayAsync();
var data = await view
.Where(e => e.pu.ProviderId == providerId && (status == null || e.pu.Status == status))
.Select(e => new ProviderUserUserDetails
{
Id = e.pu.Id,
UserId = e.pu.UserId,
ProviderId = e.pu.ProviderId,
Name = e.u.Name,
Email = e.u.Email ?? e.pu.Email,
Status = e.pu.Status,
Type = e.pu.Type,
Permissions = e.pu.Permissions,
}).ToArrayAsync();
return data;
}
}

View File

@@ -37,6 +37,7 @@ public class OrganizationUserOrganizationDetailsViewQuery : IQuery<OrganizationU
Use2fa = o.Use2fa,
UseApi = o.UseApi,
UseResetPassword = o.UseResetPassword,
UseSecretsManager = o.UseSecretsManager,
SelfHost = o.SelfHost,
UsersGetPremium = o.UsersGetPremium,
UseCustomPermissions = o.UseCustomPermissions,
@@ -58,7 +59,8 @@ public class OrganizationUserOrganizationDetailsViewQuery : IQuery<OrganizationU
FamilySponsorshipFriendlyName = os.FriendlyName,
FamilySponsorshipLastSyncDate = os.LastSyncDate,
FamilySponsorshipToDelete = os.ToDelete,
FamilySponsorshipValidUntil = os.ValidUntil
FamilySponsorshipValidUntil = os.ValidUntil,
AccessSecretsManager = ou.AccessSecretsManager,
};
return query;
}

View File

@@ -29,6 +29,7 @@ public class OrganizationUserUserDetailsViewQuery : IQuery<OrganizationUserUserD
Permissions = x.ou.Permissions,
ResetPasswordKey = x.ou.ResetPasswordKey,
UsesKeyConnector = x.u != null && x.u.UsesKeyConnector,
AccessSecretsManager = x.ou.AccessSecretsManager,
});
}
}

View File

@@ -41,6 +41,7 @@ public class ProviderUserOrganizationDetailsViewQuery : IQuery<ProviderUserOrgan
PrivateKey = x.o.PrivateKey,
ProviderId = x.p.Id,
ProviderName = x.p.Name,
PlanType = x.o.PlanType
});
}
}

View File

@@ -1,5 +1,4 @@
using Bit.Core.Entities;
using Bit.Core.Enums;
using Bit.Core.Enums;
using User = Bit.Infrastructure.EntityFramework.Models.User;
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries;
@@ -7,15 +6,9 @@ namespace Bit.Infrastructure.EntityFramework.Repositories.Queries;
public class UserBumpAccountRevisionDateByCipherIdQuery : IQuery<User>
{
private readonly Guid _cipherId;
private readonly Guid? _organizationId;
private readonly Guid _organizationId;
public UserBumpAccountRevisionDateByCipherIdQuery(Cipher cipher)
{
_cipherId = cipher.Id;
_organizationId = cipher.OrganizationId;
}
public UserBumpAccountRevisionDateByCipherIdQuery(Guid cipherId, Guid? organizationId)
public UserBumpAccountRevisionDateByCipherIdQuery(Guid cipherId, Guid organizationId)
{
_cipherId = cipherId;
_organizationId = organizationId;