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

[AC-2328] Add a Bulk OrganizationUsersController.GetResetPasswordDetails endpoint #4079

Merged
merged 19 commits into from May 24, 2024

Conversation

r-tome
Copy link
Contributor

@r-tome r-tome commented May 11, 2024

Type of change

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

Objective

The current endpoint requires multiple database calls, this new endpoint gets all data using one new stored procedure.

Code changes

Clients PR

@bitwarden/team-billing-dev, you've been added as reviewers because dotnet format removed a few usings on StripeController

  • src/Api/AdminConsole/Controllers/OrganizationUsersController.cs: New endpoint to retrieve data for multiple organization user ids
  • src/Api/AdminConsole/Models/Response/Organizations/OrganizationUserResponseModel.cs: Add OrganizationUserId property to be able to identify each one on the result list
  • src/Core/AdminConsole/Models/Data/Organizations/OrganizationUsers/OrganizationUserResetPasswordDetails.cs: Add the OrganizationUserId property and a parameterless constructor for the auto mapper
  • src/Core/AdminConsole/Repositories/IOrganizationUserRepository.cs: New bulk method
  • src/Infrastructure.Dapper/AdminConsole/Repositories/OrganizationUserRepository.cs: Dapper implementation
  • src/Infrastructure.EntityFramework/AdminConsole/Repositories/OrganizationUserRepository.cs: EF implementation
  • src/Sql/dbo/Stored Procedures/OrganizationUser_ReadManyResetPasswordDetailsByOrganizationUserIds.sql: New stored procedure
  • test/Api.Test/AdminConsole/Controllers/OrganizationUsersControllerTests.cs: Unit tests
  • util/Migrator/DbScripts/2024-05-10_00_OrgUserReadManyResetPasswordDetailsByOrgUserIds.sql: Migration script

Before you submit

  • Please check for formatting errors (dotnet format --verify-no-changes) (required)
  • If making database changes - make sure you also update Entity Framework queries and/or migrations
  • 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

Copy link

codecov bot commented May 11, 2024

Codecov Report

Attention: Patch coverage is 29.72973% with 26 lines in your changes are missing coverage. Please review.

Project coverage is 39.08%. Comparing base (be41865) to head (fc9fcd2).

Files Patch % Lines
...Console/Repositories/OrganizationUserRepository.cs 0.00% 16 Missing ⚠️
...Console/Repositories/OrganizationUserRepository.cs 0.00% 9 Missing ⚠️
...ationUsers/OrganizationUserResetPasswordDetails.cs 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4079      +/-   ##
==========================================
+ Coverage   39.05%   39.08%   +0.03%     
==========================================
  Files        1202     1202              
  Lines       58081    58118      +37     
  Branches     5350     5351       +1     
==========================================
+ Hits        22684    22717      +33     
- Misses      34328    34330       +2     
- Partials     1069     1071       +2     

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

Copy link
Contributor

github-actions bot commented May 11, 2024

Logo
Checkmarx One – Scan Summary & Detailsdd906075-9d9a-4caa-94b4-9255b7fdb147

New Issues

Severity Issue Source File / Package Checkmarx Insight
MEDIUM Privacy_Violation /src/Api/AdminConsole/Controllers/OrganizationsController.cs: 428 Attack Vector
MEDIUM Privacy_Violation /src/Api/AdminConsole/Controllers/OrganizationsController.cs: 375 Attack Vector
LOW Log_Forging /src/Api/AdminConsole/Controllers/OrganizationsController.cs: 340 Attack Vector
LOW Log_Forging /src/Api/AdminConsole/Controllers/OrganizationsController.cs: 403 Attack Vector
LOW Missing_CSP_Header /src/Core/MailTemplates/Handlebars/InitiateDeleteOrganzation.html.hbs: 10 Attack Vector

Fixed Issues

