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

Removing hanging promises, and adding a guard to projects routing #8891

Merged
merged 19 commits into from
Jun 4, 2024

Conversation

cd-bitwarden
Copy link
Contributor

@cd-bitwarden cd-bitwarden commented Apr 24, 2024

Type of change

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

Objective

Make sure secrets manager doesn't have hanging promises, also remove unused code that's handled by guards instead.

Code changes

  • file.ext: Description of what was changed and why
    overview.component.ts
  • in order to remove hanging promises we had to make copySecretValue and hideOnboarding async

project-dialog.component.ts - awaited the promise

bitwarden_license/bit-web/src/app/secrets-manager/projects/guards/project-access.guard.ts - created a guard to check if the project exists, if not it will redirect to projects list. Because of this code we don't need the catchError code in project.component.ts

bitwarden_license/bit-web/src/app/secrets-manager/projects/project/project-people.component.ts - awaited the promise

bitwarden_license/bit-web/src/app/secrets-manager/projects/project/project-secrets.component.ts - made copySecretValue async and we now pass logService to SecretsListComponent.copySecretValue()

bitwarden_license/bit-web/src/app/secrets-manager/projects/project/project.component.ts - removed the catchError, its' not needed anymore because of the guard

bitwarden_license/bit-web/src/app/secrets-manager/projects/projects-routing.module.ts - using the new guard

bitwarden_license/bit-web/src/app/secrets-manager/secrets/dialog/secret-dialog.component.ts - awaiting the promise, making openDeleteSecretDialog an async function.

bitwarden_license/bit-web/src/app/secrets-manager/secrets/secrets.component.ts - making copy secret value function async and passing the logService into it now.

bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/dialog/service-account-dialog.component.ts - awaiting the promise

bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/people/service-account-people.component.ts - awaiting both promises

bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/service-account.component.ts - removing the catchError because the guard handles this

bitwarden_license/bit-web/src/app/secrets-manager/shared/secrets-list.component.ts - making copySecretValue async and awaiting the promise

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

@cd-bitwarden cd-bitwarden requested a review from a team as a code owner April 24, 2024 00:09
Copy link

codecov bot commented Apr 24, 2024

Codecov Report

Attention: Patch coverage is 47.72727% with 23 lines in your changes missing coverage. Please review.

Project coverage is 28.23%. Comparing base (490e6c3) to head (4c3112c).
Report is 1 commits behind head on main.

Current head 4c3112c differs from pull request most recent head b08a196

Please upload reports for the commit b08a196 to get more accurate results.

Files Patch % Lines
...app/secrets-manager/overview/overview.component.ts 0.00% 4 Missing ⚠️
...nager/projects/project/project-people.component.ts 0.00% 4 Missing ⚠️
...p/secrets-manager/shared/secrets-list.component.ts 0.00% 4 Missing ⚠️
...ager/projects/project/project-secrets.component.ts 0.00% 3 Missing ⚠️
...c/app/secrets-manager/secrets/secrets.component.ts 0.00% 3 Missing ⚠️
...anager/projects/dialog/project-dialog.component.ts 0.00% 1 Missing ⚠️
...ecrets-manager/projects/projects-routing.module.ts 0.00% 1 Missing ⚠️
...-manager/secrets/dialog/secret-dialog.component.ts 0.00% 1 Missing ⚠️
...ccounts/dialog/service-account-dialog.component.ts 0.00% 1 Missing ⚠️
...ager/service-accounts/service-account.component.ts 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8891      +/-   ##
==========================================
+ Coverage   28.01%   28.23%   +0.22%     
==========================================
  Files        2424     2437      +13     
  Lines       71535    70521    -1014     
  Branches    13361    13141     -220     
==========================================
- Hits        20039    19911     -128     
+ Misses      49924    49070     -854     
+ Partials     1572     1540      -32     

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

Copy link
Contributor

github-actions bot commented Apr 24, 2024

Logo
Checkmarx One – Scan Summary & Details9130f664-35d0-4617-a17c-11bebade453d

No New Or Fixed Issues Found

Copy link
Member

@coltonhurst coltonhurst 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, thanks for the updates @cd-bitwarden! The only other thing we might want to consider adding is tests for the new route guard? Just an idea, I think we could potentially base it on this example from @differsthecat in this PR? I haven't looked too deeply into this though.

@cd-bitwarden
Copy link
Contributor Author

