1
0
mirror of https://github.com/bitwarden/server.git synced 2025-05-22 12:04:27 -05:00

subvault ciphers

This commit is contained in:
Kyle Spearrin 2017-03-23 17:43:12 -04:00
parent 072fb727a8
commit 47477f6ca5
5 changed files with 74 additions and 0 deletions

View File

@ -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)

View File

@ -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);

View 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);
}
}

View File

@ -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))

View 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();
}
}
}
}