mirror of
https://github.com/bitwarden/server.git
synced 2025-07-01 08:02:49 -05:00
remove deprecated code
This commit is contained in:
@ -16,7 +16,6 @@ namespace Bit.Api.Controllers
|
|||||||
public class CiphersController : Controller
|
public class CiphersController : Controller
|
||||||
{
|
{
|
||||||
private readonly ICipherRepository _cipherRepository;
|
private readonly ICipherRepository _cipherRepository;
|
||||||
private readonly IFolderRepository _folderRepository;
|
|
||||||
private readonly ICollectionCipherRepository _collectionCipherRepository;
|
private readonly ICollectionCipherRepository _collectionCipherRepository;
|
||||||
private readonly ICipherService _cipherService;
|
private readonly ICipherService _cipherService;
|
||||||
private readonly IUserService _userService;
|
private readonly IUserService _userService;
|
||||||
@ -24,14 +23,12 @@ namespace Bit.Api.Controllers
|
|||||||
|
|
||||||
public CiphersController(
|
public CiphersController(
|
||||||
ICipherRepository cipherRepository,
|
ICipherRepository cipherRepository,
|
||||||
IFolderRepository folderRepository,
|
|
||||||
ICollectionCipherRepository collectionCipherRepository,
|
ICollectionCipherRepository collectionCipherRepository,
|
||||||
ICipherService cipherService,
|
ICipherService cipherService,
|
||||||
IUserService userService,
|
IUserService userService,
|
||||||
CurrentContext currentContext)
|
CurrentContext currentContext)
|
||||||
{
|
{
|
||||||
_cipherRepository = cipherRepository;
|
_cipherRepository = cipherRepository;
|
||||||
_folderRepository = folderRepository;
|
|
||||||
_collectionCipherRepository = collectionCipherRepository;
|
_collectionCipherRepository = collectionCipherRepository;
|
||||||
_cipherService = cipherService;
|
_cipherService = cipherService;
|
||||||
_userService = userService;
|
_userService = userService;
|
||||||
@ -68,26 +65,11 @@ namespace Bit.Api.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("")]
|
[HttpGet("")]
|
||||||
public async Task<ListResponseModel<CipherResponseModel>> Get(bool includeFolders = true, bool includeShared = false)
|
public async Task<ListResponseModel<CipherResponseModel>> Get()
|
||||||
{
|
{
|
||||||
var userId = _userService.GetProperUserId(User).Value;
|
var userId = _userService.GetProperUserId(User).Value;
|
||||||
var ciphers = await _cipherRepository.GetManyByUserIdAsync(userId);
|
var ciphers = await _cipherRepository.GetManyByUserIdAsync(userId);
|
||||||
|
|
||||||
// For backwards compat, do not include shared ciphers. Can be removed in a future release.
|
|
||||||
if(!includeShared)
|
|
||||||
{
|
|
||||||
ciphers = ciphers.Where(c => !c.OrganizationId.HasValue).ToList();
|
|
||||||
}
|
|
||||||
|
|
||||||
var responses = ciphers.Select(c => new CipherResponseModel(c)).ToList();
|
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);
|
return new ListResponseModel<CipherResponseModel>(responses);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -123,39 +105,13 @@ namespace Bit.Api.Controllers
|
|||||||
return new ListResponseModel<CipherMiniDetailsResponseModel>(responses);
|
return new ListResponseModel<CipherMiniDetailsResponseModel>(responses);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Obsolete]
|
|
||||||
[HttpGet("history")]
|
|
||||||
public Task<CipherHistoryResponseModel> Get(DateTime since)
|
|
||||||
{
|
|
||||||
return Task.FromResult(new CipherHistoryResponseModel());
|
|
||||||
}
|
|
||||||
|
|
||||||
[HttpPost("import")]
|
[HttpPost("import")]
|
||||||
public async Task PostImport([FromBody]ImportPasswordsRequestModel model)
|
public async Task PostImport([FromBody]ImportPasswordsRequestModel model)
|
||||||
{
|
{
|
||||||
var userId = _userService.GetProperUserId(User).Value;
|
var userId = _userService.GetProperUserId(User).Value;
|
||||||
var folders = model.Folders.Select(f => f.ToFolder(userId)).ToList();
|
var folders = model.Folders.Select(f => f.ToFolder(userId)).ToList();
|
||||||
var ciphers = model.Logins.Select(l => l.ToCipherDetails(userId)).ToList();
|
var ciphers = model.Logins.Select(l => l.ToCipherDetails(userId)).ToList();
|
||||||
|
await _cipherService.ImportCiphersAsync(folders, ciphers, model.FolderRelationships);
|
||||||
await _cipherService.ImportCiphersAsync(
|
|
||||||
folders,
|
|
||||||
ciphers,
|
|
||||||
model.FolderRelationships);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Obsolete]
|
|
||||||
[HttpPut("{id}/favorite")]
|
|
||||||
[HttpPost("{id}/favorite")]
|
|
||||||
public async Task Favorite(string id)
|
|
||||||
{
|
|
||||||
var userId = _userService.GetProperUserId(User).Value;
|
|
||||||
var cipher = await _cipherRepository.GetByIdAsync(new Guid(id), userId);
|
|
||||||
if(cipher == null)
|
|
||||||
{
|
|
||||||
throw new NotFoundException();
|
|
||||||
}
|
|
||||||
|
|
||||||
await _cipherRepository.UpdatePartialAsync(new Guid(id), userId, cipher.FolderId, !cipher.Favorite);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPut("{id}/partial")]
|
[HttpPut("{id}/partial")]
|
||||||
|
@ -8,9 +8,6 @@ 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
|
||||||
{
|
{
|
||||||
@ -21,20 +18,17 @@ 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;
|
||||||
@ -72,10 +66,8 @@ namespace Bit.Api.Controllers
|
|||||||
public async Task<ListResponseModel<LoginResponseModel>> Get(string[] expand = null)
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -161,39 +153,5 @@ 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,14 +0,0 @@
|
|||||||
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; }
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,16 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace Bit.Core.Models.Api
|
|
||||||
{
|
|
||||||
[Obsolete]
|
|
||||||
public class CipherHistoryResponseModel : ResponseModel
|
|
||||||
{
|
|
||||||
public CipherHistoryResponseModel()
|
|
||||||
: base("cipherHistory")
|
|
||||||
{ }
|
|
||||||
|
|
||||||
public IEnumerable<CipherResponseModel> Revised { get; set; } = new List<CipherResponseModel>();
|
|
||||||
public IEnumerable<string> Deleted { get; set; } = new List<string>();
|
|
||||||
}
|
|
||||||
}
|
|
@ -31,21 +31,6 @@ 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 Id { get; set; }
|
||||||
public string OrganizationId { get; set; }
|
public string OrganizationId { get; set; }
|
||||||
public Enums.CipherType Type { get; set; }
|
public Enums.CipherType Type { get; set; }
|
||||||
@ -63,11 +48,6 @@ namespace Bit.Core.Models.Api
|
|||||||
Edit = cipher.Edit;
|
Edit = cipher.Edit;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Obsolete]
|
|
||||||
public CipherResponseModel(Folder folder, string obj = "cipher")
|
|
||||||
: base(folder, obj)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
public string FolderId { get; set; }
|
public string FolderId { get; set; }
|
||||||
public bool Favorite { get; set; }
|
public bool Favorite { get; set; }
|
||||||
public bool Edit { get; set; }
|
public bool Edit { get; set; }
|
||||||
|
@ -51,8 +51,5 @@ 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; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user