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-3000] Add Environment URLs to Account Switcher #5978

Merged
merged 28 commits into from
Nov 15, 2023

Conversation

rr-bw
Copy link
Contributor

@rr-bw rr-bw commented Aug 7, 2023

Type of change

  • New feature development

Objective

Add the environment URL to the account switcher active active tab and dropdown accounts

Code changes

  • apps/desktop/src/app/layout/account-switcher.component.html
    • Add server URL display for active account and inactive accounts
  • apps/desktop/src/app/layout/account-switcher.component.ts
    • Retrieve server URLs for active and inactive accounts
    • Refactor SwitcherAccount class to InactiveAccount type
  • libs/common/src/platform/services/environment.service.ts
    • add getHost() method to retrieve host for US, EU, or self-hosted environments
  • apps/desktop/src/scss/header.scss
    • Update header styles

Video and Screenshot

Screen.Recording.2023-10-12.at.11.18.03.AM.mov

Screenshot 2023-10-12 at 11 13 45 AM

@github-actions github-actions bot added the needs-qa Marks a PR as requiring QA approval label Aug 7, 2023
@bitwarden-bot
Copy link

bitwarden-bot commented Aug 7, 2023

Logo
Checkmarx One – Scan Summary & Details4a981a08-ec99-4091-a56f-2a9822d1c2bc

New Issues

Severity Issue Source File / Package Checkmarx Insight
LOW Client_Password_In_Comment /libs/angular/src/auth/components/sso.component.ts: 280 Attack Vector
LOW Use_Of_Hardcoded_Password /apps/desktop/src/platform/preload.ts: 25 Attack Vector
LOW Use_Of_Hardcoded_Password /apps/desktop/src/platform/preload.ts: 23 Attack Vector
LOW Use_Of_Hardcoded_Password /apps/desktop/src/platform/preload.ts: 21 Attack Vector
LOW Use_Of_Hardcoded_Password /apps/desktop/src/platform/preload.ts: 19 Attack Vector

Fixed Issues

Severity Issue Source File / Package
LOW Client_Password_In_Comment /libs/angular/src/auth/components/sso.component.ts: 213
LOW Use_Of_Hardcoded_Password /libs/importer/spec/securesafe-csv-importer.spec.ts: 41
LOW Use_Of_Hardcoded_Password /libs/importer/spec/securesafe-csv-importer.spec.ts: 20

@rr-bw rr-bw changed the title [PM-3000] Add Server URLs to Account Switcher [PM-3000] Add Environment URLs to Account Switcher Aug 8, 2023
@rr-bw rr-bw marked this pull request as ready for review August 8, 2023 00:15
@rr-bw rr-bw requested review from a team as code owners August 8, 2023 00:15
jlf0dev
jlf0dev previously approved these changes Sep 11, 2023
Copy link
Member

@jlf0dev jlf0dev 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! Just had a small suggestion but its non-blocking

libs/common/src/platform/misc/utils.ts Outdated Show resolved Hide resolved
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.

We seem to be directly modifying accounts state in a component. This shouldn't happen, any such action must go through the state service, but it's confusing in the first place why showing accounts would require that they be modified.

libs/common/src/platform/misc/utils.ts Outdated Show resolved Hide resolved
libs/angular/src/auth/components/lock.component.ts Outdated Show resolved Hide resolved
apps/desktop/src/app/layout/account-switcher.component.ts Outdated Show resolved Hide resolved
apps/desktop/src/app/layout/account-switcher.component.ts Outdated Show resolved Hide resolved
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.

Apologies for my previous comments they were quite abrupt.

I believe the account switcher has gone through a series of unfortunate refactors coupling it tighter and tighter to various states. This is a significant code smell and I believe this PR worsens the situation by loading the server config from state.

The StateService should be viewed as an internal services that other DomainServices can rely on to store and fetch their domain. Inter-domain fetching should be strictly forbidden. This means DomainServiceA is not allowed to call StateService to fetch DomainB.

Concrete blockers as I view it:

  • We're introducing getServerConfig, this should at a minimum go through the config service first.
  • The Utils.removeVaultFromHostname seems potentially dangerous. You could have a self-hosted vault on vault.company.com which would now show up as company.com. Is that intentional?
  • We have special handling for bitwarden environments burned into the code for lock.component. I believe this is better served in the EnvironmentService? (Ideally long term I would like to see an Environment class that we pass along that can have a getter for presentational text but that feels better left for the Environment service refactors)

