mirror of https://github.com/Squidex/squidex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.6 KiB
47 lines
1.6 KiB
// ==========================================================================
|
|
// Squidex Headless CMS
|
|
// ==========================================================================
|
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|
// All rights reserved. Licensed under the MIT license.
|
|
// ==========================================================================
|
|
|
|
using Squidex.Domain.Apps.Core.Rules.EnrichedEvents;
|
|
using Squidex.Flows;
|
|
using Squidex.Infrastructure;
|
|
|
|
namespace Squidex.Extensions.Actions;
|
|
|
|
public static class RuleHelper
|
|
{
|
|
public static bool ShouldDelete(this EnrichedEvent @event, FlowExecutionContext context, string? expression)
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(expression))
|
|
{
|
|
return context.Evaluate(expression, context.Context);
|
|
}
|
|
|
|
return IsContentDeletion(@event) || IsAssetDeletion(@event);
|
|
}
|
|
|
|
public static bool IsContentDeletion(this EnrichedEvent @event)
|
|
{
|
|
return @event is EnrichedContentEvent { Type: EnrichedContentEventType.Deleted or EnrichedContentEventType.Unpublished };
|
|
}
|
|
|
|
public static bool IsAssetDeletion(this EnrichedEvent @event)
|
|
{
|
|
return @event is EnrichedAssetEvent { Type: EnrichedAssetEventType.Deleted };
|
|
}
|
|
|
|
public static (string Id, bool IsGenerated) GetOrCreateId(this EnrichedEvent @event)
|
|
{
|
|
if (@event is IEnrichedEntityEvent enrichedEntityEvent)
|
|
{
|
|
return (enrichedEntityEvent.Id.ToString(), false);
|
|
}
|
|
else
|
|
{
|
|
return (DomainId.NewGuid().ToString(), true);
|
|
}
|
|
}
|
|
}
|
|
|