-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Add CQRS and caching support for OrganizationIntegrationConfigurations #6690
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
brant-livefront
merged 1 commit into
main
from
add-cqrs-and-cache-support-for-organization-integration-configurations
Dec 12, 2025
+1,674
−1,103
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
...rganizationIntegrationConfigurations/CreateOrganizationIntegrationConfigurationCommand.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| using Bit.Core.AdminConsole.Entities; | ||
| using Bit.Core.AdminConsole.EventIntegrations.OrganizationIntegrationConfigurations.Interfaces; | ||
| using Bit.Core.AdminConsole.Services; | ||
| 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.OrganizationIntegrationConfigurations; | ||
|
|
||
| /// <summary> | ||
| /// Command implementation for creating organization integration configurations with validation and cache invalidation support. | ||
| /// </summary> | ||
| public class CreateOrganizationIntegrationConfigurationCommand( | ||
| IOrganizationIntegrationRepository integrationRepository, | ||
| IOrganizationIntegrationConfigurationRepository configurationRepository, | ||
| [FromKeyedServices(EventIntegrationsCacheConstants.CacheName)] IFusionCache cache, | ||
| IOrganizationIntegrationConfigurationValidator validator) | ||
| : ICreateOrganizationIntegrationConfigurationCommand | ||
| { | ||
| public async Task<OrganizationIntegrationConfiguration> CreateAsync( | ||
| Guid organizationId, | ||
| Guid integrationId, | ||
| OrganizationIntegrationConfiguration configuration) | ||
| { | ||
| var integration = await integrationRepository.GetByIdAsync(integrationId); | ||
| if (integration == null || integration.OrganizationId != organizationId) | ||
| { | ||
| throw new NotFoundException(); | ||
| } | ||
| if (!validator.ValidateConfiguration(integration.Type, configuration)) | ||
| { | ||
| throw new BadRequestException( | ||
| $"Invalid Configuration and/or Filters for integration type {integration.Type}"); | ||
| } | ||
|
|
||
| var created = await configurationRepository.CreateAsync(configuration); | ||
|
|
||
| // Invalidate the cached configuration details | ||
| // Even though this is a new record, the cache could hold a stale empty list for this | ||
| if (created.EventType == null) | ||
| { | ||
| // Wildcard configuration - invalidate all cached results for this org/integration | ||
| await cache.RemoveByTagAsync( | ||
| EventIntegrationsCacheConstants.BuildCacheTagForOrganizationIntegration( | ||
| organizationId: organizationId, | ||
| integrationType: integration.Type | ||
| )); | ||
| } | ||
| else | ||
| { | ||
| // Specific event type - only invalidate that specific cache entry | ||
| await cache.RemoveAsync( | ||
| EventIntegrationsCacheConstants.BuildCacheKeyForOrganizationIntegrationConfigurationDetails( | ||
| organizationId: organizationId, | ||
| integrationType: integration.Type, | ||
| eventType: created.EventType.Value | ||
| )); | ||
| } | ||
|
|
||
| return created; | ||
| } | ||
| } |
54 changes: 54 additions & 0 deletions
54
...rganizationIntegrationConfigurations/DeleteOrganizationIntegrationConfigurationCommand.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| using Bit.Core.AdminConsole.EventIntegrations.OrganizationIntegrationConfigurations.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.OrganizationIntegrationConfigurations; | ||
|
|
||
| /// <summary> | ||
| /// Command implementation for deleting organization integration configurations with cache invalidation support. | ||
| /// </summary> | ||
| public class DeleteOrganizationIntegrationConfigurationCommand( | ||
| IOrganizationIntegrationRepository integrationRepository, | ||
| IOrganizationIntegrationConfigurationRepository configurationRepository, | ||
| [FromKeyedServices(EventIntegrationsCacheConstants.CacheName)] IFusionCache cache) | ||
| : IDeleteOrganizationIntegrationConfigurationCommand | ||
| { | ||
| public async Task DeleteAsync(Guid organizationId, Guid integrationId, Guid configurationId) | ||
| { | ||
| var integration = await integrationRepository.GetByIdAsync(integrationId); | ||
| if (integration == null || integration.OrganizationId != organizationId) | ||
| { | ||
| throw new NotFoundException(); | ||
| } | ||
| var configuration = await configurationRepository.GetByIdAsync(configurationId); | ||
| if (configuration is null || configuration.OrganizationIntegrationId != integrationId) | ||
| { | ||
| throw new NotFoundException(); | ||
| } | ||
|
|
||
| await configurationRepository.DeleteAsync(configuration); | ||
|
|
||
| if (configuration.EventType == null) | ||
| { | ||
| // Wildcard configuration - invalidate all cached results for this org/integration | ||
| await cache.RemoveByTagAsync( | ||
| EventIntegrationsCacheConstants.BuildCacheTagForOrganizationIntegration( | ||
| organizationId: organizationId, | ||
| integrationType: integration.Type | ||
| )); | ||
| } | ||
| else | ||
| { | ||
| // Specific event type - only invalidate that specific cache entry | ||
| await cache.RemoveAsync( | ||
| EventIntegrationsCacheConstants.BuildCacheKeyForOrganizationIntegrationConfigurationDetails( | ||
| organizationId: organizationId, | ||
| integrationType: integration.Type, | ||
| eventType: configuration.EventType.Value | ||
| )); | ||
| } | ||
| } | ||
| } |
29 changes: 29 additions & 0 deletions
29
...ns/OrganizationIntegrationConfigurations/GetOrganizationIntegrationConfigurationsQuery.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| using Bit.Core.AdminConsole.Entities; | ||
| using Bit.Core.AdminConsole.EventIntegrations.OrganizationIntegrationConfigurations.Interfaces; | ||
| using Bit.Core.Exceptions; | ||
| using Bit.Core.Repositories; | ||
|
|
||
| namespace Bit.Core.AdminConsole.EventIntegrations.OrganizationIntegrationConfigurations; | ||
|
|
||
| /// <summary> | ||
| /// Query implementation for retrieving organization integration configurations. | ||
| /// </summary> | ||
| public class GetOrganizationIntegrationConfigurationsQuery( | ||
| IOrganizationIntegrationRepository integrationRepository, | ||
| IOrganizationIntegrationConfigurationRepository configurationRepository) | ||
| : IGetOrganizationIntegrationConfigurationsQuery | ||
| { | ||
| public async Task<List<OrganizationIntegrationConfiguration>> GetManyByIntegrationAsync( | ||
| Guid organizationId, | ||
| Guid integrationId) | ||
| { | ||
| var integration = await integrationRepository.GetByIdAsync(integrationId); | ||
| if (integration == null || integration.OrganizationId != organizationId) | ||
| { | ||
| throw new NotFoundException(); | ||
| } | ||
|
|
||
| var configurations = await configurationRepository.GetManyByIntegrationAsync(integrationId); | ||
| return configurations.ToList(); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.