mirror of
https://github.com/bitwarden/server
synced 2026-01-06 18:43:36 +00:00
[PM 21897]Add Manual Enable/Disable Override for Providers in Admin Portal (#6072)
* Add the changes for the enable provider * remove the wanted permission added * Added a unit testing for the updateAsync
This commit is contained in:
@@ -152,7 +152,15 @@ public class ProviderService : IProviderService
|
||||
throw new ArgumentException("Cannot create provider this way.");
|
||||
}
|
||||
|
||||
var existingProvider = await _providerRepository.GetByIdAsync(provider.Id);
|
||||
var enabledStatusChanged = existingProvider != null && existingProvider.Enabled != provider.Enabled;
|
||||
|
||||
await _providerRepository.ReplaceAsync(provider);
|
||||
|
||||
if (enabledStatusChanged && (provider.Type == ProviderType.Msp || provider.Type == ProviderType.BusinessUnit))
|
||||
{
|
||||
await UpdateClientOrganizationsEnabledStatusAsync(provider.Id, provider.Enabled);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<List<ProviderUser>> InviteUserAsync(ProviderUserInvite<string> invite)
|
||||
@@ -728,4 +736,20 @@ public class ProviderService : IProviderService
|
||||
throw new BadRequestException($"Unsupported provider type {providerType}.");
|
||||
}
|
||||
}
|
||||
|
||||
private async Task UpdateClientOrganizationsEnabledStatusAsync(Guid providerId, bool enabled)
|
||||
{
|
||||
var providerOrganizations = await _providerOrganizationRepository.GetManyDetailsByProviderAsync(providerId);
|
||||
|
||||
foreach (var providerOrganization in providerOrganizations)
|
||||
{
|
||||
var organization = await _organizationRepository.GetByIdAsync(providerOrganization.OrganizationId);
|
||||
if (organization != null && organization.Enabled != enabled)
|
||||
{
|
||||
organization.Enabled = enabled;
|
||||
await _organizationRepository.ReplaceAsync(organization);
|
||||
await _applicationCacheService.UpsertOrganizationAbilityAsync(organization);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user