mirror of
https://github.com/bitwarden/server
synced 2026-01-01 08:03:23 +00:00
Fix DI
This commit is contained in:
@@ -1,13 +1,9 @@
|
||||
using Bit.Core.KeyManagement.Models.Api.Request;
|
||||
using Bit.Core.KeyManagement.Repositories;
|
||||
using Bit.Core.Repositories;
|
||||
|
||||
namespace Bit.Core.KeyManagement.Commands.Interfaces;
|
||||
|
||||
public interface ISetAccountKeysForUserCommand
|
||||
{
|
||||
Task SetAccountKeysForUserAsync(Guid userId,
|
||||
AccountKeysRequestModel accountKeys,
|
||||
IUserRepository userRepository,
|
||||
IUserSignatureKeyPairRepository userSignatureKeyPairRepository);
|
||||
AccountKeysRequestModel accountKeys);
|
||||
}
|
||||
|
||||
@@ -9,9 +9,19 @@ namespace Bit.Core.KeyManagement.Commands;
|
||||
|
||||
public class SetAccountKeysForUserCommand : ISetAccountKeysForUserCommand
|
||||
{
|
||||
public async Task SetAccountKeysForUserAsync(Guid userId, AccountKeysRequestModel accountKeys, IUserRepository userRepository, IUserSignatureKeyPairRepository userSignatureKeyPairRepository)
|
||||
private readonly IUserRepository _userRepository;
|
||||
private readonly IUserSignatureKeyPairRepository _userSignatureKeyPairRepository;
|
||||
public SetAccountKeysForUserCommand(
|
||||
IUserRepository userRepository,
|
||||
IUserSignatureKeyPairRepository userSignatureKeyPairRepository)
|
||||
{
|
||||
var user = await userRepository.GetByIdAsync(userId);
|
||||
_userRepository = userRepository;
|
||||
_userSignatureKeyPairRepository = userSignatureKeyPairRepository;
|
||||
}
|
||||
|
||||
public async Task SetAccountKeysForUserAsync(Guid userId, AccountKeysRequestModel accountKeys)
|
||||
{
|
||||
var user = await _userRepository.GetByIdAsync(userId);
|
||||
if (user == null)
|
||||
{
|
||||
throw new ArgumentException("User not found", nameof(userId));
|
||||
@@ -29,7 +39,7 @@ public class SetAccountKeysForUserCommand : ISetAccountKeysForUserCommand
|
||||
user.SignedPublicKey = accountKeysData.PublicKeyEncryptionKeyPairData.SignedPublicKey;
|
||||
user.SecurityState = accountKeysData.SecurityStateData.SecurityState;
|
||||
user.SecurityVersion = accountKeysData.SecurityStateData.SecurityVersion;
|
||||
await userSignatureKeyPairRepository.UpsertAsync(new UserSignatureKeyPair
|
||||
await _userSignatureKeyPairRepository.UpsertAsync(new UserSignatureKeyPair
|
||||
{
|
||||
Id = CoreHelpers.GenerateComb(),
|
||||
UserId = userId,
|
||||
@@ -40,6 +50,6 @@ public class SetAccountKeysForUserCommand : ISetAccountKeysForUserCommand
|
||||
RevisionDate = DateTime.UtcNow,
|
||||
});
|
||||
}
|
||||
await userRepository.ReplaceAsync(user);
|
||||
await _userRepository.ReplaceAsync(user);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ public static class KeyManagementServiceCollectionExtensions
|
||||
{
|
||||
services.AddScoped<IRegenerateUserAsymmetricKeysCommand, RegenerateUserAsymmetricKeysCommand>();
|
||||
services.AddScoped<IChangeKdfCommand, ChangeKdfCommand>();
|
||||
services.AddScoped<ISetAccountKeysForUserCommand, SetAccountKeysForUserCommand>();
|
||||
}
|
||||
|
||||
private static void AddKeyManagementQueries(this IServiceCollection services)
|
||||
|
||||
Reference in New Issue
Block a user