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-18770] Convert Organization to Business Unit #5610

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

amorask-bitwarden
Copy link
Contributor

@amorask-bitwarden amorask-bitwarden commented Apr 4, 2025

🎟️ Tracking

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

📔 Objective

This PR accomplishes the following:

  1. It renames all instances or naming of Multi-Organization Enterprise to Business Unit to bring the codebase in line with our domain model. This commit has no logic changes.
  2. It creates a new email that gets sent to the provider admins of pending business units that were converted from organizations. The email passes the query parameters necessary for the client-side acceptance component to process the invite.
  3. It adds the new BusinessUnitConverter, the self-contained location for all logic related to converting an organization to a business unit. The convert has 4 methods:
    • InitiateConversion: Begins the process of converting an organization into a business unit by running some validation, creating the necessary entities and sending out the invite.
    • FinalizeConversion: Finalizes the process of converting an organization to a business unit by updating the organization's subscription as well as assigning the correct client-side keys to the provider's linking records.
    • ResendConversionInvite: Resends the invite outlined in number 2.
    • ResetConversion: Deletes all of the entities created as part of InitiateConversion. This is useful in the case the Bitwarden Administrator accidentally entered the wrong Provider Admin email or otherwise wants to abandon the conversion.
  4. It adds the new BusinessUnitConversionController to the Admin application along with the necessary views and models. This results in a page where a Bitwarden Owner, Admin or Billing person can initialize a business unit conversion.
  5. It conditionally adds a "Convert to Business Unit" button on the Organization Edit page if the organization is eligible to be converted to a business unit.
  6. It adds a new SetupBusinessUnitAsync endpoint to the OrganizationBillingController. This endpoint is invoked by the client after the acceptance component has processed the incoming invite. This endpoint calls the converter's FinalizeConversion operation.
  7. It propagates the ProviderType to the sync's ProfileResponse. This is necessary as to determine the type of a provider after retrieving it from the client's state. This provider type is used to pivot some UI elements from saying "Provider Portal" to "Business Unit Portal".
  8. It wraps the ability to convert an organization to a business unit behind a feature flag.

bup-conversion drawio

clients PR: bitwarden/clients#14131

📸 Screenshots

Screen.Recording.2025-04-04.at.1.56.56.PM.mov

⏰ 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

codecov bot commented Apr 4, 2025

Codecov Report

Attention: Patch coverage is 54.80226% with 240 lines in your changes missing coverage. Please review.

Project coverage is 48.79%. Comparing base (01daad5) to head (14acf3c).

Files with missing lines Patch % Lines
...ng/Controllers/BusinessUnitConversionController.cs 0.00% 96 Missing ⚠️
...c/Commercial.Core/Billing/BusinessUnitConverter.cs 87.85% 24 Missing and 15 partials ⚠️
.../Billing/Views/BusinessUnitConversion/Index.cshtml 0.00% 24 Missing ⚠️
...lling/Controllers/OrganizationBillingController.cs 8.69% 21 Missing ⚠️
.../Services/Implementations/HandlebarsMailService.cs 0.00% 14 Missing ⚠️
...Admin/AdminConsole/Views/Organizations/Edit.cshtml 0.00% 9 Missing ⚠️
...dmin/Billing/Models/BusinessUnitConversionModel.cs 0.00% 5 Missing ⚠️
...ng/Models/Requests/SetupBusinessUnitRequestBody.cs 0.00% 4 Missing ⚠️
.../Mail/Billing/BusinessUnitConversionInviteModel.cs 0.00% 4 Missing ⚠️
...nConsole/Models/CreateBusinessUnitProviderModel.cs 25.00% 3 Missing ⚠️
... and 13 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5610      +/-   ##
==========================================
+ Coverage   45.66%   48.79%   +3.12%     
==========================================
  Files        1597     1603       +6     
  Lines       72490    73001     +511     
  Branches     6495     6544      +49     
==========================================
+ Hits        33101    35619    +2518     
+ Misses      37974    35901    -2073     
- Partials     1415     1481      +66     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

github-actions bot commented Apr 4, 2025

Logo
Checkmarx One – Scan Summary & Details61102c77-8a2a-497a-9302-d05f30a56aae

New Issues (1)

Checkmarx found the following issues in this Pull Request

Severity Issue Source File / Package Checkmarx Insight
MEDIUM CSRF /src/Admin/Billing/Controllers/BusinessUnitConversionController.cs: 70
detailsMethod InitiateAsync at line 70 of /src/Admin/Billing/Controllers/BusinessUnitConversionController.cs gets a parameter from a user request from Ini...
Attack Vector

@@ -133,10 +133,10 @@ public IActionResult CreateReseller()
return View(new CreateResellerProviderModel());
}

[HttpGet("providers/create/multi-organization-enterprise")]
public IActionResult CreateMultiOrganizationEnterprise(int enterpriseMinimumSeats, string ownerEmail = null)
[HttpGet("providers/create/business-unit")]
Copy link
Contributor

Choose a reason for hiding this comment

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

We’re changing the endpoint route here. How are we accounting for backward compatibility with existing clients during the transition?

Do we have some kind of URL rewrite in place to map the old route to the new one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @JimmyVo16, thanks for the review.

Since these changes are for the Admin Portal specifically, there's no existing clients that are communicating with it; it's all the same server-side application. As such, for any release of this application prior to this, that controller action will serve up /providers/create/multi-organization-enterprise and after this is released, it will serve up /providers/create/business-unit, but the functionality will remain exactly the same.

@@ -198,18 +198,18 @@ public async Task<IActionResult> CreateReseller(CreateResellerProviderModel mode
return RedirectToAction("Edit", new { id = provider.Id });
}

[HttpPost("providers/create/multi-organization-enterprise")]
[HttpPost("providers/create/business-unit")]
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as this question.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See above.

Copy link
Contributor

@JimmyVo16 JimmyVo16 left a comment

Choose a reason for hiding this comment

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

Just one question from the AC side.

Copy link

sonarqubecloud bot commented Apr 7, 2025

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