clients icon indicating copy to clipboard operation
clients copied to clipboard

Migrate existing organizations state from `StateService` → `StateProvider`

Open addisonbeck opened this issue 2 years ago • 6 comments

Type of change

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

Objective

This PR migrates OrganizationService over to StateProvider.

Before you submit

  • 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
  • Ensure that all UI additions follow WCAG AA requirements

References

addisonbeck avatar Feb 09 '24 19:02 addisonbeck

Codecov Report

Attention: Patch coverage is 50.40650% with 61 lines in your changes are missing coverage. Please review.

Project coverage is 26.20%. Comparing base (ca86288) to head (d2f9644).

Files Patch % Lines
...rets-manager/projects/project/project.component.ts 0.00% 7 Missing :warning:
...ganizations/settings/two-factor-setup.component.ts 0.00% 6 Missing :warning:
...c/app/secrets-manager/shared/new-menu.component.ts 0.00% 6 Missing :warning:
...sole/services/organization/organization.service.ts 80.00% 3 Missing and 2 partials :warning:
.../secrets-manager/shared/org-suspended.component.ts 0.00% 3 Missing :warning:
libs/importer/src/components/import.component.ts 0.00% 3 Missing :warning:
apps/browser/src/background/main.background.ts 0.00% 2 Missing :warning:
apps/desktop/src/app/app.component.ts 0.00% 2 Missing :warning:
.../organizations/reporting/reports-home.component.ts 0.00% 2 Missing :warning:
apps/web/src/app/app.component.ts 0.00% 2 Missing :warning:
... and 22 more
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7895   +/-   ##
=======================================
  Coverage   26.20%   26.20%           
=======================================
  Files        2280     2280           
  Lines       66727    66735    +8     
  Branches    12549    12550    +1     
=======================================
+ Hits        17483    17489    +6     
- Misses      47881    47883    +2     
  Partials     1363     1363           

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Feb 09 '24 19:02 codecov[bot]

Logo Checkmarx One – Scan Summary & Details25ceb7aa-26da-48db-8216-4e6673958871

No New Or Fixed Issues Found

bitwarden-bot avatar Feb 09 '24 20:02 bitwarden-bot

@justindbaur that makes sense. It is important to me to make incremental steps here for several reasons. Is there any good way for me to "queue" up a migration so that the migration can be written and tested without being implemented yet? I had thought of just removing it from the migration list & renaming the file without a number. Then applying the migration would just involve numbering the migration and adding it to the list. The still seems a little complicated though, so I'm wondering if you've got any better ideas?

addisonbeck avatar Feb 12 '24 21:02 addisonbeck

@addisonbeck There is no way to queue up a migration, moving the backing location of your data is kind of an all or nothing move. If you're trying to keep things small you can delete some of the type assertions in here: https://github.com/bitwarden/clients/pull/7895/files#diff-397e257f75aaf8565e7025b97bbf6d6c0830fb174aceaa38522097a74422f2dcR54-R103

If the properties aren't referenced in the migration code they don't really contribute, what's is most important are the types for the account object shape leading up to your data. Then your data can be represented with an unknown.

Then, if you use the same observable names that the state service ones use you can switch over their backing data right now. Then you can have another 1 or 2 PR's that rename those observables to the new name if you want and one for deleting the state service methods and account property.

With those changes I think this PR would actually be slightly smaller.

justindbaur avatar Feb 13 '24 14:02 justindbaur

Renaming the exposed methods & observables separately is a good idea. I'll go that route, thanks!

addisonbeck avatar Feb 13 '24 16:02 addisonbeck

@justindbaur @eliykat This ended up getting bigger since many of OrganizationService's methods were made async. Would y'all mind giving it a review before I open it up to teams to review the changes to OrganizationService callers?

addisonbeck avatar Feb 15 '24 00:02 addisonbeck

Apologies for the miscommunication about making interface changes. I was under the impression you asked for them. I'm not even remotely upset about reverting, as I was not enjoying how large the PR had gotten, even though I did think the changes were for the best.

That said, I didn't completely revert things. Here's how the change set looks now:

  • ~~There are 0 interface changes that impact callers. Every method signature that existed before still exists now and has not been altered. This means we don't have to bug other teams and can know where the bugs are coming from if they show up. Yay ✨~~ This is no longer true
  • I kept all of the new interface methods and mappers. I marked old methods as deprecated, and pointed them to the new ones in their function bodies. This isn't always the most elegant solution (there are several really bad uses of observables in order to facilitate the not-promise based methods that were checking the current value of _organizations without async/await), but it does mean we will have an easy time deleting them later.
  • I kept all the mapper functions, and still wrote everything as if one observable and a collection of operator functions is the direction we'd go in later when we update callers. I know you had some concerns about this, and figured we'd still talk it through in more detail later, but I do have some arguments in favor of this pattern so I didn't want to scrap what was already written.
  • Once this has had some time to prove itself in production I'd like to handle updating callers to use observable patterns as tech debt on a team-by-team basis, or even more gradually if desired.

addisonbeck avatar Feb 28 '24 00:02 addisonbeck

A tech debt task has been created for paying the tech debt associated with this PR that led to so much discussion: The service's continued use of promises for get operations.

addisonbeck avatar Feb 28 '24 23:02 addisonbeck