From fe59186c9667d48421ce7ee1bee2f87ff433168a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rui=20Tom=C3=A9?= <108268980+r-tome@users.noreply.github.com> Date: Tue, 6 Dec 2022 15:35:05 +0000 Subject: [PATCH] [EC-584] Add TryParse to ClientVersion due to QA builds having an appended git hash (#2395) * [EC-584] Add TryParse to ClientVersion due to QA builds having an appended git hash * [EC-584] Add string.Split to only get 'ClientVersion' number when the input value includes the git hash * Revert "[EC-584] Add string.Split to only get 'ClientVersion' number when the input value includes the git hash" This reverts commit 9ebad69c6a88527c8240b152057ff6d7722ef602. * [EC-584] Update client version check to 2022.12 * [EC-584] Inverted check on ClientVersion * [EC-584] Bumped version check to version 2023.01 * [EC-584] Removed the 0 prefix from the client version check --- .../OrganizationExportController.cs | 20 +++++++++---------- src/Core/Context/CurrentContext.cs | 4 ++-- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Api/Controllers/OrganizationExportController.cs b/src/Api/Controllers/OrganizationExportController.cs index 9c075b18f..cde9a4a15 100644 --- a/src/Api/Controllers/OrganizationExportController.cs +++ b/src/Api/Controllers/OrganizationExportController.cs @@ -41,25 +41,25 @@ public class OrganizationExportController : Controller IEnumerable orgCollections = await _collectionService.GetOrganizationCollections(organizationId); (IEnumerable orgCiphers, Dictionary> collectionCiphersGroupDict) = await _cipherService.GetOrganizationCiphers(userId, organizationId); - // Backward compatibility with versions before 2022.11.0 that use ListResponseModel - if (_currentContext.ClientVersion < new Version("2022.11.0")) + if (_currentContext.ClientVersion == null || _currentContext.ClientVersion >= new Version("2023.1.0")) { - var organizationExportListResponseModel = new OrganizationExportListResponseModel + var organizationExportResponseModel = new OrganizationExportResponseModel { - Collections = GetOrganizationCollectionsResponse(orgCollections), - Ciphers = GetOrganizationCiphersResponse(orgCiphers, collectionCiphersGroupDict) + Collections = orgCollections.Select(c => new CollectionResponseModel(c)), + Ciphers = orgCiphers.Select(c => new CipherMiniDetailsResponseModel(c, _globalSettings, collectionCiphersGroupDict, c.OrganizationUseTotp)) }; - return Ok(organizationExportListResponseModel); + return Ok(organizationExportResponseModel); } - var organizationExportResponseModel = new OrganizationExportResponseModel + // Backward compatibility with versions before 2023.1.0 that use ListResponseModel + var organizationExportListResponseModel = new OrganizationExportListResponseModel { - Collections = orgCollections.Select(c => new CollectionResponseModel(c)), - Ciphers = orgCiphers.Select(c => new CipherMiniDetailsResponseModel(c, _globalSettings, collectionCiphersGroupDict, c.OrganizationUseTotp)) + Collections = GetOrganizationCollectionsResponse(orgCollections), + Ciphers = GetOrganizationCiphersResponse(orgCiphers, collectionCiphersGroupDict) }; - return Ok(organizationExportResponseModel); + return Ok(organizationExportListResponseModel); } private ListResponseModel GetOrganizationCollectionsResponse(IEnumerable orgCollections) diff --git a/src/Core/Context/CurrentContext.cs b/src/Core/Context/CurrentContext.cs index 8c4d40579..6e9fa2971 100644 --- a/src/Core/Context/CurrentContext.cs +++ b/src/Core/Context/CurrentContext.cs @@ -82,9 +82,9 @@ public class CurrentContext : ICurrentContext MaybeBot = httpContext.Request.Headers["X-Cf-Maybe-Bot"] == "1"; } - if (httpContext.Request.Headers.ContainsKey("Bitwarden-Client-Version")) + if (httpContext.Request.Headers.ContainsKey("Bitwarden-Client-Version") && Version.TryParse(httpContext.Request.Headers["Bitwarden-Client-Version"], out var cVersion)) { - ClientVersion = new Version(httpContext.Request.Headers["Bitwarden-Client-Version"]); + ClientVersion = cVersion; } }