-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Conversation
New Issues
Fixed Issues
|
…github.com/bitwarden/clients into auth/pm-3000/desktop-account-switcher-urls
There was a problem hiding this 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
There was a problem hiding this 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.
There was a problem hiding this 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 onvault.company.com
which would now show up ascompany.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
fromAccountProfile
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.
@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
I've also updated the PR with a demo video. Let me know what you think. Thanks again! Tagging @jlf0dev and @trmartin4 for visibility |
There was a problem hiding this 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!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great improvement.
Co-authored-by: Oscar Hinton <Hinton@users.noreply.github.com>
* 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>
Type of change
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
apps/desktop/src/app/layout/account-switcher.component.ts
SwitcherAccount
class toInactiveAccount
typelibs/common/src/platform/services/environment.service.ts
getHost()
method to retrieve host for US, EU, or self-hosted environmentsapps/desktop/src/scss/header.scss
Video and Screenshot
Screen.Recording.2023-10-12.at.11.18.03.AM.mov