mirror of
https://github.com/bitwarden/server.git
synced 2025-05-22 12:04:27 -05:00
subvault ciphers
This commit is contained in:
parent
072fb727a8
commit
47477f6ca5
@ -15,15 +15,18 @@ namespace Bit.Api.Controllers
|
|||||||
public class CiphersController : Controller
|
public class CiphersController : Controller
|
||||||
{
|
{
|
||||||
private readonly ICipherRepository _cipherRepository;
|
private readonly ICipherRepository _cipherRepository;
|
||||||
|
private readonly ISubvaultCipherRepository _subvaultCipherRepository;
|
||||||
private readonly ICipherService _cipherService;
|
private readonly ICipherService _cipherService;
|
||||||
private readonly IUserService _userService;
|
private readonly IUserService _userService;
|
||||||
|
|
||||||
public CiphersController(
|
public CiphersController(
|
||||||
ICipherRepository cipherRepository,
|
ICipherRepository cipherRepository,
|
||||||
|
ISubvaultCipherRepository subvaultCipherRepository,
|
||||||
ICipherService cipherService,
|
ICipherService cipherService,
|
||||||
IUserService userService)
|
IUserService userService)
|
||||||
{
|
{
|
||||||
_cipherRepository = cipherRepository;
|
_cipherRepository = cipherRepository;
|
||||||
|
_subvaultCipherRepository = subvaultCipherRepository;
|
||||||
_cipherService = cipherService;
|
_cipherService = cipherService;
|
||||||
_userService = userService;
|
_userService = userService;
|
||||||
}
|
}
|
||||||
@ -50,6 +53,16 @@ namespace Bit.Api.Controllers
|
|||||||
return new ListResponseModel<CipherResponseModel>(responses);
|
return new ListResponseModel<CipherResponseModel>(responses);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpGet("subvaults")]
|
||||||
|
public async Task<ListResponseModel<CipherDetailsResponseModel>> GetSubvaults()
|
||||||
|
{
|
||||||
|
var userId = _userService.GetProperUserId(User).Value;
|
||||||
|
var ciphers = await _cipherRepository.GetManyByUserIdHasSubvaultsAsync(userId);
|
||||||
|
var subvaultCiphers = await _subvaultCipherRepository.GetManyByUserIdAsync(userId);
|
||||||
|
var responses = ciphers.Select(c => new CipherDetailsResponseModel(c, subvaultCiphers));
|
||||||
|
return new ListResponseModel<CipherDetailsResponseModel>(responses);
|
||||||
|
}
|
||||||
|
|
||||||
//[Obsolete]
|
//[Obsolete]
|
||||||
//[HttpGet("history")]
|
//[HttpGet("history")]
|
||||||
//public async Task<CipherHistoryResponseModel> Get(DateTime since)
|
//public async Task<CipherHistoryResponseModel> Get(DateTime since)
|
||||||
|
@ -10,6 +10,7 @@ namespace Bit.Core.Repositories
|
|||||||
{
|
{
|
||||||
Task<CipherDetails> GetByIdAsync(Guid id, Guid userId);
|
Task<CipherDetails> GetByIdAsync(Guid id, Guid userId);
|
||||||
Task<ICollection<CipherDetails>> GetManyByUserIdAsync(Guid userId);
|
Task<ICollection<CipherDetails>> GetManyByUserIdAsync(Guid userId);
|
||||||
|
Task<ICollection<CipherDetails>> GetManyByUserIdHasSubvaultsAsync(Guid userId);
|
||||||
Task<ICollection<CipherDetails>> GetManyByTypeAndUserIdAsync(Enums.CipherType type, Guid userId);
|
Task<ICollection<CipherDetails>> GetManyByTypeAndUserIdAsync(Enums.CipherType type, Guid userId);
|
||||||
Task<Tuple<ICollection<CipherDetails>, ICollection<Guid>>> GetManySinceRevisionDateAndUserIdWithDeleteHistoryAsync(
|
Task<Tuple<ICollection<CipherDetails>, ICollection<Guid>>> GetManySinceRevisionDateAndUserIdWithDeleteHistoryAsync(
|
||||||
DateTime sinceRevisionDate, Guid userId);
|
DateTime sinceRevisionDate, Guid userId);
|
||||||
|
12
src/Core/Repositories/ISubvaultCipherRepository.cs
Normal file
12
src/Core/Repositories/ISubvaultCipherRepository.cs
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Bit.Core.Models.Table;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Bit.Core.Repositories
|
||||||
|
{
|
||||||
|
public interface ISubvaultCipherRepository
|
||||||
|
{
|
||||||
|
Task<ICollection<SubvaultCipher>> GetManyByUserIdAsync(Guid userId);
|
||||||
|
}
|
||||||
|
}
|
@ -49,6 +49,19 @@ namespace Bit.Core.Repositories.SqlServer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<ICollection<CipherDetails>> GetManyByUserIdHasSubvaultsAsync(Guid userId)
|
||||||
|
{
|
||||||
|
using(var connection = new SqlConnection(ConnectionString))
|
||||||
|
{
|
||||||
|
var results = await connection.QueryAsync<CipherDetails>(
|
||||||
|
$"[{Schema}].[CipherDetails_ReadByUserIdHasSubvault]",
|
||||||
|
new { UserId = userId },
|
||||||
|
commandType: CommandType.StoredProcedure);
|
||||||
|
|
||||||
|
return results.ToList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<ICollection<CipherDetails>> GetManyByTypeAndUserIdAsync(Enums.CipherType type, Guid userId)
|
public async Task<ICollection<CipherDetails>> GetManyByTypeAndUserIdAsync(Enums.CipherType type, Guid userId)
|
||||||
{
|
{
|
||||||
using(var connection = new SqlConnection(ConnectionString))
|
using(var connection = new SqlConnection(ConnectionString))
|
||||||
|
35
src/Core/Repositories/SqlServer/SubvaultCipherRepository.cs
Normal file
35
src/Core/Repositories/SqlServer/SubvaultCipherRepository.cs
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
using System;
|
||||||
|
using Bit.Core.Models.Table;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Data.SqlClient;
|
||||||
|
using System.Data;
|
||||||
|
using Dapper;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace Bit.Core.Repositories.SqlServer
|
||||||
|
{
|
||||||
|
public class SubvaultCipherRepository : BaseRepository, ISubvaultCipherRepository
|
||||||
|
{
|
||||||
|
public SubvaultCipherRepository(GlobalSettings globalSettings)
|
||||||
|
: this(globalSettings.SqlServer.ConnectionString)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
public SubvaultCipherRepository(string connectionString)
|
||||||
|
: base(connectionString)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
public async Task<ICollection<SubvaultCipher>> GetManyByUserIdAsync(Guid userId)
|
||||||
|
{
|
||||||
|
using(var connection = new SqlConnection(ConnectionString))
|
||||||
|
{
|
||||||
|
var results = await connection.QueryAsync<SubvaultCipher>(
|
||||||
|
$"[dbo].[SubvaultCipher_ReadByUserId]",
|
||||||
|
new { UserId = userId },
|
||||||
|
commandType: CommandType.StoredProcedure);
|
||||||
|
|
||||||
|
return results.ToList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user