mirror of
https://github.com/bitwarden/server.git
synced 2024-11-29 13:25:17 +01:00
backwards compat for folders in cipher listing
This commit is contained in:
parent
d87441c9fe
commit
54f58ba14d
@ -16,6 +16,7 @@ namespace Bit.Api.Controllers
|
||||
public class CiphersController : Controller
|
||||
{
|
||||
private readonly ICipherRepository _cipherRepository;
|
||||
private readonly IFolderRepository _folderRepository;
|
||||
private readonly ISubvaultCipherRepository _subvaultCipherRepository;
|
||||
private readonly ICipherService _cipherService;
|
||||
private readonly IUserService _userService;
|
||||
@ -23,12 +24,14 @@ namespace Bit.Api.Controllers
|
||||
|
||||
public CiphersController(
|
||||
ICipherRepository cipherRepository,
|
||||
IFolderRepository folderRepository,
|
||||
ISubvaultCipherRepository subvaultCipherRepository,
|
||||
ICipherService cipherService,
|
||||
IUserService userService,
|
||||
CurrentContext currentContext)
|
||||
{
|
||||
_cipherRepository = cipherRepository;
|
||||
_folderRepository = folderRepository;
|
||||
_subvaultCipherRepository = subvaultCipherRepository;
|
||||
_cipherService = cipherService;
|
||||
_userService = userService;
|
||||
@ -64,11 +67,19 @@ namespace Bit.Api.Controllers
|
||||
}
|
||||
|
||||
[HttpGet("")]
|
||||
public async Task<ListResponseModel<CipherResponseModel>> Get()
|
||||
public async Task<ListResponseModel<CipherResponseModel>> Get(bool includeFolders = true)
|
||||
{
|
||||
var userId = _userService.GetProperUserId(User).Value;
|
||||
var ciphers = await _cipherRepository.GetManyByUserIdAsync(userId);
|
||||
var responses = ciphers.Select(c => new CipherResponseModel(c));
|
||||
var responses = ciphers.Select(c => new CipherResponseModel(c)).ToList();
|
||||
|
||||
// Folders are included for backwards compat. Can be removed in a future release.
|
||||
if(includeFolders)
|
||||
{
|
||||
var folders = await _folderRepository.GetManyByUserIdAsync(userId);
|
||||
responses.AddRange(folders.Select(f => new CipherResponseModel(f)));
|
||||
}
|
||||
|
||||
return new ListResponseModel<CipherResponseModel>(responses);
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,8 @@
|
||||
{
|
||||
public enum CipherType : byte
|
||||
{
|
||||
//Folder = 0,
|
||||
// Folder is deprecated
|
||||
Folder = 0,
|
||||
Login = 1
|
||||
}
|
||||
}
|
||||
|
14
src/Core/Models/Api/FolderDataModel.cs
Normal file
14
src/Core/Models/Api/FolderDataModel.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using Bit.Core.Models.Table;
|
||||
|
||||
namespace Bit.Core.Models.Api
|
||||
{
|
||||
public class FolderDataModel
|
||||
{
|
||||
public FolderDataModel(Folder folder)
|
||||
{
|
||||
Name = folder.Name;
|
||||
}
|
||||
|
||||
public string Name { get; set; }
|
||||
}
|
||||
}
|
@ -31,6 +31,21 @@ namespace Bit.Core.Models.Api
|
||||
}
|
||||
}
|
||||
|
||||
[Obsolete]
|
||||
public CipherMiniResponseModel(Folder folder, string obj = "cipherMini")
|
||||
: base(obj)
|
||||
{
|
||||
if(folder == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(folder));
|
||||
}
|
||||
|
||||
Id = folder.Id.ToString();
|
||||
Type = Enums.CipherType.Folder;
|
||||
RevisionDate = folder.RevisionDate;
|
||||
Data = new FolderDataModel(folder);
|
||||
}
|
||||
|
||||
public string Id { get; set; }
|
||||
public string OrganizationId { get; set; }
|
||||
public Enums.CipherType Type { get; set; }
|
||||
@ -47,6 +62,11 @@ namespace Bit.Core.Models.Api
|
||||
Favorite = cipher.Favorite;
|
||||
}
|
||||
|
||||
[Obsolete]
|
||||
public CipherResponseModel(Folder folder, string obj = "cipher")
|
||||
: base(folder, obj)
|
||||
{ }
|
||||
|
||||
public string FolderId { get; set; }
|
||||
public bool Favorite { get; set; }
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user