mirror of
https://github.com/bitwarden/server.git
synced 2025-07-02 00:22:50 -05:00

* [PM-17562] Add integration filter support * Repond to PR feedback; Remove Date-related filters * Use tables to format the filter class descriptions * [PM-17562] Add database support for integration filters (#5988) * [PM-17562] Add database support for integration filters * Respond to PR review - fix database scripts * Further database updates; fix Filters to be last in views, stored procs, etc * Fix for missing nulls in stored procedures in main migration script * Reorder Filters to the bottom of OrganizationIntegrationConfiguration * Separate out the creation of filters from the IntegrationFilterService to IntegrationFIlterFactory * Move properties to static readonly field * Fix unit tests failing from merge --------- Co-authored-by: Matt Bishop <mbishop@bitwarden.com>
100 lines
2.7 KiB
C#
100 lines
2.7 KiB
C#
using System.ComponentModel.DataAnnotations;
|
|
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;
|
|
|
|
public class OrganizationIntegrationConfigurationRequestModel
|
|
{
|
|
public string? Configuration { get; set; }
|
|
|
|
[Required]
|
|
public EventType EventType { get; set; }
|
|
|
|
public string? Filters { get; set; }
|
|
|
|
public string? Template { get; set; }
|
|
|
|
public bool IsValidForType(IntegrationType integrationType)
|
|
{
|
|
switch (integrationType)
|
|
{
|
|
case IntegrationType.CloudBillingSync or IntegrationType.Scim:
|
|
return false;
|
|
case IntegrationType.Slack:
|
|
return !string.IsNullOrWhiteSpace(Template) &&
|
|
IsConfigurationValid<SlackIntegrationConfiguration>() &&
|
|
IsFiltersValid();
|
|
case IntegrationType.Webhook:
|
|
return !string.IsNullOrWhiteSpace(Template) &&
|
|
IsConfigurationValid<WebhookIntegrationConfiguration>() &&
|
|
IsFiltersValid();
|
|
default:
|
|
return false;
|
|
|
|
}
|
|
}
|
|
|
|
public OrganizationIntegrationConfiguration ToOrganizationIntegrationConfiguration(Guid organizationIntegrationId)
|
|
{
|
|
return new OrganizationIntegrationConfiguration()
|
|
{
|
|
OrganizationIntegrationId = organizationIntegrationId,
|
|
Configuration = Configuration,
|
|
Filters = Filters,
|
|
EventType = EventType,
|
|
Template = Template
|
|
};
|
|
}
|
|
|
|
public OrganizationIntegrationConfiguration ToOrganizationIntegrationConfiguration(OrganizationIntegrationConfiguration currentConfiguration)
|
|
{
|
|
currentConfiguration.Configuration = Configuration;
|
|
currentConfiguration.EventType = EventType;
|
|
currentConfiguration.Filters = Filters;
|
|
currentConfiguration.Template = Template;
|
|
|
|
return currentConfiguration;
|
|
}
|
|
|
|
private bool IsConfigurationValid<T>()
|
|
{
|
|
if (string.IsNullOrWhiteSpace(Configuration))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
try
|
|
{
|
|
var config = JsonSerializer.Deserialize<T>(Configuration);
|
|
return config is not null;
|
|
}
|
|
catch
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
private bool IsFiltersValid()
|
|
{
|
|
if (Filters is null)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
try
|
|
{
|
|
var filters = JsonSerializer.Deserialize<IntegrationFilterGroup>(Filters);
|
|
return filters is not null;
|
|
}
|
|
catch
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
}
|