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

[pm-14025] Remove usage of ActiveUserState from organization.service #11799

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

BTreston
Copy link
Contributor

@BTreston BTreston commented Oct 30, 2024

🎟️ Tracking

https://bitwarden.atlassian.net/browse/PM-14025

📔 Objective

We are deprecating ActiveUserState. Remove it from OrganizationService so that its methods always require a UserId or an Observable.

This PR adds vNextOrganizationService. The stateful methods are fully tested but not wired up yet. The goal is to focus on the new service implementation in isolation, and then wire it up in a following PR.

📸 Screenshots

⏰ Reminders before review

  • Contributor guidelines followed
  • All formatters and local linters executed and passed
  • Written new unit and / or integration tests where applicable
  • Protected functional changes with optionality (feature flags)
  • Used internationalization (i18n) for all UI strings
  • CI builds passed
  • Communicated to DevOps any deployment requirements
  • Updated any necessary documentation (Confluence, contributing docs) or informed the documentation team

🦮 Reviewer guidelines

  • 👍 (:+1:) or similar for great changes
  • 📝 (:memo:) or ℹ️ (:information_source:) for notes or general info
  • ❓ (:question:) for questions
  • 🤔 (:thinking:) or 💭 (:thought_balloon:) for more open inquiry that's not quite a confirmed issue and could potentially benefit from discussion
  • 🎨 (:art:) for suggestions / improvements
  • ❌ (:x:) or ⚠️ (:warning:) for more significant problems or concerns needing attention
  • 🌱 (:seedling:) or ♻️ (:recycle:) for future improvements or indications of technical debt
  • ⛏ (:pick:) for minor or nitpick changes

Copy link

codecov bot commented Oct 30, 2024

Codecov Report

Attention: Patch coverage is 33.33333% with 38 lines in your changes missing coverage. Please review.

Project coverage is 33.48%. Comparing base (ac0e008) to head (3c09561).
Report is 44 commits behind head on main.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...actions/organization/vnext.organization.service.ts 0.00% 31 Missing ⚠️
...organization/default-vnext-organization.service.ts 72.72% 5 Missing and 1 partial ⚠️
.../services/organization/vnext-organization.state.ts 75.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #11799      +/-   ##
==========================================
+ Coverage   33.44%   33.48%   +0.04%     
==========================================
  Files        2844     2849       +5     
  Lines       89043    89271     +228     
  Branches    16982    17012      +30     
==========================================
+ Hits        29777    29891     +114     
- Misses      56929    57026      +97     
- Partials     2337     2354      +17     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@BTreston BTreston marked this pull request as ready for review October 31, 2024 16:01
@BTreston BTreston requested a review from a team as a code owner October 31, 2024 16:01
Copy link
Member

@eliykat eliykat left a comment

Choose a reason for hiding this comment

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

Nice work!

Copy link
Member

Choose a reason for hiding this comment

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

Please fix the naming of these classes while you're here:

  • abstract class has no prefix or suffix: organization.service.ts
  • the default (common) implementation has a "default" prefix: default-organization.service.ts

Or for this PR, vnext-organization.service.ts and default-vnext.organization.service.ts.

ref

Copy link
Member

Choose a reason for hiding this comment

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

I approve of removing deprecated / duplicate interfaces from this class!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just to be clear on this one:

  • rename the class definitions in organization.service.ts to include the "default" prefix
  • rename organization.service.ts to default-organization.service.ts
  • rename new vnext-[filename] files to default-vnext[filename]

This would include updating the import statements across some 150 files. Just want to double check before making that wide a change. The other requested changes have been committed to this branch.

Copy link
Member

@eliykat eliykat Nov 12, 2024

Choose a reason for hiding this comment

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

I've commented on each file to clarify exact naming.

No need to rename the current organization service given that we're about to replace it anyway. But I thought that you're going to have to update all the calling locations when you wire up this new implementation (in the next PR), so it's a good opportunity to update the name while we're at it.

