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

Replace account service with Input #13045

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

albertboyd5
Copy link
Contributor

🎟️ Tracking

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

📔 Objective

📸 Screenshots

This PR replaces the direct usage of AccountService with an @input() account in all components within @bitwarden/generator-components. The goal is to decouple components from AccountService and make them more reusable by leveraging reactive @input() bindings for the account.

⏰ 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
Contributor

Logo
Checkmarx One – Scan Summary & Details2df159f9-27f7-43cb-9b09-f0d5c07e46a7

New Issues (10)

Checkmarx found the following issues in this Pull Request

Severity Issue Source File / Package Checkmarx Insight
MEDIUM Client_Privacy_Violation /apps/browser/src/vault/popup/components/vault-v2/attachments/open-attachments/open-attachments.component.ts: 50
detailsMethod OpenAttachmentsComponent at line 50 of /apps/browser/src/vault/popup/components/vault-v2/attachments/open-attachments/open-attachments.compo...
Attack Vector
MEDIUM Client_Privacy_Violation /libs/angular/src/vault/components/add-edit.component.ts: 780
detailsMethod loadAddEditCipherInfo at line 780 of /libs/angular/src/vault/components/add-edit.component.ts sends user information outside the application...
Attack Vector
MEDIUM Client_Privacy_Violation /apps/browser/src/vault/popup/components/vault-v2/attachments/open-attachments/open-attachments.component.ts: 50
detailsMethod at line 50 of /apps/browser/src/vault/popup/components/vault-v2/attachments/open-attachments/open-attachments.component.ts sends user infor...
Attack Vector
MEDIUM Client_Privacy_Violation /libs/angular/src/vault/components/add-edit.component.ts: 119
detailsMethod at line 119 of /libs/angular/src/vault/components/add-edit.component.ts sends user information outside the application. This may constitute...
Attack Vector
MEDIUM Client_Privacy_Violation /libs/angular/src/vault/components/add-edit.component.ts: 286
detailsMethod load at line 286 of /libs/angular/src/vault/components/add-edit.component.ts sends user information outside the application. This may consti...
Attack Vector
MEDIUM Client_Privacy_Violation /libs/angular/src/admin-console/components/collections.component.ts: 36
detailsMethod at line 36 of /libs/angular/src/admin-console/components/collections.component.ts sends user information outside the application. This may ...
Attack Vector
MEDIUM Client_Privacy_Violation /libs/angular/src/vault/components/add-edit.component.ts: 278
detailsMethod load at line 278 of /libs/angular/src/vault/components/add-edit.component.ts sends user information outside the application. This may consti...
Attack Vector
MEDIUM Client_Privacy_Violation /libs/angular/src/vault/components/add-edit.component.ts: 281
detailsMethod load at line 281 of /libs/angular/src/vault/components/add-edit.component.ts sends user information outside the application. This may consti...
Attack Vector
MEDIUM Client_Privacy_Violation /libs/angular/src/vault/components/add-edit.component.ts: 776
detailsMethod loadAddEditCipherInfo at line 776 of /libs/angular/src/vault/components/add-edit.component.ts sends user information outside the application...
Attack Vector
MEDIUM Client_Privacy_Violation /libs/angular/src/vault/components/add-edit.component.ts: 70
detailsMethod at line 70 of /libs/angular/src/vault/components/add-edit.component.ts sends user information outside the application. This may constitute ...
Attack Vector

@audreyality audreyality marked this pull request as draft January 24, 2025 15:00
Copy link
Member

@audreyality audreyality left a comment

Choose a reason for hiding this comment

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

⚠️ There's a number of failing unit tests in this code. They should be addressed along with the other changes I've requested in this review.

Copy link
Member

Choose a reason for hiding this comment

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

📝 All of the generator components should have a consistent implementation; these comments apply to all of them.

⛏️ The account property should replace the UserId property in all of the modified generator components.

❌ These components should implement OnChanges and populate an account$ member when the account input changes. That member then replaces the existing uses of singleUserId$. Without the OnChange implementation, Angular won't update the component when a new account is transmitted to the component through the @Input.

References:

Comment on lines +40 to +42
if (this.account) {
this.userId$.next(this.account.id);
}
Copy link
Member

Choose a reason for hiding this comment

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

this.account is never populated when the constructor runs. This check will always fail and thus the branch will never be taken. The code this replaces used the constructor to subscribe to the account service, so when the service emitted this.userId$ would populate. Following the ngOnChanges pattern I've described for the settings component should fix this issue.

📝 This feedback also applies to credential-generator-history.component.ts

Comment on lines +102 to +104
if (this.account) {
this.userId$.next(this.account.id);
}
Copy link
Member

Choose a reason for hiding this comment

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

🎨 Once you've implemented ngOnChanges, there won't be a need to set this.userId$ in these functions. ngOnChanges runs before ngOnInit, making the code redundant!

Comment on lines +25 to +28
/**
* The account object passed from the parent component.
*/
@Input() account: Account | null = null;
Copy link
Member

Choose a reason for hiding this comment

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

👍🏻 I love the documentation!

⛏️ You should apply this consistently across account inputs.

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.

2 participants