mirror of
https://github.com/bitwarden/server
synced 2026-01-02 08:33:48 +00:00
* Add CQRS and caching support for OrganizationIntegrations * Use primary constructor for Delete command, per Claude suggestion * Fix namespace * Add XMLDoc for new commands / queries * Remove unnecessary extra call to AddExtendedCache in Startup (call in EventIntegrationsServiceCollectionExtensions handles this instead) * Alter strategy to use one cache / database call to retrieve all configurations for an event (including wildcards) * Updated README documentation to reflect updated Caching doc and updated CQRS approach
46 lines
1.7 KiB
C#
46 lines
1.7 KiB
C#
using Bit.Core.AdminConsole.Entities;
|
|
using Bit.Core.AdminConsole.EventIntegrations.OrganizationIntegrations.Interfaces;
|
|
using Bit.Core.Exceptions;
|
|
using Bit.Core.Repositories;
|
|
using Bit.Core.Utilities;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using ZiggyCreatures.Caching.Fusion;
|
|
|
|
namespace Bit.Core.AdminConsole.EventIntegrations.OrganizationIntegrations;
|
|
|
|
/// <summary>
|
|
/// Command implementation for updating organization integrations with cache invalidation support.
|
|
/// </summary>
|
|
public class UpdateOrganizationIntegrationCommand(
|
|
IOrganizationIntegrationRepository integrationRepository,
|
|
[FromKeyedServices(EventIntegrationsCacheConstants.CacheName)]
|
|
IFusionCache cache)
|
|
: IUpdateOrganizationIntegrationCommand
|
|
{
|
|
public async Task<OrganizationIntegration> UpdateAsync(
|
|
Guid organizationId,
|
|
Guid integrationId,
|
|
OrganizationIntegration updatedIntegration)
|
|
{
|
|
var integration = await integrationRepository.GetByIdAsync(integrationId);
|
|
if (integration is null ||
|
|
integration.OrganizationId != organizationId ||
|
|
integration.Type != updatedIntegration.Type)
|
|
{
|
|
throw new NotFoundException();
|
|
}
|
|
|
|
updatedIntegration.Id = integration.Id;
|
|
updatedIntegration.OrganizationId = integration.OrganizationId;
|
|
updatedIntegration.CreationDate = integration.CreationDate;
|
|
await integrationRepository.ReplaceAsync(updatedIntegration);
|
|
await cache.RemoveByTagAsync(
|
|
EventIntegrationsCacheConstants.BuildCacheTagForOrganizationIntegration(
|
|
organizationId: organizationId,
|
|
integrationType: integration.Type
|
|
));
|
|
|
|
return updatedIntegration;
|
|
}
|
|
}
|