*/
export abstract class vNextOrganizationService {
/**
* Publishes state for all organizations under the active user.
Copy link
Member

Choose a reason for hiding this comment

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

This needs to be updated - it's now for the specified UserId, not the active user.
EDIT: same for other comments in this file.

const fakeUserId = Utils.newGuid() as UserId;
let fakeAccountService: FakeAccountService;
let fakeStateProvider: FakeStateProvider;
let fakeActiveUserState: FakeActiveUserState<Record<string, OrganizationData>>;
Copy link
Member

Choose a reason for hiding this comment

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

ActiveUserState is being deprecated, that includes test fakes such this one. Also, the sut no longer has any concept of an "active user", so we shouldn't use it in our tests. You should be able to delete FakeActiveUserState and just rely on FakeStateProvider. See the collection service vnext tests as an example.

Where the tests refer to an active user vs. a non-active user, they should be rewritten to just use 2 separate fake user states (without any reference to "active"). They would now test that altering 1 user state does not alter the other user's state.

Copy link
Contributor

github-actions bot commented Nov 11, 2024

Logo
Checkmarx One – Scan Summary & Detailse7828b4c-a2d9-43df-8a07-604194bd1d07

New Issues

Severity Issue Source File / Package Checkmarx Insight
MEDIUM Unpinned Actions Full Length Commit SHA /repository-management.yml: 167 Pinning an action to a full length commit SHA is currently the only way to use an action as an immutable release. Pinning to a particular SHA helps...
MEDIUM Unpinned Actions Full Length Commit SHA /repository-management.yml: 254 Pinning an action to a full length commit SHA is currently the only way to use an action as an immutable release. Pinning to a particular SHA helps...
MEDIUM Unpinned Actions Full Length Commit SHA /repository-management.yml: 187 Pinning an action to a full length commit SHA is currently the only way to use an action as an immutable release. Pinning to a particular SHA helps...
MEDIUM Unpinned Actions Full Length Commit SHA /build-desktop.yml: 305 Pinning an action to a full length commit SHA is currently the only way to use an action as an immutable release. Pinning to a particular SHA helps...
MEDIUM Unpinned Actions Full Length Commit SHA /repository-management.yml: 114 Pinning an action to a full length commit SHA is currently the only way to use an action as an immutable release. Pinning to a particular SHA helps...
MEDIUM Unpinned Actions Full Length Commit SHA /repository-management.yml: 194 Pinning an action to a full length commit SHA is currently the only way to use an action as an immutable release. Pinning to a particular SHA helps...
MEDIUM Unpinned Actions Full Length Commit SHA /repository-management.yml: 372 Pinning an action to a full length commit SHA is currently the only way to use an action as an immutable release. Pinning to a particular SHA helps...
MEDIUM Unpinned Actions Full Length Commit SHA /build-desktop.yml: 1368 Pinning an action to a full length commit SHA is currently the only way to use an action as an immutable release. Pinning to a particular SHA helps...
MEDIUM Unpinned Actions Full Length Commit SHA /build-desktop.yml: 1319 Pinning an action to a full length commit SHA is currently the only way to use an action as an immutable release. Pinning to a particular SHA helps...
MEDIUM Unpinned Actions Full Length Commit SHA /repository-management.yml: 201 Pinning an action to a full length commit SHA is currently the only way to use an action as an immutable release. Pinning to a particular SHA helps...
MEDIUM Unpinned Actions Full Length Commit SHA /repository-management.yml: 208 Pinning an action to a full length commit SHA is currently the only way to use an action as an immutable release. Pinning to a particular SHA helps...
MEDIUM Unpinned Actions Full Length Commit SHA /build-desktop.yml: 915 Pinning an action to a full length commit SHA is currently the only way to use an action as an immutable release. Pinning to a particular SHA helps...
MEDIUM Unpinned Actions Full Length Commit SHA /repository-management.yml: 306 Pinning an action to a full length commit SHA is currently the only way to use an action as an immutable release. Pinning to a particular SHA helps...
LOW Unpinned Actions Full Length Commit SHA /build-desktop.yml: 1368 Pinning an action to a full length commit SHA is currently the only way to use an action as an immutable release. Pinning to a particular SHA helps...
LOW Unpinned Actions Full Length Commit SHA /repository-management.yml: 167 Pinning an action to a full length commit SHA is currently the only way to use an action as an immutable release. Pinning to a particular SHA helps...
LOW Unpinned Actions Full Length Commit SHA /repository-management.yml: 201 Pinning an action to a full length commit SHA is currently the only way to use an action as an immutable release. Pinning to a particular SHA helps...
LOW Unpinned Actions Full Length Commit SHA /repository-management.yml: 372 Pinning an action to a full length commit SHA is currently the only way to use an action as an immutable release. Pinning to a particular SHA helps...
LOW Unpinned Actions Full Length Commit SHA /repository-management.yml: 306 Pinning an action to a full length commit SHA is currently the only way to use an action as an immutable release. Pinning to a particular SHA helps...
LOW Unpinned Actions Full Length Commit SHA /build-desktop.yml: 305 Pinning an action to a full length commit SHA is currently the only way to use an action as an immutable release. Pinning to a particular SHA helps...
LOW Unpinned Actions Full Length Commit SHA /repository-management.yml: 254 Pinning an action to a full length commit SHA is currently the only way to use an action as an immutable release. Pinning to a particular SHA helps...
LOW Unpinned Actions Full Length Commit SHA /build-desktop.yml: 915 Pinning an action to a full length commit SHA is currently the only way to use an action as an immutable release. Pinning to a particular SHA helps...
LOW Unpinned Actions Full Length Commit SHA /repository-management.yml: 187 Pinning an action to a full length commit SHA is currently the only way to use an action as an immutable release. Pinning to a particular SHA helps...
LOW Unpinned Actions Full Length Commit SHA /repository-management.yml: 114 Pinning an action to a full length commit SHA is currently the only way to use an action as an immutable release. Pinning to a particular SHA helps...
LOW Unpinned Actions Full Length Commit SHA /repository-management.yml: 208 Pinning an action to a full length commit SHA is currently the only way to use an action as an immutable release. Pinning to a particular SHA helps...
LOW Unpinned Actions Full Length Commit SHA /build-desktop.yml: 1319 Pinning an action to a full length commit SHA is currently the only way to use an action as an immutable release. Pinning to a particular SHA helps...
LOW Unpinned Actions Full Length Commit SHA /repository-management.yml: 194 Pinning an action to a full length commit SHA is currently the only way to use an action as an immutable release. Pinning to a particular SHA helps...

Fixed Issues

Severity Issue Source File / Package
MEDIUM Unpinned Actions Full Length Commit SHA /build-desktop.yml: 318
MEDIUM Unpinned Actions Full Length Commit SHA /repository-management.yml: 173
MEDIUM Unpinned Actions Full Length Commit SHA /repository-management.yml: 113
MEDIUM Unpinned Actions Full Length Commit SHA /repository-management.yml: 207
MEDIUM Unpinned Actions Full Length Commit SHA /build-desktop.yml: 928
MEDIUM Unpinned Actions Full Length Commit SHA /build-desktop.yml: 1381
MEDIUM Unpinned Actions Full Length Commit SHA /repository-management.yml: 193
MEDIUM Unpinned Actions Full Length Commit SHA /repository-management.yml: 214
MEDIUM Unpinned Actions Full Length Commit SHA /repository-management.yml: 200
MEDIUM Unpinned Actions Full Length Commit SHA /repository-management.yml: 260
MEDIUM Unpinned Actions Full Length Commit SHA /repository-management.yml: 378
MEDIUM Unpinned Actions Full Length Commit SHA /build-desktop.yml: 1332
MEDIUM Unpinned Actions Full Length Commit SHA /repository-management.yml: 312
LOW Client_JQuery_Deprecated_Symbols /apps/cli/src/service-container/service-container.ts: 876
LOW Client_JQuery_Deprecated_Symbols /libs/importer/src/services/import.service.ts: 467
LOW Unpinned Actions Full Length Commit SHA /build-desktop.yml: 1332
LOW Unpinned Actions Full Length Commit SHA /repository-management.yml: 113
LOW Unpinned Actions Full Length Commit SHA /repository-management.yml: 312
LOW Unpinned Actions Full Length Commit SHA /build-desktop.yml: 1381
LOW Unpinned Actions Full Length Commit SHA /repository-management.yml: 207
LOW Unpinned Actions Full Length Commit SHA /repository-management.yml: 193
LOW Unpinned Actions Full Length Commit SHA /repository-management.yml: 200
LOW Unpinned Actions Full Length Commit SHA /build-desktop.yml: 928
LOW Unpinned Actions Full Length Commit SHA /repository-management.yml: 378
LOW Unpinned Actions Full Length Commit SHA /build-desktop.yml: 318
LOW Unpinned Actions Full Length Commit SHA /repository-management.yml: 214
LOW Unpinned Actions Full Length Commit SHA /repository-management.yml: 260
LOW Unpinned Actions Full Length Commit SHA /repository-management.yml: 173

Copy link
Member

@eliykat eliykat Nov 12, 2024

Choose a reason for hiding this comment

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

I've commented on each file to clarify exact naming.

No need to rename the current organization service given that we're about to replace it anyway. But I thought that you're going to have to update all the calling locations when you wire up this new implementation (in the next PR), so it's a good opportunity to update the name while we're at it.

@jrmccannon jrmccannon removed their request for review November 14, 2024 19:48
Copy link
Member

@eliykat eliykat left a comment

Choose a reason for hiding this comment

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

Just this and then we should be good to go.

The next stage of this is to update all callers to use the new interface and implementation. That will affect a lot of calling locations, so you may want to consider whether to update 1 client at a time (1 client per PR) rather than all at once.

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