mirror of
https://github.com/bitwarden/server
synced 2026-02-26 17:33:40 +00:00
Purpose: UseMyItems is a new organization ability / plan flag which is automatically enabled where UsePolicies is enabled, but can be selectively disabled to disable My Items creation when the Organization Data Ownership policy is turned on. - new organization table column with all sprocs and views updated - data migration to enable the feature for all organizations that already use policies (replicating existing behaviour) - data and api models updated - added to organization license file so it can be preserved in self-hosted instances - note that we don't have a plan feature defined for this yet, so it is set based on UsePolicies to match the migration logic. Billing Team have a ticket to add this
77 lines
2.8 KiB
C#
77 lines
2.8 KiB
C#
using Bit.Core.AdminConsole.Entities;
|
|
using Bit.Core.Repositories;
|
|
using Bit.Infrastructure.IntegrationTest.Services;
|
|
using Xunit;
|
|
|
|
namespace Bit.Infrastructure.IntegrationTest.AdminConsole.Migrations;
|
|
|
|
public class UseMyItemsDataMigrationTests
|
|
{
|
|
private const string _migrationName = "UseMyItemsDataMigration";
|
|
|
|
[Theory, DatabaseData(MigrationName = _migrationName)]
|
|
public async Task Migration_WithUsePoliciesEnabled_SetsUseMyItemsToTrue(
|
|
IOrganizationRepository organizationRepository,
|
|
IMigrationTesterService migrationTester)
|
|
{
|
|
// Arrange
|
|
var organization = await SetupOrganization(organizationRepository, usePolicies: true);
|
|
|
|
// Verify initial state
|
|
Assert.True(organization.UsePolicies);
|
|
Assert.False(organization.UseMyItems);
|
|
|
|
// Act
|
|
migrationTester.ApplyMigration();
|
|
|
|
// Assert
|
|
var migratedOrganization = await organizationRepository.GetByIdAsync(organization.Id);
|
|
Assert.NotNull(migratedOrganization);
|
|
Assert.True(migratedOrganization.UsePolicies);
|
|
Assert.True(migratedOrganization.UseMyItems);
|
|
}
|
|
|
|
[Theory, DatabaseData(MigrationName = _migrationName)]
|
|
public async Task Migration_WithUsePoliciesDisabled_LeavesUseMyItemsFalse(
|
|
IOrganizationRepository organizationRepository,
|
|
IMigrationTesterService migrationTester)
|
|
{
|
|
// Arrange
|
|
var organization = await SetupOrganization(organizationRepository, usePolicies: false);
|
|
|
|
// Verify initial state
|
|
Assert.False(organization.UsePolicies);
|
|
Assert.False(organization.UseMyItems);
|
|
|
|
// Act
|
|
migrationTester.ApplyMigration();
|
|
|
|
// Assert
|
|
var migratedOrganization = await organizationRepository.GetByIdAsync(organization.Id);
|
|
Assert.NotNull(migratedOrganization);
|
|
Assert.False(migratedOrganization.UsePolicies);
|
|
Assert.False(migratedOrganization.UseMyItems);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Helper method to create a test organization with specified UsePolicies value.
|
|
/// UseMyItems is always initialized to false to simulate pre-migration state.
|
|
/// </summary>
|
|
private static async Task<Organization> SetupOrganization(
|
|
IOrganizationRepository organizationRepository,
|
|
bool usePolicies,
|
|
string identifier = "test")
|
|
{
|
|
// CreateTestOrganizationAsync sets UsePolicies = true by default
|
|
var organization = await organizationRepository.CreateTestOrganizationAsync(identifier: identifier);
|
|
|
|
// Override to test both true and false scenarios
|
|
organization.UsePolicies = usePolicies;
|
|
organization.UseMyItems = false; // Simulate pre-migration state
|
|
|
|
await organizationRepository.ReplaceAsync(organization);
|
|
|
|
return organization;
|
|
}
|
|
}
|