mirror of
https://github.com/bitwarden/server.git
synced 2025-06-20 02:48:03 -05:00
Add query and fix types
This commit is contained in:
parent
ccf1ffa90f
commit
de3efbeaf7
@ -401,9 +401,9 @@ public class AccountsController : Controller
|
|||||||
var hasPremiumFromOrg = await _userService.HasPremiumFromOrganization(user);
|
var hasPremiumFromOrg = await _userService.HasPremiumFromOrganization(user);
|
||||||
var organizationIdsClaimingActiveUser = await GetOrganizationIdsClaimingUserAsync(user.Id);
|
var organizationIdsClaimingActiveUser = await GetOrganizationIdsClaimingUserAsync(user.Id);
|
||||||
|
|
||||||
var userAccountKeysData = await _userAccountKeysQuery.Run(user);
|
var accountKeysResponse = new PrivateKeysResponseModel(await _userAccountKeysQuery.Run(user));
|
||||||
|
|
||||||
var response = new ProfileResponseModel(user, userAccountKeysData, organizationUserDetails, providerUserDetails,
|
var response = new ProfileResponseModel(user, accountKeysResponse, organizationUserDetails, providerUserDetails,
|
||||||
providerUserOrganizationDetails, twoFactorEnabled,
|
providerUserOrganizationDetails, twoFactorEnabled,
|
||||||
hasPremiumFromOrg, organizationIdsClaimingActiveUser);
|
hasPremiumFromOrg, organizationIdsClaimingActiveUser);
|
||||||
return response;
|
return response;
|
||||||
@ -438,7 +438,7 @@ public class AccountsController : Controller
|
|||||||
var organizationIdsClaimingActiveUser = await GetOrganizationIdsClaimingUserAsync(user.Id);
|
var organizationIdsClaimingActiveUser = await GetOrganizationIdsClaimingUserAsync(user.Id);
|
||||||
var userAccountKeysData = await _userAccountKeysQuery.Run(user);
|
var userAccountKeysData = await _userAccountKeysQuery.Run(user);
|
||||||
|
|
||||||
var response = new ProfileResponseModel(user, userAccountKeysData, null, null, null, twoFactorEnabled, hasPremiumFromOrg, organizationIdsClaimingActiveUser);
|
var response = new ProfileResponseModel(user, new PrivateKeysResponseModel(userAccountKeysData), null, null, null, twoFactorEnabled, hasPremiumFromOrg, organizationIdsClaimingActiveUser);
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -456,9 +456,9 @@ public class AccountsController : Controller
|
|||||||
var userTwoFactorEnabled = await _twoFactorIsEnabledQuery.TwoFactorIsEnabledAsync(user);
|
var userTwoFactorEnabled = await _twoFactorIsEnabledQuery.TwoFactorIsEnabledAsync(user);
|
||||||
var userHasPremiumFromOrganization = await _userService.HasPremiumFromOrganization(user);
|
var userHasPremiumFromOrganization = await _userService.HasPremiumFromOrganization(user);
|
||||||
var organizationIdsClaimingActiveUser = await GetOrganizationIdsClaimingUserAsync(user.Id);
|
var organizationIdsClaimingActiveUser = await GetOrganizationIdsClaimingUserAsync(user.Id);
|
||||||
var userAccountKeysData = await _userAccountKeysQuery.Run(user);
|
var accountKeys = new PrivateKeysResponseModel(await _userAccountKeysQuery.Run(user));
|
||||||
|
|
||||||
var response = new ProfileResponseModel(user, userAccountKeysData, null, null, null, userTwoFactorEnabled, userHasPremiumFromOrganization, organizationIdsClaimingActiveUser);
|
var response = new ProfileResponseModel(user, accountKeys, null, null, null, userTwoFactorEnabled, userHasPremiumFromOrganization, organizationIdsClaimingActiveUser);
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ public class AccountsController(
|
|||||||
var userTwoFactorEnabled = await twoFactorIsEnabledQuery.TwoFactorIsEnabledAsync(user);
|
var userTwoFactorEnabled = await twoFactorIsEnabledQuery.TwoFactorIsEnabledAsync(user);
|
||||||
var userHasPremiumFromOrganization = await userService.HasPremiumFromOrganization(user);
|
var userHasPremiumFromOrganization = await userService.HasPremiumFromOrganization(user);
|
||||||
var organizationIdsClaimingActiveUser = await GetOrganizationIdsClaimingUserAsync(user.Id);
|
var organizationIdsClaimingActiveUser = await GetOrganizationIdsClaimingUserAsync(user.Id);
|
||||||
var userAccountKeysData = await userAccountKeysQuery.Run(user);
|
var userAccountKeysData = new PrivateKeysResponseModel(await userAccountKeysQuery.Run(user));
|
||||||
|
|
||||||
var profile = new ProfileResponseModel(user, userAccountKeysData, null, null, null, userTwoFactorEnabled,
|
var profile = new ProfileResponseModel(user, userAccountKeysData, null, null, null, userTwoFactorEnabled,
|
||||||
userHasPremiumFromOrganization, organizationIdsClaimingActiveUser);
|
userHasPremiumFromOrganization, organizationIdsClaimingActiveUser);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
using Bit.Api.KeyManagement.Models.Response;
|
using Bit.Api.KeyManagement.Models.Response;
|
||||||
|
using Bit.Api.KeyManagement.Queries;
|
||||||
using Bit.Core.Exceptions;
|
using Bit.Core.Exceptions;
|
||||||
using Bit.Core.KeyManagement.Repositories;
|
|
||||||
using Bit.Core.Repositories;
|
using Bit.Core.Repositories;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
@ -10,19 +10,10 @@ namespace Bit.Api.Controllers;
|
|||||||
|
|
||||||
[Route("users")]
|
[Route("users")]
|
||||||
[Authorize("Application")]
|
[Authorize("Application")]
|
||||||
public class UsersController : Controller
|
public class UsersController(
|
||||||
|
IUserRepository _userRepository,
|
||||||
|
IUserAccountKeysQuery _userAccountKeysQuery) : Controller
|
||||||
{
|
{
|
||||||
private readonly IUserRepository _userRepository;
|
|
||||||
private readonly IUserSignatureKeyPairRepository _signatureKeyPairRepository;
|
|
||||||
|
|
||||||
public UsersController(
|
|
||||||
IUserRepository userRepository,
|
|
||||||
IUserSignatureKeyPairRepository signatureKeyPairRepository)
|
|
||||||
{
|
|
||||||
_userRepository = userRepository;
|
|
||||||
_signatureKeyPairRepository = signatureKeyPairRepository;
|
|
||||||
}
|
|
||||||
|
|
||||||
[HttpGet("{id}/public-key")]
|
[HttpGet("{id}/public-key")]
|
||||||
public async Task<UserKeyResponseModel> Get(string id)
|
public async Task<UserKeyResponseModel> Get(string id)
|
||||||
{
|
{
|
||||||
@ -46,9 +37,11 @@ public class UsersController : Controller
|
|||||||
throw new NotFoundException();
|
throw new NotFoundException();
|
||||||
}
|
}
|
||||||
|
|
||||||
var signingKeys = await _signatureKeyPairRepository.GetByUserIdAsync(guidId);
|
var accountKeys = await _userAccountKeysQuery.Run(user);
|
||||||
var verifyingKey = signingKeys?.VerifyingKey;
|
if (accountKeys == null)
|
||||||
|
{
|
||||||
return new PublicKeysResponseModel(verifyingKey, user.PublicKey, null);
|
throw new NotFoundException("User account keys not found.");
|
||||||
|
}
|
||||||
|
return new PublicKeysResponseModel(accountKeys);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,8 +13,10 @@ namespace Bit.Api.Models.Response;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class PrivateKeysResponseModel : ResponseModel
|
public class PrivateKeysResponseModel : ResponseModel
|
||||||
{
|
{
|
||||||
public PrivateKeysResponseModel(UserAccountKeysData accountKeys) : base("accountKeys")
|
[System.Diagnostics.CodeAnalysis.SetsRequiredMembersAttribute]
|
||||||
|
public PrivateKeysResponseModel(UserAccountKeysData accountKeys) : base("privateKeys")
|
||||||
{
|
{
|
||||||
|
PublicKeyEncryptionKeyPair = accountKeys.PublicKeyEncryptionKeyPairData;
|
||||||
if (accountKeys == null)
|
if (accountKeys == null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(accountKeys));
|
throw new ArgumentNullException(nameof(accountKeys));
|
||||||
@ -24,11 +26,6 @@ public class PrivateKeysResponseModel : ResponseModel
|
|||||||
{
|
{
|
||||||
SignatureKeyPair = accountKeys.SignatureKeyPairData;
|
SignatureKeyPair = accountKeys.SignatureKeyPairData;
|
||||||
}
|
}
|
||||||
PublicKeyEncryptionKeyPair = accountKeys.PublicKeyEncryptionKeyPairData;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PrivateKeysResponseModel() : base("privateKeys")
|
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Not all accounts have signature keys, but all accounts have public encryption keys.
|
// Not all accounts have signature keys, but all accounts have public encryption keys.
|
||||||
|
@ -11,9 +11,11 @@ namespace Bit.Api.KeyManagement.Models.Response;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class PublicKeysResponseModel : ResponseModel
|
public class PublicKeysResponseModel : ResponseModel
|
||||||
{
|
{
|
||||||
|
[System.Diagnostics.CodeAnalysis.SetsRequiredMembersAttribute]
|
||||||
public PublicKeysResponseModel(UserAccountKeysData accountKeys)
|
public PublicKeysResponseModel(UserAccountKeysData accountKeys)
|
||||||
: base("publicKeys")
|
: base("publicKeys")
|
||||||
{
|
{
|
||||||
|
PublicKey = accountKeys.PublicKeyEncryptionKeyPairData.PublicKey;
|
||||||
if (accountKeys == null)
|
if (accountKeys == null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(accountKeys));
|
throw new ArgumentNullException(nameof(accountKeys));
|
||||||
@ -24,11 +26,9 @@ public class PublicKeysResponseModel : ResponseModel
|
|||||||
SignedPublicKey = accountKeys.PublicKeyEncryptionKeyPairData.SignedPublicKey;
|
SignedPublicKey = accountKeys.PublicKeyEncryptionKeyPairData.SignedPublicKey;
|
||||||
VerifyingKey = accountKeys.SignatureKeyPairData.VerifyingKey;
|
VerifyingKey = accountKeys.SignatureKeyPairData.VerifyingKey;
|
||||||
}
|
}
|
||||||
PublicKey = accountKeys.PublicKeyEncryptionKeyPairData.PublicKey;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public string? VerifyingKey { get; set; }
|
public string? VerifyingKey { get; set; }
|
||||||
public string? SignedPublicKey { get; set; }
|
public string? SignedPublicKey { get; set; }
|
||||||
[System.Obsolete("Use SignedPublicKey for new code, if it is not null.")]
|
|
||||||
public required string PublicKey { get; set; }
|
public required string PublicKey { get; set; }
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
using Bit.Api.AdminConsole.Models.Response.Providers;
|
using Bit.Api.AdminConsole.Models.Response.Providers;
|
||||||
using Bit.Core.AdminConsole.Models.Data.Provider;
|
using Bit.Core.AdminConsole.Models.Data.Provider;
|
||||||
using Bit.Core.Entities;
|
using Bit.Core.Entities;
|
||||||
using Bit.Core.KeyManagement.Models.Data;
|
|
||||||
using Bit.Core.Models.Api;
|
using Bit.Core.Models.Api;
|
||||||
using Bit.Core.Models.Data.Organizations.OrganizationUsers;
|
using Bit.Core.Models.Data.Organizations.OrganizationUsers;
|
||||||
|
|
||||||
@ -11,7 +10,7 @@ namespace Bit.Api.Models.Response;
|
|||||||
public class ProfileResponseModel : ResponseModel
|
public class ProfileResponseModel : ResponseModel
|
||||||
{
|
{
|
||||||
public ProfileResponseModel(User user,
|
public ProfileResponseModel(User user,
|
||||||
UserAccountKeysData userAccountKeysData,
|
PrivateKeysResponseModel privateKeysResponseModel,
|
||||||
IEnumerable<OrganizationUserOrganizationDetails> organizationsUserDetails,
|
IEnumerable<OrganizationUserOrganizationDetails> organizationsUserDetails,
|
||||||
IEnumerable<ProviderUserProviderDetails> providerUserDetails,
|
IEnumerable<ProviderUserProviderDetails> providerUserDetails,
|
||||||
IEnumerable<ProviderUserOrganizationDetails> providerUserOrganizationDetails,
|
IEnumerable<ProviderUserOrganizationDetails> providerUserOrganizationDetails,
|
||||||
@ -34,7 +33,7 @@ public class ProfileResponseModel : ResponseModel
|
|||||||
TwoFactorEnabled = twoFactorEnabled;
|
TwoFactorEnabled = twoFactorEnabled;
|
||||||
Key = user.Key;
|
Key = user.Key;
|
||||||
PrivateKey = user.PrivateKey;
|
PrivateKey = user.PrivateKey;
|
||||||
AccountKeys = userAccountKeysData;
|
AccountKeys = privateKeysResponseModel;
|
||||||
SecurityStamp = user.SecurityStamp;
|
SecurityStamp = user.SecurityStamp;
|
||||||
ForcePasswordReset = user.ForcePasswordReset;
|
ForcePasswordReset = user.ForcePasswordReset;
|
||||||
UsesKeyConnector = user.UsesKeyConnector;
|
UsesKeyConnector = user.UsesKeyConnector;
|
||||||
@ -62,7 +61,7 @@ public class ProfileResponseModel : ResponseModel
|
|||||||
public string Key { get; set; }
|
public string Key { get; set; }
|
||||||
[Obsolete("Use AccountKeys instead.")]
|
[Obsolete("Use AccountKeys instead.")]
|
||||||
public string PrivateKey { get; set; }
|
public string PrivateKey { get; set; }
|
||||||
public UserAccountKeysData AccountKeys { get; set; }
|
public PrivateKeysResponseModel AccountKeys { get; set; }
|
||||||
public string SecurityStamp { get; set; }
|
public string SecurityStamp { get; set; }
|
||||||
public bool ForcePasswordReset { get; set; }
|
public bool ForcePasswordReset { get; set; }
|
||||||
public bool UsesKeyConnector { get; set; }
|
public bool UsesKeyConnector { get; set; }
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using Bit.Api.Vault.Models.Response;
|
using Bit.Api.Models.Response;
|
||||||
|
using Bit.Api.Vault.Models.Response;
|
||||||
using Bit.Core;
|
using Bit.Core;
|
||||||
using Bit.Core.AdminConsole.Entities;
|
using Bit.Core.AdminConsole.Entities;
|
||||||
using Bit.Core.AdminConsole.Enums.Provider;
|
using Bit.Core.AdminConsole.Enums.Provider;
|
||||||
@ -124,7 +125,7 @@ public class SyncController : Controller
|
|||||||
SignatureKeyPairData = signingKeys,
|
SignatureKeyPairData = signingKeys,
|
||||||
};
|
};
|
||||||
|
|
||||||
var response = new SyncResponseModel(_globalSettings, user, userAccountKeysData, userTwoFactorEnabled, userHasPremiumFromOrganization, organizationAbilities,
|
var response = new SyncResponseModel(_globalSettings, user, new PrivateKeysResponseModel(userAccountKeysData), userTwoFactorEnabled, userHasPremiumFromOrganization, organizationAbilities,
|
||||||
organizationIdsClaimingActiveUser, organizationUserDetails, providerUserDetails, providerUserOrganizationDetails,
|
organizationIdsClaimingActiveUser, organizationUserDetails, providerUserDetails, providerUserOrganizationDetails,
|
||||||
folders, collections, ciphers, collectionCiphersGroupDict, excludeDomains, policies, sends);
|
folders, collections, ciphers, collectionCiphersGroupDict, excludeDomains, policies, sends);
|
||||||
return response;
|
return response;
|
||||||
|
@ -4,7 +4,6 @@ using Bit.Api.Tools.Models.Response;
|
|||||||
using Bit.Core.AdminConsole.Entities;
|
using Bit.Core.AdminConsole.Entities;
|
||||||
using Bit.Core.AdminConsole.Models.Data.Provider;
|
using Bit.Core.AdminConsole.Models.Data.Provider;
|
||||||
using Bit.Core.Entities;
|
using Bit.Core.Entities;
|
||||||
using Bit.Core.KeyManagement.Models.Data;
|
|
||||||
using Bit.Core.Models.Api;
|
using Bit.Core.Models.Api;
|
||||||
using Bit.Core.Models.Data;
|
using Bit.Core.Models.Data;
|
||||||
using Bit.Core.Models.Data.Organizations;
|
using Bit.Core.Models.Data.Organizations;
|
||||||
@ -21,7 +20,7 @@ public class SyncResponseModel : ResponseModel
|
|||||||
public SyncResponseModel(
|
public SyncResponseModel(
|
||||||
GlobalSettings globalSettings,
|
GlobalSettings globalSettings,
|
||||||
User user,
|
User user,
|
||||||
UserAccountKeysData userAccountKeysData,
|
PrivateKeysResponseModel privateKeysResponseModel,
|
||||||
bool userTwoFactorEnabled,
|
bool userTwoFactorEnabled,
|
||||||
bool userHasPremiumFromOrganization,
|
bool userHasPremiumFromOrganization,
|
||||||
IDictionary<Guid, OrganizationAbility> organizationAbilities,
|
IDictionary<Guid, OrganizationAbility> organizationAbilities,
|
||||||
@ -38,7 +37,7 @@ public class SyncResponseModel : ResponseModel
|
|||||||
IEnumerable<Send> sends)
|
IEnumerable<Send> sends)
|
||||||
: base("sync")
|
: base("sync")
|
||||||
{
|
{
|
||||||
Profile = new ProfileResponseModel(user, userAccountKeysData, organizationUserDetails, providerUserDetails,
|
Profile = new ProfileResponseModel(user, privateKeysResponseModel, organizationUserDetails, providerUserDetails,
|
||||||
providerUserOrganizationDetails, userTwoFactorEnabled, userHasPremiumFromOrganization, organizationIdsClaimingingUser);
|
providerUserOrganizationDetails, userTwoFactorEnabled, userHasPremiumFromOrganization, organizationIdsClaimingingUser);
|
||||||
Folders = folders.Select(f => new FolderResponseModel(f));
|
Folders = folders.Select(f => new FolderResponseModel(f));
|
||||||
Ciphers = ciphers.Select(cipher =>
|
Ciphers = ciphers.Select(cipher =>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user