161 Commits

Author SHA1 Message Date
Stephon Brown
6ab70c1d99 [PM-34570] Expired or Cancelled Claimed User Throws Billing Exception on Subscription Cancel (#7382)
* fix(billing): broaden exception handling for subscription cancellations

* test(billing): add BillingException handling tests for user account deletion

* test(billing): add BillingException handling tests for organization deletion

* refactor(test): remove unused ILogger using statement

* refactor(billing): add specific usings for billing exceptions

* fix(billing): specify exceptions for billing cancellation failures
2026-04-02 14:21:51 -04:00
John Harrington
7e02832672 [PM-31885] Consolidate all Send policies to a single policy (#7113)
* initial send controls

* update vNext methods and add test coverage for policy validators

* add comments to tests

* Apply suggestion from @mkincaid-bw

• `IX_Policy_OrganizationId_Type` is a unique index

Co-authored-by: mkincaid-bw <mkincaid@bitwarden.com>

* renamne migrations for correct sorting

* respond to csharp related review comments

* fix failing lints

* fix tests

* revise policy sync logic

* revise policy event logic and tests

* add integration tests

- fix SQL syntax error
- escape Sqlite format specifier
- update migration IDs to match sorted filename
- fix SQL syntax error

* OR legacy policy data with SendControls policy data

* remove migrations and associated integration test

* whitespacing and comment correction

* aggregate kegacy Send policies in PolicyQuery and adjust PoliciesController logic

* add comments to simplify post-migration cleanup

* consolidate legacy Send policy synthesis from PoliciesController into PolicyQuery.GetAllAsync

* respond to review comments and other minor fixes

---------

Co-authored-by: mkincaid-bw <mkincaid@bitwarden.com>
2026-04-01 08:03:46 -07:00
Nick Krantz
557eeaaa8f [PM-33405] Add OrganizationUserNotificationPolicy (#7250)
* add OrganizationUserNotification policy

* remove "policy" from policy name

* update policy text
2026-03-31 15:31:56 -05:00
sven-bitwarden
4cb60ac37d [PM-332124] Finalize PolicyRequirement + 2FA Feature Flag (#7209)
* Remove 2FA feature flag

* Remove unused using
2026-03-31 16:22:12 +00:00
Stephon Brown
f1a43078f3 [PM-33891] Migrate Cancel and Reinstate Paths (#7331)
* refactor(billing): make OffboardingSurveyResponse optional in CancelSubscription

* refactor(billing): migrate UserService.CancelPremiumAsync behind PM32645 feature flag

* refactor(billing): migrate OrganizationDeleteCommand cancel behind PM32645 feature flag

* refactor(billing): migrate AccountsController reinstate-premium behind PM32645 feature flag

* refactor(billing): migrate OrganizationsController reinstate behind PM32645 feature flag

* feat(billing): Introduce CancelSubscription overload for system cancellations

* refactor(billing): Conditionally apply Stripe cancellation metadata

* chore(tests): Remove unused using directive in OrganizationDeleteCommandTests

* refactor(billing): simplify OneOf result handling

* chore(deps): remove unused OneOf.Types imports

* chore(deps): remove unused Bit.Core.Billing.Commands imports

* chore(deps): remove unused Bit.Core imports

* refactor(billing): unify ISubscriberService.CancelSubscription overloads

* refactor(billing): update SubscriberService.CancelSubscription implementation

* fix(api): adjust CancelSubscription calls in billing controllers

* fix(user): adjust UserService.CancelSubscription call

* test(billing): adjust SubscriberServiceTests for new CancelSubscription signature

* test(user): adjust UserServiceTests for new CancelSubscription signature

* refactor(billing): feature flag subscription cancel

* refactor: decouple premium cancellation logic from user service

* test: add tests for organization cancellation with feature flag

* test: add tests for handling gateway exceptions during cancellation

* fix(billing): run dotnet format
2026-03-31 14:29:27 +00:00
Kyle Spearrin
30f9229b22 [PM-15489] 2fa account recovery (#7139)
* implementation plan

* feedback updates

* revert updates

* implementation plan

* feedback updates

* revert updates

* implement plan

* Revert "Merge branch '2fa-account-recovery' of github.com:bitwarden/server into 2fa-account-recovery"

This reverts commit 3be2d140f1, reversing
changes made to 9fb8d3891c.

* PR feedback

* revert claude  local settings

* lint fixes

* fix test models

* move new commands to v2 namespace.

* format

* fix swagger stuff

* update feature flag name
2026-03-30 10:48:43 -04:00
Rui Tomé
e09e63569c [PM-33086] Remove the feature flag RefactorOrgAcceptInit (#7287) 2026-03-26 12:36:07 +00:00
Alex Morask
212a0609c0 [PM-33415] [PM-33418] Fix add-on item proration and Families > Teams/Enterprise upgrade seat count (#7259)
* fix(billing): replace per-change IsStructural with changeset-level ChargeImmediately flag

* fix(billing): set seat quantity when upgrading from non-seat-based to seat-based plan
2026-03-20 09:29:45 -05:00
sven-bitwarden
081bbe66d0 [PM-30993] Better Error Message for Expired Invitation Tokens (#6971)
* Send better error message when token is expired

* Add comment indicating frontend usage

* Add testcase for Invalid Token scenario

* Update comment in test-case

* Fix merge issue

* Fix method name

* Consolidate token validation error calculation, apply to new area

* Move away from magic strings, fix tests

* Adjust class name

* Clean up old method name references

* Change errors to fields for singleton behavior

* Formatting
2026-03-20 08:35:39 -05:00
Thomas Rittson
f9f123b757 Revert MasterPasswordPolicyRequirement implementation (#7232)
This was being used to combine policies before sending them
to the client. Instead, the server just send the policies and
the client should process/combine them. Revert this to save
unnecessary QA (etc) and we will refactor this away in the
future.
2026-03-18 09:50:32 +10:00
Thomas Rittson
99454f5fe7 [PM-33216] Finalize RequireSsoPolicyRequirement (#7173)
* Add more efficient sproc to retrieve PolicyDetails
  for a single user. This closely matches the existing sproc
  used by PolicyService and should be performant enough
  to be used in the login flow

* Maintain feature flag for this critical path
2026-03-17 08:30:51 +10:00
Jimmy Vo
0ad7a10c56 [PM-32665] Fix Cross-Organization IDOR in Bulk User Revoke (#7206) 2026-03-13 09:32:16 -04:00
Patrick-Pimentel-Bitwarden
e0a08710a8 feat(emergency-access): [PM-29585] Prevent New EA Invitations or Acceptance (#6940)
* feat(emergency-access): [PM-29585] Prevent New EA Invitations or Acceptance - Initial implementation

* fix(emergency-access): [PM-29585] Prevent New EA Invitations or Acceptance - Changes in a good place. Need to write tests.

* test(emergency-access): [PM-29585] Prevent New EA Invitations or Acceptance - Service tests have been added.

* fix(emergency-access): [PM-29585] Prevent New EA Invitations or Acceptance - Fixed comment.
2026-03-12 16:48:19 +00:00
Jared
09f0a7bca3 Refactor email confirmation logic to remove legacy mail service usage and streamline organization confirmation process (#7192) 2026-03-11 11:34:36 -04:00
Brandon Treston
49ec89d821 remove flagged logic (#7179) 2026-03-09 16:43:50 -04:00
Alex Morask
ed861d89f8 [PM-32581] Refactor organization subscription update process (#7132)
* chore: add CLAUDE.local.md and .worktrees to gitignore

* feat(billing): add Stripe interval and payment behavior constants and feature flag

* feat(billing): add OrganizationSubscriptionChangeSet model and unit tests

* refactor(billing): rename UpdateOrganizationSubscriptionCommand to BulkUpdateOrganizationSubscriptionsCommand

* feat(billing): add UpdateOrganizationSubscriptionCommand with tests

* feat(billing): use UpdateOrganizationSubscriptionCommand in BulkUpdateOrganizationSubscriptions behind feature flag

* feat(billing): use UpdateOrganizationSubscriptionCommand in SetUpSponsorshipCommand behind feature flag

* feat(billing): add UpgradeOrganizationPlanVNextCommand with tests and feature flag gate

* feat(billing): use UpdateOrganizationSubscriptionCommand in OrganizationService.AdjustSeatsAsync behind feature flag

* feat(billing): use UpdateOrganizationSubscriptionCommand in UpdateSecretsManagerSubscriptionCommand behind feature flag

* feat(billing): use UpdateOrganizationSubscriptionCommand in BillingHelpers.AdjustStorageAsync behind feature flag

* chore: run dotnet format

* fix(billing): missed optional owner in OrganizationBillingService.Finalize after merge

* refactor(billing): address PR feedback on UpdateOrganizationSubscription
2026-03-09 15:37:51 -05:00
Jared McCannon
f820b7ec87 [PM-18236] - Use Single Org Requirement (#6999)
* Added new methods and ff for single org req

* Changed req messages and added new method for creating orgs

* Updated Requirement and Tests.

* Updated commands and requirement to take a list of org users

* Updated xml docs and renamed to be consistent

* Changes from Code Review

* Removed feature flag check for policy requirements around single org. Aligned error message with what other commands were returning.

* Fixed test names. Updated error messages to be specific for each caller.

* Updated tests to clean up details consturction

* Added test for confirmed accepted user in another org.

* fixed tests to use new factory

* Update test/Core.Test/AdminConsole/OrganizationFeatures/OrganizationUsers/RestoreUser/RestoreOrganizationUserCommandTests.cs

Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>

* Fixed tests by adding no op for req.

---------

Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
2026-03-09 10:55:55 -05:00
sven-bitwarden
43d3c414cc [PM-28519] Remove Emergency Access Contacts for AutoConfirm Org Flows (#7123)
* Remove emergency access from all organization users on policy enable, or when accepted/restored

* Use correct policy save system

* Add additional tests

* Implement both PreUpsert and OnSave side effects
2026-03-05 09:56:02 -06:00
Thomas Rittson
1586c1ce14 [PM-33068] Fix Organization not found error when editing policy after signup (#7126)
The IApplicationCacheService implementation is defective and
does not synchronise between instances. Switch to using
the repository directly to ensure that the organization is always
available. This will be reverted when the cache is fixed.

---------

Co-authored-by: Jared McCannon <jmccannon@bitwarden.com>
2026-03-03 16:42:59 -05:00
Rui Tomé
c97ccc1610 [PM-28795] Refactor organization accept-init flow with atomic database operations and upfront validation (#6831)
* Add integration tests for AcceptInit endpoint in OrganizationUsersController

* Add new feature flag for organization acceptance initialization refactor

* Add InitPendingOrganizationVNextAsync for consolidated organization initialization

Introduces a new method that consolidates organization initialization,
user confirmation, email verification, and collection creation into a
single operation with upfront validation.

Key improvements:
- All validation performed before any state changes
- Returns typed errors via CommandResult instead of throwing exceptions
- Reduces three separate command calls into one unified flow
- Maintains backward compatibility via feature flag

The existing InitPendingOrganizationAsync is marked obsolete and will be
removed after feature flag rollout completes.

* Add unit tests for InitPendingOrganizationVNextAsync method

Introduces comprehensive unit tests for the InitPendingOrganizationVNextAsync method, covering various scenarios including valid data initialization, error handling for invalid tokens, organization status checks, and user confirmation requirements.

Key additions:
- Tests for successful organization initialization and user confirmation.
- Error handling tests for invalid tokens, already enabled organizations, and mismatched organization IDs.
- Validation for existing keys and email mismatches.
- Support for creating default collections during initialization.

These tests enhance the reliability and robustness of the organization initialization process.

* Refactor AcceptInit method to support feature flag for organization initialization

Updated the AcceptInit method in OrganizationUsersController to return an IResult type and handle organization initialization based on a feature flag. If the feature is enabled, it utilizes the new InitPendingOrganizationVNextAsync method for atomic organization setup and user confirmation. Integration tests were added to verify the behavior under both feature flag states, ensuring proper initialization and error handling.

* Enhance InitPendingOrganizationCommand with policy validation and feature flag support

Updated the ValidatePoliciesAsync method to enforce the Automatic User Confirmation Policy when the feature flag is enabled. Added new unit tests to cover scenarios for automatic user confirmation and single organization policy violations, ensuring comprehensive validation during organization initialization. This improves error handling and maintains compliance with organizational policies.

* Add InitializePendingOrganizationAsync method for atomic organization initialization

Implemented the InitializePendingOrganizationAsync method in both Dapper and Entity Framework repositories to streamline the initialization of pending organizations. This method enables the organization, confirms the first owner, updates user details, and optionally creates a default collection, all within a single atomic transaction. Enhanced error handling ensures robustness during the initialization process.

* Add unit tests for InitializePendingOrganizationAsync method

Introduced several unit tests for the InitializePendingOrganizationAsync method, covering scenarios such as successful organization initialization with and without collections, exception handling for invalid organization IDs, and rollback behavior on errors. These tests enhance the reliability of the organization initialization process and ensure proper handling of various edge cases.

* Refactor InitPendingOrganizationCommand to use consolidated InitializePendingOrganizationAsync method

Replaced multiple asynchronous calls for organization initialization with a single call to the new InitializePendingOrganizationAsync method. This change streamlines the process by encapsulating organization setup, user confirmation, and collection creation into one atomic operation, enhancing maintainability and reducing complexity in the command logic.

* Enhance InitPendingOrganizationCommandTests with new test cases and refactor existing ones

Added a new test case for InitPendingOrganizationVNextAsync to validate organization initialization with a collection name. Refactored existing tests to improve clarity and maintainability, including the removal of redundant assertions and the consolidation of organization setup logic. This update strengthens the test coverage for the organization initialization process and ensures proper handling of various scenarios.

* Refactor IOrganizationRepository and OrganizationRepository to remove nullable collectionName parameter

Updated the IOrganizationRepository and OrganizationRepository interfaces to change the collectionName parameter from nullable to non-nullable. This change enforces stricter parameter requirements and improves data integrity during organization initialization processes.

* Improve error handling in OrganizationRepository by logging exceptions during transaction rollback

Updated the OrganizationRepository in both Dapper and Entity Framework implementations to log detailed error messages when exceptions occur during the initialization of pending organizations. This enhancement improves traceability and debugging capabilities by providing context on failures, ensuring better maintainability of the organization initialization process.

* Refactor OrganizationRepository to consolidate SaveChangesAsync calls

Updated the OrganizationRepository to reduce multiple SaveChangesAsync calls into a single call at the end of the transaction. This change enhances performance and ensures that all changes are committed atomically, improving the overall maintainability of the organization initialization process.

* refactor: Introduce InitPendingOrganizationRequest model and update InitPendingOrganizationVNextAsync method

- Created InitPendingOrganizationRequest to encapsulate parameters for initializing a pending organization.
- Refactored InitPendingOrganizationVNextAsync method to accept the new request model instead of multiple parameters.
- Updated OrganizationUsersController to use the new request model for improved readability and maintainability.
- Adjusted related tests to accommodate the new request structure.

* Create database update action delegate for organization initialization.

* Add BuildVerifyUserEmailAction method to IUserRepository and implementations in UserRepository classes

- Introduced a new method in IUserRepository to create an action for verifying user emails.
- Implemented the method in both Dapper and Entity Framework UserRepository classes to update the email verification status of users.
- Ensured that the method checks if the user's email is already verified before updating.

* Add BuildCreateDefaultCollectionAction method to ICollectionRepository and implementations in CollectionRepository classes

- Introduced a new method in ICollectionRepository to build an action for creating a default collection with user access.
- Implemented the method in both Dapper and Entity Framework CollectionRepository classes to handle collection creation and user access assignments.
- Enhanced the functionality to support transaction execution for database operations.

* Add BuildConfirmOrganizationUserAction method to IOrganizationUserRepository and implementations in OrganizationUserRepository classes

- Introduced a new method in IOrganizationUserRepository to build an action for confirming an organization user.
- Implemented the method in both Dapper and Entity Framework OrganizationUserRepository classes to handle user confirmation and status updates.
- Enhanced the functionality to support transaction execution for database operations.

* Refactor organization initialization methods in IOrganizationRepository and implementations

- Introduced BuildUpdateOrganizationAction method to create an action for updating organization properties during initialization.
- Replaced the InitializePendingOrganizationAsync method with ExecuteOrganizationInitializationUpdatesAsync to handle multiple update actions in a single transaction.
- Updated Dapper and Entity Framework implementations to support the new action-based approach for organization initialization, enhancing transaction management and code clarity.

* Add integration tests for ExecuteOrganizationInitializationUpdatesAsync

* Refactor InitPendingOrganizationCommand to streamline organization initialization process

- Introduced methods for preparing organization and organization user for initialization.
- Replaced direct calls to repository methods with a new action-based approach for executing multiple database updates in a single transaction.
- Enhanced test cases to validate the new initialization logic and ensure proper handling of organization states.

* Refactor organization user acceptance tests to utilize feature flags

- Converted existing tests to use [Theory] with [InlineData] for feature flag variations.
- Updated assertions to reflect expected status codes based on feature flag state.
- Enhanced user confirmation checks to ensure proper linking and email verification after acceptance.
- Improved test coverage for organization initialization scenarios with and without collections.

* Refactor BuildVerifyUserEmailAction to accept User entity instead of user ID

- Updated IUserRepository and its implementations to change the parameter of BuildVerifyUserEmailAction from Guid userId to User user.
- Modified related repository methods in Dapper and Entity Framework to utilize the User entity for email verification.
- Adjusted tests to reflect the new method signature, ensuring proper functionality and integration with the updated user verification process.

* Revert "Refactor BuildVerifyUserEmailAction to accept User entity instead of user ID"

This reverts commit 71047bee2a.

* Enhance InitPendingOrganizationCommand for null safety and error handling

- Removed nullable disable directive to enable null safety checks.
- Added a null check for the organization retrieval, throwing a BadRequestException if not found.
- Updated validation methods to return nullable Error types, improving error handling in the organization initialization process.

* Add remarks to IInitPendingOrganizationCommand for clarity on organization initialization

- Enhanced the documentation for the InitPendingOrganizationCommand interface by adding remarks to clarify the role of the user initializing the organization.
- Explained the default state assumptions during validation, emphasizing that no policies are enforced at this stage.

* Implement InitPendingOrganizationValidator for improved organization initialization validation

- Introduced IInitPendingOrganizationValidator interface and its implementation to encapsulate validation logic for organization initialization.
- Refactored InitPendingOrganizationCommand to utilize the new validator for token validation, user email matching, organization state checks, and policy enforcement.
- Enhanced dependency injection in OrganizationServiceCollectionExtensions to include the new validator.
- Added comprehensive unit tests for the validator to ensure robust validation logic and error handling.

* Update documentation in IInitPendingOrganizationCommand to clarify organization initialization process

- Revised the summary comment to specify that the method initializes a pending organization created via the Bitwarden Portal on behalf of a Reseller.
- Added a reference to the ResellerClientOrganizationSignUpCommand for better context.
- Emphasized the confirmation of the first owner during the initialization process.

* Update InitPendingOrganizationRequest to allow optional collection name

- Modified the CollectionName property to be nullable, allowing for no collection to be created if the value is null or empty.
- Enhanced documentation to clarify the optional nature of the CollectionName parameter.

* Fix nullability issue in InitPendingOrganizationCommand by enforcing non-null collection name assignment

* Refactor organization key handling in InitPendingOrganization features. Updated OrganizationUsersController to use new key pair data structure. Adjusted InitPendingOrganizationCommand and InitPendingOrganizationRequest to reflect changes in key management.

* Update organization key handling to use the name EncryptedOrganizationSymmetricKey. Refactor OrganizationUsersController, InitPendingOrganizationCommand, and InitPendingOrganizationRequest for consistency in key management.

* Refactor InitPendingOrganizationCommand to utilize TimeProvider for date handling. Updated methods to replace direct DateTime calls with _timeProvider.GetUtcNow().

* Refactor InitPendingOrganization validation methods to rename ValidateBusinessRulesAsync to ValidateFreeOrganizationLimitAsync for clarity and consistency. Updated related command and test files accordingly.

* Refactor InitPendingOrganizationCommand and related classes to streamline validation logic. Introduced InitPendingOrganizationValidationRequest for enriched validation context and updated methods to improve clarity and consistency in error handling. Adjusted tests to reflect changes in validation flow.

* Remove unused dependencies from InitPendingOrganizationCommand

* Refactor InitPendingOrganizationCommand to streamline organization initialization process. Replaced multiple update actions with a single atomic operation for organization and owner confirmation. Updated related repository interfaces and methods for improved clarity and consistency in transaction handling.

* Remove commented-out regions and clean up whitespace in InitPendingOrganizationCommandTests for improved readability.

* Remove unnecessary null check for organization in InitPendingOrganizationCommand

* Revert "Remove unnecessary null check for organization in InitPendingOrganizationCommand"

This reverts commit 1ad7148fc9.

* Refactor organization initialization actions to use DbConnection and DbTransaction instead of SqlConnection and SqlTransaction. Update related interfaces and implementations across repositories for improved database transaction handling.

* Refactor organization and organization user update logic to use null checks for entity existence. Throw exceptions for not found entities to improve error handling during initialization.

* Update InitPendingOrganizationCommandTests to use SendConfirmationAsync for email notifications and added missing using directive for OrganizationConfirmation.

* Remove unnecessary blank lines from CollectionRepository and UserRepository classes for improved code readability.

* Remove redundant test cases from OrganizationUsersControllerAcceptInitTests

* Enhance InitPendingOrganizationCommandTests to validate organization and user properties in repository interactions

* Update RefactorOrgAcceptInit feature flag key to new identifier pm-33082-refactor-org-accept-init
2026-03-03 17:50:31 +00:00
sven-bitwarden
5be9ccd67d [PM-24788] Remove Org-Based Policy Requirements Queries (#7038)
* Remove usage of policy requirements retrieval by org

* Simplify result model

* Return early if no restored confirmed users exist to create default collections for

* fix merge conflict flog

* Fix test mocks

---------

Co-authored-by: bnagawiecki <107435978+bnagawiecki@users.noreply.github.com>
2026-03-03 10:18:05 -06:00
Jared McCannon
07ead26009 [PM-30886] - Remove FF for Restoring Users (#7071)
* Cleaning up code around feature flag. removing old implementation. will remove flag in subsequent pr.

* Remove unused feature flag

* Fixing test from merge
2026-03-02 11:31:58 -06:00
Brandon Treston
85af9fe71d [PM-32782] Add organization userId to payload (#7104)
* add organization userId to payload

* fix tests
2026-03-02 09:34:47 -05:00
Rui Tomé
d1a5c4de46 [PM-32796] Fix bulk reinvite timeouts by moving updated org emails from IMailer to IMailService (#7105) 2026-02-27 13:42:11 -05:00
Thomas Rittson
415805679d PM-31847 Wire up UseMyItems organization ability (#7039)
Skip My Items creation if organization.UseMyItems is disabled
2026-02-27 11:28:55 +10:00
Rui Tomé
ef4f4e352f [PM-21179] Add interface to check if user is enrolled in account recovery (#6993)
* Add validation for reset password key and account recovery enrollment in OrganizationUser

* Update admin approval logic to check account recovery enrollment and add tests for reset password key validation

* Enhance UserService validation to include account recovery enrollment and add unit test for empty or whitespace reset password key handling

* Refactor OrganizationUserUserDetailsQuery to validate reset password keys and add unit tests for filtering out invalid keys

* Update AdminRecoverAccountCommand to validate account recovery enrollment and adjust tests for whitespace reset password keys

* Enhance OrganizationUserRotationValidator to validate reset password keys, including filtering out whitespace-only keys, and add corresponding unit tests for validation logic.

* Refactor OrganizationUserUserDetailsQueryTests to remove unnecessary whitespace-only test cases for account recovery key validation.

* Refactor MemberResponseModel to use OrganizationUser's validation method for ResetPasswordEnrolled status and update corresponding unit test for clarity.

* Refactor OrganizationUsersController and response models to utilize OrganizationUser's validation method for ResetPasswordKey, ensuring consistent validation across the application. Add unit tests for OrganizationUser to verify key validation logic.

* Update OrganizationUserRotationValidator to handle null reset password keys and adjust tests for client-side bug. Add comments for future migration after resolving PM-31001.

* Fix whitespace issue in UserServiceTests.cs by removing BOM character from the file header.
2026-02-24 14:16:54 +00:00
sven-bitwarden
b412826951 [PM-4142] Clean Up Pre-Tokenable Token Validation (#6972)
* Remove old pre-tokenable code

* Clean up dead code

* Remove unused imports
2026-02-23 10:23:38 -06:00
Jared McCannon
708ea66393 [PM-27705] - Notify Admins/Owners/Managers Auto Confirm Enabled (#6938)
* Adding email for sending to owners, admins, and managers to notify that auto confirm feature has been enabled from admin portal
2026-02-20 08:26:31 -06:00
Jared McCannon
8fefae98e4 [PM-18715] - SCIM Revoke User v2 (#7024)
* Migrated SCIM revoke user call to the v2 implementation.

* Correcting feature string
2026-02-18 08:09:45 -06:00
sven-bitwarden
0874163911 [PM-24759] Add Method for Retrieving Policy Requirements for Multiple Users (#6876)
* Adds new method for retrieving policy requirements for a collection of user IDs

* Use Single instead of First for explicit correctness

* Fix xmldoc

* Refactor return type to include user ID
2026-02-17 10:33:27 -06:00
Rui Tomé
e65ed484f9 [PM-21740 / PM-27878] Update join organization email templates (#6941)
* Add new feature flag for updating the join organization email templates

* Add new MJML email template for organization invite to existing users

* Add new MJML email template for organization invite to new users

* Add new MJML email template for organization invite to existing families

* Add new MJML email template for organization invite to families for new users

* Add new MJML email template for organization invite to free users

* Add OrganizationInviteBaseView model for organization invite email templates

* Add required properties for email title customization in OrganizationInviteBaseView

* Add new MJML email templates for organization invites to existing and new users, including families and free users.

* Enhance SendInvitesRequest to include optional InvitingUserId and update related methods in OrganizationService for improved user invitation tracking.

* Refactor organization invite email handling to support customized templates for existing and new users, incorporating inviting user information and enhancing the SendInvitesRequest structure.

* Refactor OrganizationInviteBaseView and SendOrganizationInvitesCommand to remove unnecessary properties, streamlining the organization invite email structure and focusing on essential information for user invitations.

* Refactor SendOrganizationInvitesCommand to improve email invitation logic by removing the OrganizationCategory enum and consolidating plan type checks. Introduce a new method for formatting expiration dates to enhance code clarity and maintainability.

* Update organization invite email templates to enhance styling

* Enhance SendOrganizationInvitesCommand to include additional plan types for organization invites, allowing support for TeamsStarter, TeamsStarter2023, and Custom plans in the invitation logic.

* Add tests for SendOrganizationInvitesCommand to validate email sending logic for various plan types, including Enterprise, Teams, Families, Free, and Custom plans, based on user existence and feature flags.

* Update organization invite email templates to improve styling and layout consistency across various user types, including adjustments to padding, font weights, and vertical alignment for a more polished appearance.

* Refactor organization invite email templates to improve styling consistency and layout across various user types, including adjustments to padding, font families, and visibility of icon rows for a more polished appearance.

* [PM-30610] Break shared components into AC versions

* Revert changes to shared MJML components

* Refactor organization invite email templates to use admin console MJML components

* Update organization invite email templates to utilize new admin console MJML components

* Enhance organization invite email templates by adding bullet point for mobile views

* Update organization invite email templates to improve layout and visibility of bullet points by changing display properties and adding inline text spans.

---------

Co-authored-by: Jimmy Vo <huynhmaivo82@gmail.com>
2026-02-16 11:26:34 +00:00
Brandon Treston
bf9cc01459 [PM-26379] Implement auto confirm push notification (#6980)
* implement auto confirm push notification

* fix test

* fix test

* simplify LINQ
2026-02-13 11:50:12 -05:00
Rui Tomé
17166dc0f5 [PM-28300] Remove BlockClaimedDomainAccountCreation feature flag checks (#6934)
* [PM-28300] Remove BlockClaimedDomainAccountCreation feature flag checks

* Fix user registration tests by adding proper email domains

* Remove redundant feature flag checks from user registration tests

* Remove BlockClaimedDomainAccountCreation constant from FeatureFlagKeys
2026-02-11 22:10:59 +00:00
Jared McCannon
0566de90d6 [PM-27145] - Block Auto Confirm Enable Admin Portal (#6981)
* Extracted policy compliance checking for the organization out and added a check when attempting to enable auto user confirm via Admin Portal

* Moved injection order. Fixed error message.
2026-02-11 09:59:18 -06:00
Jared
7c216366a7 [PM-31153] email updates for domain claim pt 2 (#6965)
* [PM-31361] Enhance domain claimed email notifications

* Updated the email template to include the claimed domain name and user email.
* Modified the `ClaimedUserDomainClaimedEmails` model to include the domain name.
* Adjusted the `SendClaimedDomainUserEmailAsync` method to pass the domain name to the email message.
* Added a new test for rendering the domain claimed email to ensure proper content delivery.

* Update email templates for domain claimed notifications

* Adjusted styles and formatting in the DomainClaimedByOrganization email template for improved readability.
* Modified the TitleContactUs layout to ensure proper rendering of titles.
* Updated the HandlebarsMailService to include HTML line breaks in the email title for better presentation.

* Update TitleContactUs email template to center-align title text for improved presentation

* Refine TitleContactUs email template by removing unnecessary text-align property for improved consistency in styling

* Fix PR comments

* Update test/Core.Test/Platform/Mail/DomainClaimedEmailRenderTest.cs

Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>

* Update test/Core.Test/Platform/Mail/DomainClaimedEmailRenderTest.cs

Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>

* Update test/Core.Test/Platform/Mail/DomainClaimedEmailRenderTest.cs

Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>

* Remove unnecessary comments

---------

Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
2026-02-09 14:38:50 -05:00
sven-bitwarden
93a28eed40 [PM-29246] Simplify Usage of Organization Policies (#6837)
* Initial implementation of new policy query

* Remove unused using

* Adjusts method name to better match repository method

* Correct namespace

* Initial refactor of policy loading

* Add xml doc, incorporate shim data model

* Updates usages to reflect new shim model

* Prune extranneous data from policy detail response model, format code

* Fix broken test, delete inapplicable test

* Adds test cases covering query

* Adjust codebase to use new PolicyQueryçˆ

* Format code

* Fix incorrect mock on test

* Fix formatting

* Adjust method name

* More naming adjustments

* Add PolicyData constructor, update test usages

* Rename PolicyData -> PolicyStatus

* Remove unused using
2026-01-29 14:11:20 -06:00
Jared McCannon
ddbaffad59 [PM-28627] Create Default Collection Restore (#6879)
* Add default collection name to call stack for restore user command

* Committing feature flag and request model.

* Added tests

* fix for tests.

* added empty string to test

* figured out the mystery commit.

* added vnext onto method name.

* updating tests and command to include feature flag

* moved event call

* last few changes.

* opting for null instead of empty string.
2026-01-28 09:05:29 -06:00
Rui Tomé
7fb2822e05 [PM-28023] Fix restoring revoked invited users in Free Organizations (#6861)
* Fix null reference when restoring invited users in Free orgs

Add null check before querying for other free org ownership. Invited
users don't have a UserId yet, causing NullReferenceException.

* Add regression test for restoring revoked invited users with null UserId.
2026-01-21 11:27:24 +00:00
Thomas Rittson
ebb0712e33 [PM-28555] Add idempotent sproc to create My Items collections (#6801)
* Add sproc to create multiple default collections. 
  SqlBulkCopy implementation is overkill for most cases.
  This provides a lighter weight sproc implementation for smaller
  data sets.
* DRY up collection arrangement
* DRY up tests because bulk and non-bulk share same behavior
* use EF native AddRange instead of bulk insert, because
  we expect smaller data sizes on self-host
2026-01-15 22:49:25 +00:00
Brandon Treston
aa8d7c6775 [PM-30682] Add missing null check, update tests (#6826)
* add missing null check, update tests

* CR feedback
2026-01-14 12:19:23 -05:00
Jimmy Vo
b1cf59b1bf [PM-27882] Fix the subject line. (#6818) 2026-01-09 10:04:52 -05:00
Jimmy Vo
63784e1f5f [PM-27882] Add SendOrganizationConfirmationCommand (#6743) 2026-01-06 16:43:36 -05:00
Rui Tomé
1b17d99bfd [PM-29555] Add self-revoke endpoint for declining organization data ownership policy (#6739)
* Add OrganizationUser_SelfRevoked event type to EventType enum

* Add SelfRevokeOrganizationUserCommand implementation and interface for user self-revocation from organizations

* Add unit tests for SelfRevokeOrganizationUserCommand to validate user self-revocation logic, including success scenarios and various failure conditions.

* Add ISelfRevokeOrganizationUserCommand registration to OrganizationServiceCollectionExtensions for user self-revocation functionality

* Add self-revoke user functionality to OrganizationUsersController with new endpoint for user-initiated revocation

* Add integration tests for self-revoke functionality in OrganizationUsersController, covering scenarios for eligible users, non-members, and users with owner/admin roles.

* Add unit test for SelfRevokeOrganizationUserCommand to validate behavior when a user attempts to self-revoke without confirmation. This test checks for a BadRequestException with an appropriate message.

* Add MemberRequirement class for organization membership authorization

- Implemented MemberRequirement to check if a user is a member of the organization.
- Added unit tests for MemberRequirement to validate authorization logic for different user types.

* Update authorization requirement for self-revoke endpoint and add integration test for provider users

- Changed authorization attribute from MemberOrProviderRequirement to MemberRequirement in the RevokeSelfAsync method.
- Added a new integration test to verify that provider users who are not members receive a forbidden response when attempting to revoke themselves.

* Add EligibleForSelfRevoke method to OrganizationDataOwnershipPolicyRequirement

- Implemented the EligibleForSelfRevoke method to determine if a user can self-revoke their data ownership based on their membership status and policy state.
- Added unit tests to validate the eligibility logic for confirmed, invited, and non-policy users, as well as for different organization IDs.

* Refactor self-revoke user command to enhance eligibility checks

- Updated the SelfRevokeOrganizationUserCommand to utilize policy requirements for determining user eligibility for self-revocation.
- Implemented checks to prevent the last owner from revoking themselves, ensuring organizational integrity.
- Modified unit tests to reflect changes in eligibility logic and added scenarios for confirmed owners and admins.
- Removed deprecated policy checks and streamlined the command's dependencies.

* Use CommandResult pattern in self-revoke command

* Clearer documentation
2026-01-06 11:25:14 +00:00
Vincent Salucci
35868c2a65 [PM-22434] Remove CreateDefaultLocation feature flag references (#6758)
* chore: remove ff ref from PoliciesController

* chore: remove ff ref from OrganizationExportController, refs PM-22434

* chore: remove ff ref from CiphersController, refs PM-22434

* chore: remove ff ref from ConfirmOrganizationUserCommand, refs PM-22434

* chore: remove ff refs from OrganizationDataOwnershipPolicyValidator, refs PM-22434

* chore: remove ff ref from OrganizationUserControllerTests, refs PM-22434

* chore: remove ff refs from ConfirmOrganizationUserCommandTests, refs PM-22434

* chore: remove ff refs from OrganizationDataOwnershipPolicyValidatorTests, refs PM-22434

* chore: format, refs PM-22434
2026-01-05 17:27:17 -06:00
Thomas Rittson
67534e2cda [PM-29556] Fix: changing organization plan nulls out public and private keys (#6738)
Main fix: only assign new key value where old keys are not set
and new keys have been provided.

Refactors:
- use consistent DTO model for keypairs
- delete duplicate property assignment for new orgs
2025-12-26 10:13:12 +10:00
Alex Morask
39a6719361 [PM-27117] Sync Stripe Customer details for Organizations and Providers in API & Admin (#6679)
* Sync Stripe customer details for Provider / Organization in API & Admin

* Remove unnecessary var

* Fix logical operator

* Remove customer ID check from callers

* Fix failing tests

* Missed conflicts
2025-12-16 07:59:05 -06:00
Jared McCannon
e646b91a50 [PM-27131] Auto confirm policy requirement (#6649)
* Added Auto confirm policy enforcement requirement. Includes strict single org enforcement along with blocking provider users from joining orgs with auto confirm enabled.
2025-12-15 15:40:00 -06:00
Kyle Denney
99e1326039 [PM-24616] refactor stripe adapter (#6527)
* move billing services+tests to billing namespaces

* reorganized methods in file and added comment headers

* renamed StripeAdapter methods for better clarity

* clean up redundant qualifiers

* Upgrade Stripe.net to v48.4.0

* Update PreviewTaxAmountCommand

* Remove unused UpcomingInvoiceOptionExtensions

* Added SubscriptionExtensions with GetCurrentPeriodEnd

* Update PremiumUserBillingService

* Update OrganizationBillingService

* Update GetOrganizationWarningsQuery

* Update BillingHistoryInfo

* Update SubscriptionInfo

* Remove unused Sql Billing folder

* Update StripeAdapter

* Update StripePaymentService

* Update InvoiceCreatedHandler

* Update PaymentFailedHandler

* Update PaymentSucceededHandler

* Update ProviderEventService

* Update StripeEventUtilityService

* Update SubscriptionDeletedHandler

* Update SubscriptionUpdatedHandler

* Update UpcomingInvoiceHandler

* Update ProviderSubscriptionResponse

* Remove unused Stripe Subscriptions Admin Tool

* Update RemoveOrganizationFromProviderCommand

* Update ProviderBillingService

* Update RemoveOrganizatinoFromProviderCommandTests

* Update PreviewTaxAmountCommandTests

* Update GetCloudOrganizationLicenseQueryTests

* Update GetOrganizationWarningsQueryTests

* Update StripePaymentServiceTests

* Update ProviderBillingControllerTests

* Update ProviderEventServiceTests

* Update SubscriptionDeletedHandlerTests

* Update SubscriptionUpdatedHandlerTests

* Resolve Billing test failures

I completely removed tests for the StripeEventService as they were using a system I setup a while back that read JSON files of the Stripe event structure. I did not anticipate how frequently these structures would change with each API version and the cost of trying to update these specific JSON files to test a very static data retrieval service far outweigh the benefit.

* Resolve Core test failures

* Run dotnet format

* Remove unused provider migration

* Fixed failing tests

* Run dotnet format

* Replace the old webhook secret key with new one (#6223)

* Fix compilation failures in additions

* Run dotnet format

* Bump Stripe API version

* Fix recent addition: CreatePremiumCloudHostedSubscriptionCommand

* Fix new code in main according to Stripe update

* Fix InvoiceExtensions

* Bump SDK version to match API Version

* cleanup

* fixing items missed after the merge

* use expression body for all simple returns

* forgot fixes, format, and pr feedback

* claude pr feedback

* pr feedback and cleanup

* more claude feedback

---------

Co-authored-by: Alex Morask <amorask@bitwarden.com>
Co-authored-by: cyprain-okeke <108260115+cyprain-okeke@users.noreply.github.com>
2025-12-12 15:32:43 -06:00
Jared McCannon
2f893768f5 [PM-18718] Refactor Bulk Revoke Users (#6601) 2025-12-05 11:19:26 -06:00
Rui Tomé
5469d8be0e [PM-28260] Optimize bulk reinvite endpoint (#6670)
* Implement optimized bulk invite resend command

- Added IBulkResendOrganizationInvitesCommand interface to define the bulk resend operation.
- Created BulkResendOrganizationInvitesCommand class to handle the logic for resending invites to multiple organization users.
- Integrated logging and validation to ensure only valid users receive invites.
- Included error handling for non-existent organizations and invalid user statuses.

* Add unit tests for BulkResendOrganizationInvitesCommand

- Implemented comprehensive test cases for the BulkResendOrganizationInvitesCommand class.
- Validated user statuses and ensured correct handling of valid and invalid users during bulk invite resends.
- Included tests for scenarios such as organization not found and empty user lists.
- Utilized Xunit and NSubstitute for effective testing and mocking of dependencies.

* Add IBulkResendOrganizationInvitesCommand to service collection

- Registered IBulkResendOrganizationInvitesCommand in the service collection for dependency injection.

* Update OrganizationUsersController to utilize IBulkResendOrganizationInvitesCommand

- Added IBulkResendOrganizationInvitesCommand to the OrganizationUsersController for handling bulk invite resends based on feature flag.
- Updated BulkReinvite method to conditionally use the new command or the legacy service based on the feature flag status.
- Enhanced unit tests to verify correct command usage depending on feature flag state, ensuring robust testing for both scenarios.
2025-12-05 16:28:04 +00:00