Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EC-584] Removed ListResponseModel from OrganizationExportResponseModel #2316

Conversation

r-tome
Copy link
Contributor

@r-tome r-tome commented Sep 29, 2022

Type of change

- [X] Bug fix
- [ ] New feature development
- [ ] Tech debt (refactoring, code cleanup, dependency upgrades, etc)
- [ ] Build/deploy pipeline (DevOps)
- [ ] Other

Objective

There is an issue on exporting an organization vault where the nested data from the API response was not being parsed.
These changes revert the behavior back to what it was to previously before the unintended change by removing the wrap with ListResponseModel.

Code changes

Related client changes on this PR.

  • src/Api/Controllers/OrganizationExportController.cs: Removed the creation of ListResponseModels
  • src/Api/Models/Response/OrganizationExportResponseModel.cs: Removed the ListResponseModel wrap from the properties

Before you submit

  • Please check for formatting errors (dotnet format --verify-no-changes) (required)
  • If making database changes - make sure you also update Entity Framework queries and/or migrations
  • Please add unit tests where it makes sense to do so (encouraged but not required)
  • If this change requires a documentation update - notify the documentation team
  • If this change has particular deployment requirements - notify the DevOps team

Hinton
Hinton previously approved these changes Sep 29, 2022
Copy link
Member

@Hinton Hinton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks @r-tome

@Hinton
Copy link
Member

Hinton commented Oct 7, 2022

@r-tome We need to add a version check here since the CLI uses this endpoint. The clients sends a Bitwarden-Client-Version header we can use to check, if it's 2022.9.0 we should return the old wrapped response. And add a tech debt task to remove it in 9 months.

@r-tome
Copy link
Contributor Author

r-tome commented Oct 7, 2022

@Hinton thanks for the heads up, that is well spotted! I've included a basic version check on the controller and created the tech debt ticket.

@BlackDex
Copy link
Contributor

This now probably also needs to be checked for the 2022.10.0 version i guess?

@r-tome
Copy link
Contributor Author

r-tome commented Oct 12, 2022

This now probably also needs to be checked for the 2022.10.0 version i guess?

Correct! I've updated the branch with the new version.
Thank you for your question.

{
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 2022.9.0 and 2022.10.0 that use ListResponseModel
if (new[] { "2022.9.0", "2022.10.0" }.Contains(_currentContext.ClientVersion))
Copy link
Member

@Hinton Hinton Oct 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to have a parser for version and just mark it as _currentContext.ClientVersion.GreaterThan("2022.10.0") or _currentContext.ClientVersion > ClientVersion(2022, 10, 0). But that seems somewhat out of scope

Copy link
Member

@Hinton Hinton Oct 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or not, we need to include web 9.1 and 9.2 as well, at which point this feels like a pain.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I change the ICurrentContext.ClientVersion property to be an instance of the Version class and this ables us to compare versions.
I'm assuming this fix will go out on version 2022.11.0, is that correct?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, depends when QA can test it.

@r-tome r-tome requested a review from Hinton October 13, 2022 16:51
Copy link
Member

@Hinton Hinton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks for iterating on this!

@r-tome r-tome added needs-qa and removed needs-qa labels Nov 2, 2022
{
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"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to bump this right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed, this will be cherry-picked to rc and will be on version 2022.11.

@r-tome r-tome merged commit 8a6f780 into master Nov 7, 2022
@r-tome r-tome deleted the EC-584-the-new-organization-export-is-case-sensitive-in-regards-to-the-server-response-with-ciphers-and-collections branch November 7, 2022 12:01
r-tome added a commit that referenced this pull request Nov 7, 2022
…el (#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

(cherry picked from commit 8a6f780)
BlackDex added a commit to BlackDex/vaultwarden that referenced this pull request Nov 7, 2022
Since v2022.9.x the org export uses a different endpoint.
But, since v2022.11.x this endpoint will return a different format.
See: bitwarden/clients#3641 and bitwarden/server#2316

To support both version in the case of users having an older client
either web-vault or cli this PR checks the version and responds using
the correct format. If no version can be determined it will use the new
format as a default.
BlackDex added a commit to BlackDex/vaultwarden that referenced this pull request Nov 7, 2022
Since v2022.9.x the org export uses a different endpoint.
But, since v2022.11.x this endpoint will return a different format.
See: bitwarden/clients#3641 and bitwarden/server#2316

To support both version in the case of users having an older client
either web-vault or cli this PR checks the version and responds using
the correct format. If no version can be determined it will use the new
format as a default.
r-tome added a commit that referenced this pull request Nov 8, 2022
r-tome added a commit that referenced this pull request Dec 6, 2022
…el (#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

(cherry picked from commit 8a6f780)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants