mirror of
https://github.com/bitwarden/server
synced 2025-12-29 14:43:39 +00:00
[PM-17562] Add support for null/all event type (#6100)
* [PM-17562] Add support for null/all event type * Address PR Feedback * Adjusted SQL scripts per feedback
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
#nullable enable
|
||||
|
||||
using System.Text.Json;
|
||||
using Bit.Core.AdminConsole.Entities;
|
||||
using Bit.Core.AdminConsole.Models.Data.EventIntegrations;
|
||||
using Bit.Core.Enums;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace Bit.Api.AdminConsole.Models.Request.Organizations;
|
||||
|
||||
@@ -12,8 +12,7 @@ public class OrganizationIntegrationConfigurationRequestModel
|
||||
{
|
||||
public string? Configuration { get; set; }
|
||||
|
||||
[Required]
|
||||
public EventType EventType { get; set; }
|
||||
public EventType? EventType { get; set; }
|
||||
|
||||
public string? Filters { get; set; }
|
||||
|
||||
|
||||
@@ -25,6 +25,6 @@ public class OrganizationIntegrationConfigurationResponseModel : ResponseModel
|
||||
public string? Configuration { get; set; }
|
||||
public string? Filters { get; set; }
|
||||
public DateTime CreationDate { get; set; }
|
||||
public EventType EventType { get; set; }
|
||||
public EventType? EventType { get; set; }
|
||||
public string? Template { get; set; }
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ public class OrganizationIntegrationConfiguration : ITableObject<Guid>
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public Guid OrganizationIntegrationId { get; set; }
|
||||
public EventType EventType { get; set; }
|
||||
public EventType? EventType { get; set; }
|
||||
public string? Configuration { get; set; }
|
||||
public string? Template { get; set; }
|
||||
public DateTime CreationDate { get; internal set; } = DateTime.UtcNow;
|
||||
|
||||
@@ -11,7 +11,7 @@ public class OrganizationIntegrationConfigurationDetails
|
||||
public Guid OrganizationId { get; set; }
|
||||
public Guid OrganizationIntegrationId { get; set; }
|
||||
public IntegrationType IntegrationType { get; set; }
|
||||
public EventType EventType { get; set; }
|
||||
public EventType? EventType { get; set; }
|
||||
public string? Configuration { get; set; }
|
||||
public string? Filters { get; set; }
|
||||
public string? IntegrationConfiguration { get; set; }
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace Bit.Core.Services;
|
||||
|
||||
public class IntegrationConfigurationDetailsCacheService : BackgroundService, IIntegrationConfigurationDetailsCache
|
||||
{
|
||||
private readonly record struct IntegrationCacheKey(Guid OrganizationId, IntegrationType IntegrationType, EventType EventType);
|
||||
private readonly record struct IntegrationCacheKey(Guid OrganizationId, IntegrationType IntegrationType, EventType? EventType);
|
||||
private readonly IOrganizationIntegrationConfigurationRepository _repository;
|
||||
private readonly ILogger<IntegrationConfigurationDetailsCacheService> _logger;
|
||||
private readonly TimeSpan _refreshInterval;
|
||||
@@ -19,8 +19,7 @@ public class IntegrationConfigurationDetailsCacheService : BackgroundService, II
|
||||
public IntegrationConfigurationDetailsCacheService(
|
||||
IOrganizationIntegrationConfigurationRepository repository,
|
||||
GlobalSettings globalSettings,
|
||||
ILogger<IntegrationConfigurationDetailsCacheService> logger
|
||||
)
|
||||
ILogger<IntegrationConfigurationDetailsCacheService> logger)
|
||||
{
|
||||
_repository = repository;
|
||||
_logger = logger;
|
||||
@@ -32,10 +31,21 @@ public class IntegrationConfigurationDetailsCacheService : BackgroundService, II
|
||||
IntegrationType integrationType,
|
||||
EventType eventType)
|
||||
{
|
||||
var key = new IntegrationCacheKey(organizationId, integrationType, eventType);
|
||||
return _cache.TryGetValue(key, out var value)
|
||||
? value
|
||||
: new List<OrganizationIntegrationConfigurationDetails>();
|
||||
var specificKey = new IntegrationCacheKey(organizationId, integrationType, eventType);
|
||||
var allEventsKey = new IntegrationCacheKey(organizationId, integrationType, null);
|
||||
|
||||
var results = new List<OrganizationIntegrationConfigurationDetails>();
|
||||
|
||||
if (_cache.TryGetValue(specificKey, out var specificConfigs))
|
||||
{
|
||||
results.AddRange(specificConfigs);
|
||||
}
|
||||
if (_cache.TryGetValue(allEventsKey, out var fallbackConfigs))
|
||||
{
|
||||
results.AddRange(fallbackConfigs);
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
|
||||
@@ -2,7 +2,7 @@ CREATE TABLE [dbo].[OrganizationIntegrationConfiguration]
|
||||
(
|
||||
[Id] UNIQUEIDENTIFIER NOT NULL,
|
||||
[OrganizationIntegrationId] UNIQUEIDENTIFIER NOT NULL,
|
||||
[EventType] SMALLINT NOT NULL,
|
||||
[EventType] SMALLINT NULL,
|
||||
[Configuration] VARCHAR (MAX) NULL,
|
||||
[Template] VARCHAR (MAX) NULL,
|
||||
[CreationDate] DATETIME2 (7) NOT NULL,
|
||||
|
||||
Reference in New Issue
Block a user