Looks good, thanks for the updates @cd-bitwarden! The only other thing we might want to consider adding is tests for the new route guard? Just an idea, I think we could potentially base it on this example from @differsthecat in this PR? I haven't looked too deeply into this though.

Good eye! It wouldn't be a bad idea to do so, however, is it overkill? I'm not super versed on testing so I couldn't say - but to me, the guard is so simple and it likely will never change, is this something that needs a test? 🤔 I would love to hear others opinions on this, as I have definitely struggled with identifying what changes do require tests 😅 @differsthecat

@coltonhurst
Copy link
Member

coltonhurst commented Apr 26, 2024

Good eye! It wouldn't be a bad idea to do so, however, is it overkill? I'm not super versed on testing so I couldn't say - but to me, the guard is so simple and it likely will never change, is this something that needs a test? 🤔 I would love to hear others opinions on this, as I have definitely struggled with identifying what changes do require tests 😅 @differsthecat

I think it would be nice to be consistent, and more testing is not bad - but if the team thinks we don't need it no worries! 👍


Did one final pass and was just curious, why remove the catchError block in these two files?

  • bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/service-account.component.ts
  • bitwarden_license/bit-web/src/app/secrets-manager/projects/project/project.component.ts

I think if getByProjectId or getByServiceAccountId return a rejected promise, without a toast the user could be confused why a link to a project or service/machine account doesn't work? I could be missing something here though.

Thanks again for your work on this!

@differsthecat
Copy link
Member

Looks good, thanks for the updates @cd-bitwarden! The only other thing we might want to consider adding is tests for the new route guard? Just an idea, I think we could potentially base it on this example from @differsthecat in this PR? I haven't looked too deeply into this though.

Good eye! It wouldn't be a bad idea to do so, however, is it overkill? I'm not super versed on testing so I couldn't say - but to me, the guard is so simple and it likely will never change, is this something that needs a test? 🤔 I would love to hear others opinions on this, as I have definitely struggled with identifying what changes do require tests 😅 @differsthecat

It may be a bit overkill, but it'd be a good exercise to do and have examples of!
Plus it will make that code coverage report just a little bit better 😉

@cd-bitwarden
Copy link
Contributor Author

Looks good, thanks for the updates @cd-bitwarden! The only other thing we might want to consider adding is tests for the new route guard? Just an idea, I think we could potentially base it on this example from @differsthecat in this PR? I haven't looked too deeply into this though.

Good eye! It wouldn't be a bad idea to do so, however, is it overkill? I'm not super versed on testing so I couldn't say - but to me, the guard is so simple and it likely will never change, is this something that needs a test? 🤔 I would love to hear others opinions on this, as I have definitely struggled with identifying what changes do require tests 😅 @differsthecat

It may be a bit overkill, but it'd be a good exercise to do and have examples of! Plus it will make that code coverage report just a little bit better 😉

Sounds good to me 😄 thanks everyone for explaining!

@cd-bitwarden
Copy link
Contributor Author

Good eye! It wouldn't be a bad idea to do so, however, is it overkill? I'm not super versed on testing so I couldn't say - but to me, the guard is so simple and it likely will never change, is this something that needs a test? 🤔 I would love to hear others opinions on this, as I have definitely struggled with identifying what changes do require tests 😅 @differsthecat

I think it would be nice to be consistent, and more testing is not bad - but if the team thinks we don't need it no worries! 👍

Did one final pass and was just curious, why remove the catchError block in these two files?

  • bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/service-account.component.ts
  • bitwarden_license/bit-web/src/app/secrets-manager/projects/project/project.component.ts

I think if getByProjectId or getByServiceAccountId return a rejected promise, without a toast the user could be confused why a link to a project or service/machine account doesn't work? I could be missing something here though.

Thanks again for your work on this!

@coltonhurst great point! I will try adding the error toast message to the route guard 😄

Copy link
Member

@coltonhurst coltonhurst left a comment

Choose a reason for hiding this comment

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

Thanks so much for the changes and the added tests! Just three small items.

@cd-bitwarden cd-bitwarden enabled auto-merge (squash) June 4, 2024 14:59
@cd-bitwarden cd-bitwarden merged commit 6fa12fe into main Jun 4, 2024
13 checks passed
@cd-bitwarden cd-bitwarden deleted the SM-1094-Promises branch June 4, 2024 14:59
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.

None yet

3 participants