mirror of
https://github.com/bitwarden/server.git
synced 2024-11-23 12:25:16 +01:00
add back folder expand for backwards compat.
This commit is contained in:
parent
02c1b4e08c
commit
8ac0be7477
@ -8,6 +8,9 @@ using Bit.Core.Models.Api;
|
|||||||
using Bit.Core.Exceptions;
|
using Bit.Core.Exceptions;
|
||||||
using Bit.Core.Services;
|
using Bit.Core.Services;
|
||||||
using Bit.Core;
|
using Bit.Core;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Core.Models.Data;
|
||||||
|
using Bit.Core.Models.Table;
|
||||||
|
|
||||||
namespace Bit.Api.Controllers
|
namespace Bit.Api.Controllers
|
||||||
{
|
{
|
||||||
@ -18,17 +21,20 @@ namespace Bit.Api.Controllers
|
|||||||
public class LoginsController : Controller
|
public class LoginsController : Controller
|
||||||
{
|
{
|
||||||
private readonly ICipherRepository _cipherRepository;
|
private readonly ICipherRepository _cipherRepository;
|
||||||
|
private readonly IFolderRepository _folderRepository;
|
||||||
private readonly ICipherService _cipherService;
|
private readonly ICipherService _cipherService;
|
||||||
private readonly IUserService _userService;
|
private readonly IUserService _userService;
|
||||||
private readonly CurrentContext _currentContext;
|
private readonly CurrentContext _currentContext;
|
||||||
|
|
||||||
public LoginsController(
|
public LoginsController(
|
||||||
ICipherRepository cipherRepository,
|
ICipherRepository cipherRepository,
|
||||||
|
IFolderRepository folderRepository,
|
||||||
ICipherService cipherService,
|
ICipherService cipherService,
|
||||||
IUserService userService,
|
IUserService userService,
|
||||||
CurrentContext currentContext)
|
CurrentContext currentContext)
|
||||||
{
|
{
|
||||||
_cipherRepository = cipherRepository;
|
_cipherRepository = cipherRepository;
|
||||||
|
_folderRepository = folderRepository;
|
||||||
_cipherService = cipherService;
|
_cipherService = cipherService;
|
||||||
_userService = userService;
|
_userService = userService;
|
||||||
_currentContext = currentContext;
|
_currentContext = currentContext;
|
||||||
@ -63,12 +69,13 @@ namespace Bit.Api.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("")]
|
[HttpGet("")]
|
||||||
public async Task<ListResponseModel<LoginResponseModel>> Get()
|
public async Task<ListResponseModel<LoginResponseModel>> Get(string[] expand = null)
|
||||||
{
|
{
|
||||||
var userId = _userService.GetProperUserId(User).Value;
|
var userId = _userService.GetProperUserId(User).Value;
|
||||||
var logins = await _cipherRepository.GetManyByTypeAndUserIdAsync(Core.Enums.CipherType.Login,
|
var logins = await _cipherRepository.GetManyByTypeAndUserIdAsync(Core.Enums.CipherType.Login,
|
||||||
userId);
|
userId);
|
||||||
var responses = logins.Select(l => new LoginResponseModel(l)).ToList();
|
var responses = logins.Select(l => new LoginResponseModel(l)).ToList();
|
||||||
|
await ExpandManyAsync(logins, responses, expand, userId);
|
||||||
return new ListResponseModel<LoginResponseModel>(responses);
|
return new ListResponseModel<LoginResponseModel>(responses);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,5 +154,39 @@ namespace Bit.Api.Controllers
|
|||||||
|
|
||||||
await _cipherService.DeleteAsync(login, userId);
|
await _cipherService.DeleteAsync(login, userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Obsolete]
|
||||||
|
private async Task ExpandManyAsync(IEnumerable<CipherDetails> logins, ICollection<LoginResponseModel> responses,
|
||||||
|
string[] expand, Guid userId)
|
||||||
|
{
|
||||||
|
if(expand == null || expand.Count() == 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(expand.Any(e => e.ToLower() == "folder"))
|
||||||
|
{
|
||||||
|
var folders = await _folderRepository.GetManyByUserIdAsync(userId);
|
||||||
|
if(folders != null && folders.Count() > 0)
|
||||||
|
{
|
||||||
|
foreach(var response in responses)
|
||||||
|
{
|
||||||
|
var login = logins.SingleOrDefault(s => s.Id.ToString() == response.Id);
|
||||||
|
if(login == null)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
var folder = folders.SingleOrDefault(f => f.Id == login.FolderId);
|
||||||
|
if(folder == null)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
response.Folder = new FolderResponseModel(folder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,6 +48,9 @@ namespace Bit.Core.Models.Api
|
|||||||
public string Password { get; set; }
|
public string Password { get; set; }
|
||||||
public string Notes { get; set; }
|
public string Notes { get; set; }
|
||||||
public DateTime RevisionDate { get; set; }
|
public DateTime RevisionDate { get; set; }
|
||||||
|
|
||||||
|
[Obsolete]
|
||||||
|
public FolderResponseModel Folder { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class LoginDetailsResponseModel : LoginResponseModel
|
public class LoginDetailsResponseModel : LoginResponseModel
|
||||||
|
Loading…
Reference in New Issue
Block a user