Severity Issue Source File / Package
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 628
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 628
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 628
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 628
MEDIUM CSRF /src/Api/AdminConsole/Controllers/ProvidersController.cs: 82
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 607
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 607
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 607
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 607
MEDIUM CSRF /src/Api/AdminConsole/Controllers/GroupsController.cs: 132
MEDIUM CSRF /src/Api/AdminConsole/Controllers/ProvidersController.cs: 143
MEDIUM CSRF /src/Api/SecretsManager/Controllers/AccessPoliciesController.cs: 229
MEDIUM CSRF /src/Admin/AdminConsole/Controllers/ProvidersController.cs: 319
MEDIUM CSRF /src/Api/AdminConsole/Controllers/GroupsController.cs: 163
MEDIUM CSRF /src/Api/AdminConsole/Controllers/GroupsController.cs: 163
MEDIUM CSRF /src/Api/Billing/Controllers/ProviderClientsController.cs: 28
MEDIUM CSRF /src/Api/AdminConsole/Controllers/OrganizationUsersController.cs: 190
MEDIUM CSRF /src/Api/AdminConsole/Controllers/OrganizationUsersController.cs: 333
MEDIUM CSRF /src/Api/AdminConsole/Controllers/OrganizationUsersController.cs: 333
MEDIUM CSRF /src/Api/Auth/Controllers/AccountsController.cs: 665
MEDIUM CSRF /src/Api/Auth/Controllers/AccountsController.cs: 641
MEDIUM CSRF /src/Api/Auth/Controllers/AccountsController.cs: 707
MEDIUM CSRF /src/Api/Vault/Controllers/FoldersController.cs: 45
MEDIUM CSRF /src/Api/Controllers/SelfHosted/SelfHostedOrganizationLicensesController.cs: 51
MEDIUM CSRF /src/Api/Controllers/UsersController.cs: 22
MEDIUM CSRF /src/Api/Controllers/DevicesController.cs: 70
MEDIUM CSRF /src/Api/Controllers/DevicesController.cs: 57
MEDIUM CSRF /src/Api/AdminConsole/Public/Controllers/PoliciesController.cs: 69
MEDIUM CSRF /src/Api/AdminConsole/Public/Controllers/PoliciesController.cs: 49
MEDIUM CSRF /src/Api/AdminConsole/Public/Controllers/OrganizationController.cs: 42
MEDIUM CSRF /src/Api/AdminConsole/Public/Controllers/GroupsController.cs: 92
MEDIUM CSRF /src/Api/AdminConsole/Public/Controllers/GroupsController.cs: 49
MEDIUM CSRF /src/Api/AdminConsole/Controllers/ProviderUsersController.cs: 142
MEDIUM CSRF /src/Api/AdminConsole/Controllers/PoliciesController.cs: 148
MEDIUM CSRF /src/Api/AdminConsole/Controllers/PoliciesController.cs: 78
MEDIUM CSRF /src/Api/AdminConsole/Controllers/PoliciesController.cs: 61
MEDIUM CSRF /bitwarden_license/src/Sso/Controllers/AccountController.cs: 163
MEDIUM CSRF /bitwarden_license/src/Sso/Controllers/AccountController.cs: 96
MEDIUM CSRF /bitwarden_license/src/Scim/Controllers/v2/UsersController.cs: 50
MEDIUM CSRF /src/Api/AdminConsole/Public/Controllers/GroupsController.cs: 161
MEDIUM CSRF /src/Api/Auth/Controllers/EmergencyAccessController.cs: 159
MEDIUM CSRF /bitwarden_license/src/Scim/Controllers/v2/GroupsController.cs: 98
MEDIUM CSRF /bitwarden_license/src/Scim/Controllers/v2/GroupsController.cs: 88
MEDIUM CSRF /src/Api/AdminConsole/Public/Controllers/GroupsController.cs: 133
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 193
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 583
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 583
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 752
MEDIUM CSRF /src/Api/Auth/Controllers/TwoFactorController.cs: 403
MEDIUM CSRF /src/Api/Auth/Controllers/AccountsController.cs: 526
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 1073
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 1073
MEDIUM CSRF /src/Api/AdminConsole/Controllers/OrganizationsController.cs: 315
MEDIUM CSRF /src/Api/AdminConsole/Controllers/OrganizationUsersController.cs: 449
MEDIUM CSRF /src/Api/Auth/Controllers/AccountsController.cs: 428
MEDIUM CSRF /src/Api/Controllers/CollectionsController.cs: 303
MEDIUM CSRF /src/Api/Controllers/CollectionsController.cs: 411
MEDIUM CSRF /src/Api/Controllers/CollectionsController.cs: 323
MEDIUM CSRF /src/Api/Auth/Controllers/AccountsController.cs: 541
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 159
MEDIUM CSRF /src/Api/AdminConsole/Controllers/OrganizationUsersController.cs: 246
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 855
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 222
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 570
MEDIUM CSRF /src/Api/Controllers/CollectionsController.cs: 375
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 841
MEDIUM CSRF /src/Api/Auth/Controllers/AccountsController.cs: 217
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 193
MEDIUM CSRF /src/Api/AdminConsole/Controllers/GroupsController.cs: 260
MEDIUM CSRF /src/Api/Auth/Controllers/AccountsController.cs: 283
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 928
MEDIUM CSRF /src/Api/AdminConsole/Public/Controllers/MembersController.cs: 187
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 174
MEDIUM CSRF /src/Api/Auth/Controllers/AccountsController.cs: 357
MEDIUM CSRF /src/Api/AdminConsole/Controllers/OrganizationUsersController.cs: 286
MEDIUM CSRF /src/Api/Auth/Controllers/AccountsController.cs: 920
MEDIUM CSRF /src/Api/AdminConsole/Controllers/OrganizationUsersController.cs: 301
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 778
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 1130
MEDIUM CSRF /src/Admin/AdminConsole/Controllers/OrganizationsController.cs: 334
MEDIUM CSRF /src/Admin/AdminConsole/Controllers/ProvidersController.cs: 243
MEDIUM CSRF /src/Api/AdminConsole/Public/Controllers/MembersController.cs: 150
MEDIUM CSRF /src/Api/AdminConsole/Controllers/GroupsController.cs: 81
MEDIUM CSRF /src/Api/AdminConsole/Controllers/GroupsController.cs: 118
MEDIUM CSRF /src/Api/AdminConsole/Controllers/OrganizationsController.cs: 118
MEDIUM CSRF /src/Api/AdminConsole/Controllers/OrganizationsController.cs: 315
MEDIUM CSRF /src/Api/AdminConsole/Controllers/OrganizationsController.cs: 315
MEDIUM CSRF /src/Api/AdminConsole/Controllers/OrganizationUsersController.cs: 246
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 816
MEDIUM CSRF /src/Api/Controllers/CollectionsController.cs: 303
MEDIUM CSRF /src/Api/Controllers/CollectionsController.cs: 375
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 1150
MEDIUM CSRF /src/Api/AdminConsole/Controllers/OrganizationsController.cs: 315
MEDIUM CSRF /src/Api/AdminConsole/Controllers/OrganizationUsersController.cs: 286
MEDIUM CSRF /src/Api/AdminConsole/Public/Controllers/OrganizationController.cs: 42
MEDIUM CSRF /src/Api/AdminConsole/Public/Controllers/OrganizationController.cs: 42
MEDIUM CSRF /src/Api/AdminConsole/Public/Controllers/OrganizationController.cs: 42
MEDIUM CSRF /src/Api/Controllers/CollectionsController.cs: 411
MEDIUM CSRF /src/Api/AdminConsole/Controllers/ProviderUsersController.cs: 188
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 144
MEDIUM CSRF /src/Api/AdminConsole/Public/Controllers/MembersController.cs: 150
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 222
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 570
MEDIUM CSRF /src/Api/Auth/Controllers/AccountsController.cs: 308
MEDIUM CSRF /src/Api/AdminConsole/Controllers/ProviderUsersController.cs: 175
MEDIUM CSRF /src/Api/AdminConsole/Controllers/OrganizationsController.cs: 315
MEDIUM CSRF /src/Api/AdminConsole/Controllers/OrganizationUsersController.cs: 86
MEDIUM CSRF /src/Api/Controllers/SettingsController.cs: 36
MEDIUM CSRF /src/Api/AdminConsole/Controllers/OrganizationUsersController.cs: 218
MEDIUM CSRF /src/Api/AdminConsole/Controllers/OrganizationUsersController.cs: 300
MEDIUM CSRF /src/Api/AdminConsole/Controllers/OrganizationUsersController.cs: 318
MEDIUM CSRF /src/Api/AdminConsole/Controllers/ProviderOrganizationsController.cs: 48
MEDIUM CSRF /src/Api/AdminConsole/Controllers/GroupsController.cs: 277
MEDIUM CSRF /src/Api/Auth/Controllers/AccountsController.cs: 770
MEDIUM CSRF /src/Api/Auth/Controllers/AccountsController.cs: 861
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 1096
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 1096
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 1047
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 1047
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 961
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 657
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 657
MEDIUM CSRF /src/Api/Auth/Controllers/AccountsController.cs: 403
MEDIUM CSRF /src/Api/Auth/Controllers/AccountsController.cs: 568
MEDIUM CSRF /src/Identity/Controllers/AccountsController.cs: 50
MEDIUM CSRF /src/Api/AdminConsole/Public/Controllers/MembersController.cs: 59
MEDIUM CSRF /src/Api/AdminConsole/Public/Controllers/MembersController.cs: 127
MEDIUM CSRF /src/Api/Tools/Controllers/ImportCiphersController.cs: 50
MEDIUM CSRF /src/Api/Tools/Controllers/ImportCiphersController.cs: 66
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 111
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 125
MEDIUM CSRF /src/Api/Controllers/CollectionsController.cs: 156
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 992
MEDIUM CSRF /src/Identity/Controllers/AccountsController.cs: 72
MEDIUM CSRF /src/Api/Controllers/CollectionsController.cs: 187
MEDIUM CSRF /src/Api/Controllers/CollectionsController.cs: 196
MEDIUM CSRF /src/Api/Auth/Controllers/AccountsController.cs: 515
MEDIUM CSRF /src/Api/Public/Controllers/CollectionsController.cs: 64
MEDIUM CSRF /src/Admin/AdminConsole/Controllers/ProviderOrganizationsController.cs: 35
MEDIUM CSRF /src/Api/Auth/Controllers/WebAuthnController.cs: 130
MEDIUM CSRF /src/Api/Auth/Controllers/WebAuthnController.cs: 101
MEDIUM CSRF

