Skip to content

Commit

Permalink
Skip providers that have no clients during migration
Browse files Browse the repository at this point in the history
  • Loading branch information
amorask-bitwarden committed Oct 18, 2024
1 parent 4fec7ca commit 4597afd
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 15 deletions.
19 changes: 8 additions & 11 deletions src/Core/Billing/Migration/Models/ProviderMigrationTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,14 @@
public enum ProviderMigrationProgress
{
Started = 1,
ClientsMigrated = 2,
TeamsPlanConfigured = 3,
EnterprisePlanConfigured = 4,
CustomerSetup = 5,
SubscriptionSetup = 6,
CreditApplied = 7,
Completed = 8,

Reversing = 9,
ReversedClientMigrations = 10,
RemovedProviderPlans = 11
NoClients = 2,
ClientsMigrated = 3,
TeamsPlanConfigured = 4,
EnterprisePlanConfigured = 5,
CustomerSetup = 6,
SubscriptionSetup = 7,
CreditApplied = 8,
Completed = 9,
}

public class ProviderMigrationTracker
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,18 @@ public async Task Migrate(Guid providerId)

await migrationTrackerCache.StartTracker(provider);

await MigrateClientsAsync(providerId);
var organizations = await GetEnabledClientsAsync(provider.Id);

Check warning on line 44 in src/Core/Billing/Migration/Services/Implementations/ProviderMigrator.cs

View check run for this annotation

Codecov / codecov/patch

src/Core/Billing/Migration/Services/Implementations/ProviderMigrator.cs#L44

Added line #L44 was not covered by tests

if (organizations.Count == 0)
{
logger.LogInformation("CB: Skipping migration for provider ({ProviderID}) with no clients", providerId);

Check warning on line 48 in src/Core/Billing/Migration/Services/Implementations/ProviderMigrator.cs

View check run for this annotation

Codecov / codecov/patch

src/Core/Billing/Migration/Services/Implementations/ProviderMigrator.cs#L47-L48

Added lines #L47 - L48 were not covered by tests

await migrationTrackerCache.UpdateTrackingStatus(providerId, ProviderMigrationProgress.NoClients);

Check warning on line 50 in src/Core/Billing/Migration/Services/Implementations/ProviderMigrator.cs

View check run for this annotation

Codecov / codecov/patch

src/Core/Billing/Migration/Services/Implementations/ProviderMigrator.cs#L50

Added line #L50 was not covered by tests

return;

Check warning on line 52 in src/Core/Billing/Migration/Services/Implementations/ProviderMigrator.cs

View check run for this annotation

Codecov / codecov/patch

src/Core/Billing/Migration/Services/Implementations/ProviderMigrator.cs#L52

Added line #L52 was not covered by tests
}

await MigrateClientsAsync(providerId, organizations);

Check warning on line 55 in src/Core/Billing/Migration/Services/Implementations/ProviderMigrator.cs

View check run for this annotation

Codecov / codecov/patch

src/Core/Billing/Migration/Services/Implementations/ProviderMigrator.cs#L55

Added line #L55 was not covered by tests

await ConfigureTeamsPlanAsync(providerId);

Expand All @@ -65,6 +76,16 @@ public async Task<ProviderMigrationResult> GetResult(Guid providerId)
return null;
}

if (providerTracker.Progress == ProviderMigrationProgress.NoClients)
{
return new ProviderMigrationResult
{
ProviderId = providerTracker.ProviderId,
ProviderName = providerTracker.ProviderName,
Result = providerTracker.Progress.ToString()
};

Check warning on line 86 in src/Core/Billing/Migration/Services/Implementations/ProviderMigrator.cs

View check run for this annotation

Codecov / codecov/patch

src/Core/Billing/Migration/Services/Implementations/ProviderMigrator.cs#L80-L86

Added lines #L80 - L86 were not covered by tests
}

var clientTrackers = await Task.WhenAll(providerTracker.OrganizationIds.Select(organizationId =>
migrationTrackerCache.GetTracker(providerId, organizationId)));

Expand Down Expand Up @@ -99,12 +120,10 @@ public async Task<ProviderMigrationResult> GetResult(Guid providerId)

#region Steps

private async Task MigrateClientsAsync(Guid providerId)
private async Task MigrateClientsAsync(Guid providerId, List<Organization> organizations)
{
logger.LogInformation("CB: Migrating clients for provider ({ProviderID})", providerId);

var organizations = await GetEnabledClientsAsync(providerId);

var organizationIds = organizations.Select(organization => organization.Id);

await migrationTrackerCache.SetOrganizationIds(providerId, organizationIds);
Expand Down

0 comments on commit 4597afd

Please sign in to comment.