mirror of
https://github.com/bitwarden/server.git
synced 2025-06-30 23:52:50 -05:00
[EC-584] Removed ListResponseModel from OrganizationExportResponseModel (#2316)
* [EC-584] Removed ListResponseModel from OrganizationExportResponseModel properties * [EC-584] Added backwards compatibility for client version 2022.9.0 * [EC-584] Added property 'ClientVersion' to ICurrentContext * [EC-584] Added backwards compatibility for version 2022.10.0 * [EC-584] Change ICurrentContext.ClientVersion from string to Version * [EC-584] Remove check for versions before 2022.9.0 because they do not use this endpoint
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
using Bit.Api.Models.Response;
|
||||
using Bit.Core.Context;
|
||||
using Bit.Core.Entities;
|
||||
using Bit.Core.Services;
|
||||
using Bit.Core.Settings;
|
||||
@ -12,17 +13,20 @@ namespace Bit.Api.Controllers;
|
||||
[Authorize("Application")]
|
||||
public class OrganizationExportController : Controller
|
||||
{
|
||||
private readonly ICurrentContext _currentContext;
|
||||
private readonly IUserService _userService;
|
||||
private readonly ICollectionService _collectionService;
|
||||
private readonly ICipherService _cipherService;
|
||||
private readonly GlobalSettings _globalSettings;
|
||||
|
||||
public OrganizationExportController(
|
||||
ICurrentContext currentContext,
|
||||
ICipherService cipherService,
|
||||
ICollectionService collectionService,
|
||||
IUserService userService,
|
||||
GlobalSettings globalSettings)
|
||||
{
|
||||
_currentContext = currentContext;
|
||||
_cipherService = cipherService;
|
||||
_collectionService = collectionService;
|
||||
_userService = userService;
|
||||
@ -30,20 +34,32 @@ public class OrganizationExportController : Controller
|
||||
}
|
||||
|
||||
[HttpGet("export")]
|
||||
public async Task<OrganizationExportResponseModel> Export(Guid organizationId)
|
||||
public async Task<IActionResult> Export(Guid organizationId)
|
||||
{
|
||||
var userId = _userService.GetProperUserId(User).Value;
|
||||
|
||||
IEnumerable<Collection> orgCollections = await _collectionService.GetOrganizationCollections(organizationId);
|
||||
(IEnumerable<CipherOrganizationDetails> orgCiphers, Dictionary<Guid, IGrouping<Guid, CollectionCipher>> collectionCiphersGroupDict) = await _cipherService.GetOrganizationCiphers(userId, organizationId);
|
||||
|
||||
var result = new OrganizationExportResponseModel
|
||||
// Backward compatibility with versions before 2022.11.0 that use ListResponseModel
|
||||
if (_currentContext.ClientVersion < new Version("2022.11.0"))
|
||||
{
|
||||
Collections = GetOrganizationCollectionsResponse(orgCollections),
|
||||
Ciphers = GetOrganizationCiphersResponse(orgCiphers, collectionCiphersGroupDict)
|
||||
var organizationExportListResponseModel = new OrganizationExportListResponseModel
|
||||
{
|
||||
Collections = GetOrganizationCollectionsResponse(orgCollections),
|
||||
Ciphers = GetOrganizationCiphersResponse(orgCiphers, collectionCiphersGroupDict)
|
||||
};
|
||||
|
||||
return Ok(organizationExportListResponseModel);
|
||||
}
|
||||
|
||||
var organizationExportResponseModel = new OrganizationExportResponseModel
|
||||
{
|
||||
Collections = orgCollections.Select(c => new CollectionResponseModel(c)),
|
||||
Ciphers = orgCiphers.Select(c => new CipherMiniDetailsResponseModel(c, _globalSettings, collectionCiphersGroupDict, c.OrganizationUseTotp))
|
||||
};
|
||||
|
||||
return result;
|
||||
return Ok(organizationExportResponseModel);
|
||||
}
|
||||
|
||||
private ListResponseModel<CollectionResponseModel> GetOrganizationCollectionsResponse(IEnumerable<Collection> orgCollections)
|
||||
|
@ -1,11 +1,21 @@
|
||||
namespace Bit.Api.Models.Response;
|
||||
using Bit.Core.Models.Api;
|
||||
|
||||
public class OrganizationExportResponseModel
|
||||
namespace Bit.Api.Models.Response;
|
||||
|
||||
public class OrganizationExportResponseModel : ResponseModel
|
||||
{
|
||||
public OrganizationExportResponseModel()
|
||||
public OrganizationExportResponseModel() : base("organizationExport")
|
||||
{
|
||||
}
|
||||
|
||||
public IEnumerable<CollectionResponseModel> Collections { get; set; }
|
||||
|
||||
public IEnumerable<CipherMiniDetailsResponseModel> Ciphers { get; set; }
|
||||
}
|
||||
|
||||
[Obsolete("This version is for backwards compatibility for client version 2022.9.0")]
|
||||
public class OrganizationExportListResponseModel
|
||||
{
|
||||
public ListResponseModel<CollectionResponseModel> Collections { get; set; }
|
||||
|
||||
public ListResponseModel<CipherMiniDetailsResponseModel> Ciphers { get; set; }
|
||||
|
Reference in New Issue
Block a user