diff --git a/src/Api/Controllers/CiphersController.cs b/src/Api/Controllers/CiphersController.cs index 7fb274ebc..1f6865317 100644 --- a/src/Api/Controllers/CiphersController.cs +++ b/src/Api/Controllers/CiphersController.cs @@ -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> Get() + public async Task> 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(responses); } diff --git a/src/Core/Enums/CipherType.cs b/src/Core/Enums/CipherType.cs index 65242f18c..65d8ed657 100644 --- a/src/Core/Enums/CipherType.cs +++ b/src/Core/Enums/CipherType.cs @@ -2,7 +2,8 @@ { public enum CipherType : byte { - //Folder = 0, + // Folder is deprecated + Folder = 0, Login = 1 } } diff --git a/src/Core/Models/Api/FolderDataModel.cs b/src/Core/Models/Api/FolderDataModel.cs new file mode 100644 index 000000000..55d46311a --- /dev/null +++ b/src/Core/Models/Api/FolderDataModel.cs @@ -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; } + } +} diff --git a/src/Core/Models/Api/Response/CipherResponseModel.cs b/src/Core/Models/Api/Response/CipherResponseModel.cs index 616723f41..d2a823445 100644 --- a/src/Core/Models/Api/Response/CipherResponseModel.cs +++ b/src/Core/Models/Api/Response/CipherResponseModel.cs @@ -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; } }