More results are available on AST platform

@r-tome r-tome requested a review from addisonbeck May 13, 2024 14:20
@r-tome r-tome marked this pull request as ready for review May 13, 2024 14:22
@r-tome r-tome requested review from a team as code owners May 13, 2024 14:22
@@ -186,6 +186,19 @@ public async Task<OrganizationUserResetPasswordDetailsResponseModel> GetResetPas
return new OrganizationUserResetPasswordDetailsResponseModel(new OrganizationUserResetPasswordDetails(organizationUser, user, org));
}

[HttpPost("reset-password-details")]
Copy link
Contributor

Choose a reason for hiding this comment

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

Reset master password has been renamed "account recovery" across the product and documentation, but we still have a lot of lingering code calling things by the old "reset master password" name. Part of the tech debt epic to clean up account recovery (here) is going to involve renaming code to use "account recovery" verbiage.

We can avoid having to rename this endpoint and its backing logic later if we go ahead and call this by the correct name now. I'd like to suggest we dump any new instances of "reset password" and replace them with "account recovery", so this endpoint would be at /account-recovery-details and the method would be called GetAccountRecoveryDetails. This could be followed through to the new repository method too and name it GetManyAccountRecoveryDeatilsByOrganizationUserAsync. I think the rest of the names are used in other bits of code, so those should be left alone.