The broader question is, why are we loading the config service in the first place? The user has EnvironmentUrls which should contain this information.


There are some quick wins that can be had in this component in my opinion.

  • Remove SwitcherAccount, the component should define it's own model for the template. This decouples it from internal state models. (Check ActiveAccount)
  • Remove authenticationStatus from AccountProfile it's weird that a state model contains a field only populated by a component. This can either be solved by introducing a new type using & { authenticationStatus: boolean }

Once we have a proper AccountService we should be able to remove direct calls to state service for these things.

@rr-bw rr-bw marked this pull request as draft October 10, 2023 18:06
@rr-bw
Copy link
Contributor Author

rr-bw commented Oct 12, 2023

@Hinton Thanks for the very helpful feedback.

I've refactored quite a bit and I think this addresses all of your concerns and ensures this PR is not introducing any new calls to stateService from the component. Here is a summary of recent changes:

  • I removed dependency on getServerConfig(...). Instead I created two new methods in the EnvironmentService:

    • getRegion(...) - allows us to optionally pass in a userId to get the region via StateService
    • getHost(...) - allows us to optionally pass in a userId and then uses the getRegion(...) method above to extract the host name for US, EU, or Self-Hosted
  • I refactored the SwitcherAccount class to an InactiveAccount intersection type (extends ActiveAccount). This way the component is only dealing with the data it actually needs (that is, we are no longer extending Account, and no longer adding authenticationStatus to AccountProfile via the component).

    • As a side note, I did some renaming here, from SwitcherAccount to InactiveAccount, because I believe this more clearly distinguishes the two types of accounts we are working with: ActiveAccount and InactiveAccount.

I've also updated the PR with a demo video. Let me know what you think. Thanks again!

Tagging @jlf0dev and @trmartin4 for visibility

@rr-bw rr-bw marked this pull request as ready for review October 12, 2023 19:05
@rr-bw rr-bw requested a review from Hinton October 12, 2023 19:07
Hinton
Hinton previously approved these changes Oct 16, 2023
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.

Nice, this looks significantly more maintainable. Thanks for iterating on this!

libs/common/src/platform/services/environment.service.ts Outdated Show resolved Hide resolved
libs/common/src/platform/services/environment.service.ts Outdated Show resolved Hide resolved
@rr-bw rr-bw requested a review from Hinton October 18, 2023 19:48
Hinton
Hinton previously approved these changes Oct 26, 2023
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.

Great improvement.

@rr-bw rr-bw requested a review from jlf0dev October 26, 2023 21:18
jlf0dev
jlf0dev previously approved these changes Nov 1, 2023
Hinton
Hinton previously approved these changes Nov 2, 2023
Co-authored-by: Oscar Hinton <Hinton@users.noreply.github.com>
@rr-bw rr-bw dismissed stale reviews from Hinton and jlf0dev via 1755488 November 3, 2023 19:37
@rr-bw rr-bw requested review from jlf0dev and Hinton November 3, 2023 19:42
@rr-bw rr-bw removed the needs-qa Marks a PR as requiring QA approval label Nov 15, 2023
@rr-bw rr-bw merged commit 90bad00 into master Nov 15, 2023
1 check passed
@rr-bw rr-bw deleted the auth/pm-3000/desktop-account-switcher-urls branch November 15, 2023 19:02
BlackDex pushed a commit to BlackDex/bitwarden-clients that referenced this pull request Nov 21, 2023
* add server url to account switcher tab

* add serverUrl to SwitcherAccount(s)

* refactor serverUrl getter

* cleanup urls

* adjust styling

* remove SwitcherAccount class

* remove authenticationStatus from AccountProfile

* rename to inactiveAccounts for clarity

* move business logic to environmentService

* use tokenService instead of stateService

* cleanup type and comments

* remove unused property

* replace magic strings

* remove unused function

* minor refactoring

* refactor to use environmentService insead of getServerConfig

* use Utils.getHost() instead of Utils.getDomain()

* create getHost() method

* remove comment

* get base url as fallback

* resolve eslint error

* Update apps/desktop/src/app/layout/account-switcher.component.html

Co-authored-by: Oscar Hinton <Hinton@users.noreply.github.com>

---------

Co-authored-by: Oscar Hinton <Hinton@users.noreply.github.com>
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.

4 participants