1
0
mirror of https://github.com/bitwarden/server synced 2025-12-23 11:43:23 +00:00

Alter Integration Template processing to remove keys when encountering null values (#6309)

This commit is contained in:
Brant DeBow
2025-09-10 14:17:45 -04:00
committed by GitHub
parent a458db319e
commit e57569ad57
4 changed files with 114 additions and 22 deletions

View File

@@ -1,4 +1,5 @@
using Bit.Core.AdminConsole.Entities;
using System.Text.Json;
using Bit.Core.AdminConsole.Entities;
using Bit.Core.Entities;
using Bit.Core.Enums;
using Bit.Core.Models.Data;
@@ -23,6 +24,8 @@ public class IntegrationTemplateContext(EventMessage eventMessage)
public Guid? GroupId => Event.GroupId;
public Guid? PolicyId => Event.PolicyId;
public string EventMessage => JsonSerializer.Serialize(Event);
public User? User { get; set; }
public string? UserName => User?.Name;
public string? UserEmail => User?.Email;

View File

@@ -1,6 +1,5 @@
#nullable enable
using System.Text.Json;
using System.Text.RegularExpressions;
namespace Bit.Core.AdminConsole.Utilities;
@@ -20,15 +19,14 @@ public static partial class IntegrationTemplateProcessor
return TokenRegex().Replace(template, match =>
{
var propertyName = match.Groups[1].Value;
if (propertyName == "EventMessage")
var property = type.GetProperty(propertyName);
if (property == null)
{
return JsonSerializer.Serialize(values);
}
else
{
var property = type.GetProperty(propertyName);
return property?.GetValue(values)?.ToString() ?? match.Value;
return match.Value; // Return unknown keys as keys - i.e. #Key#
}
return property?.GetValue(values)?.ToString() ?? "";
});
}