Comment on lines 9 to 12
public OrganizationUserResetPasswordDetails()
{

}
Copy link
Contributor

Choose a reason for hiding this comment

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

This can be a one-liner

@@ -3,7 +3,6 @@
using Bit.Billing.Services;
using Bit.Core;
using Bit.Core.AdminConsole.Entities;
using Bit.Core.AdminConsole.Enums.Provider;
Copy link
Contributor

Choose a reason for hiding this comment

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

I logged a separate PR for this lint failure stuff here

@@ -43,6 +43,7 @@ public interface IOrganizationUserRepository : IRepository<OrganizationUser, Gui
Task RestoreAsync(Guid id, OrganizationUserStatusType status);
Task<IEnumerable<OrganizationUserPolicyDetails>> GetByUserIdWithPolicyDetailsAsync(Guid userId, PolicyType policyType);
Task<int> GetOccupiedSmSeatCountByOrganizationIdAsync(Guid organizationId);
Task<IEnumerable<OrganizationUserResetPasswordDetails>> GetManyResetPasswordDetailsByOrganizationUserAsync(Guid organizationId, IEnumerable<Guid> organizationUserIds);
Copy link
Contributor

Choose a reason for hiding this comment

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

Lets add an integration test for this in test/Infrastructure.IntegrationTest/AdminConsole/Repositories/OrganizationUserRepositoryTests.cs.

@@ -0,0 +1,24 @@
CREATE PROCEDURE [dbo].[OrganizationUser_ReadManyResetPasswordDetailsByOrganizationUserIds]
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar to my comment about naming things in the controller and repository layers: this stored procedure name should use "account recovery" verbiage instead of the outdated "reset password". We can't do anything about the column right now, but that should be included in the tech debt epic.

@addisonbeck
Copy link
Contributor

Also, in regards to the question on slack about what to do with the single-response method:

We should log refactoring that method as follow up work on the Jira epic. My preference would be to leave the endpoint and have it reference the same repository logic, leaving clients alone completely, but removing the endpoint doesn't seem like a bad idea either. Up to you!

addisonbeck
addisonbeck previously approved these changes May 15, 2024
rkac-bw
rkac-bw previously approved these changes May 20, 2024
Copy link
Contributor

@rkac-bw rkac-bw left a comment

Choose a reason for hiding this comment

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

lgtm

@r-tome r-tome dismissed stale reviews from rkac-bw and addisonbeck via ede2155 May 21, 2024 11:32
addisonbeck
addisonbeck previously approved these changes May 21, 2024
rkac-bw
rkac-bw previously approved these changes May 22, 2024
Copy link
Contributor

@rkac-bw rkac-bw left a comment

Choose a reason for hiding this comment

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

lgtm

@r-tome r-tome dismissed stale reviews from rkac-bw and addisonbeck via 8bca89f May 23, 2024 14:04
@r-tome r-tome requested a review from addisonbeck May 23, 2024 14:04
Copy link
Contributor

LaunchDarkly flag references

🔍 1 flag added or modified

Name Key Aliases found Info
bulk-device-approval bulk-device-approval

@r-tome r-tome requested a review from rkac-bw May 23, 2024 20:53
@r-tome r-tome merged commit 5fabad3 into main May 24, 2024
52 checks passed
@r-tome r-tome deleted the ac/ac-2328/bulk-getresetpassworddetails branch May 24, 2024 10:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants