Browse Source

Flow improvements (#1337)

* Improvements

* Frontend improvements.

* New action.
pull/1341/head
Sebastian Stehle 2 months ago
committed by GitHub
parent
commit
c440cc4ab4
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 97
      backend/extensions/Squidex.Extensions/Actions/AzureServiceBus/AzureServiceBusFlowStep.cs
  2. 20
      backend/extensions/Squidex.Extensions/Actions/AzureServiceBus/AzureServiceBusPlugin.cs
  3. 68
      backend/extensions/Squidex.Extensions/Actions/CreateContent/CreateContentFlowStep.cs
  4. 1
      backend/extensions/Squidex.Extensions/Squidex.Extensions.csproj
  5. 8
      todo.md

97
backend/extensions/Squidex.Extensions/Actions/AzureServiceBus/AzureServiceBusFlowStep.cs

@ -0,0 +1,97 @@
// ==========================================================================
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex UG (haftungsbeschraenkt)
// All rights reserved. Licensed under the MIT license.
// ==========================================================================
using System.ComponentModel.DataAnnotations;
using Azure.Messaging.ServiceBus;
using Squidex.Flows;
using Squidex.Infrastructure.Validation;
namespace Squidex.Extensions.Actions.AzureServiceBus;
[FlowStep(
Title = "Azure Service Bus",
IconImage = "<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'><path d='M.011 16L0 6.248l12-1.63V16zM14 4.328L29.996 2v14H14zM30 18l-.004 14L14 29.75V18zM12 29.495L.01 27.851.009 18H12z'/></svg>",
IconColor = "#0d9bf9",
Display = "Send to Azure Service Bus",
Description = "Send an event to an azure service bus queue or topic.",
ReadMore = "https://azure.microsoft.com/en-us/products/service-bus/")]
public sealed record AzureServiceBusFlowStep : FlowStep
{
[LocalizedRequired]
[Display(Name = "Connection", Description = "The connection string to the service bus namespace.")]
[Editor(FlowStepEditor.Text)]
[Expression]
public string ConnectionString { get; set; }
[LocalizedRequired]
[Display(Name = "Queue or Topic", Description = "The name of the queue or topic.")]
[Editor(FlowStepEditor.Text)]
[Expression]
public string QueueOrTopic { get; set; }
[Display(Name = "Payload (Optional)", Description = "Leave it empty to use the full event as body.")]
[Editor(FlowStepEditor.TextArea)]
[Expression(ExpressionFallback.Envelope)]
public string? Payload { get; set; }
[Display(Name = "Subject (Optional)", Description = "The subject of the message, commonly used for filtering in subscriptions.")]
[Editor(FlowStepEditor.Text)]
[Expression]
public string? Subject { get; set; }
[Display(Name = "Session ID (Optional)", Description = "The session ID, required for session enabled queues and subscriptions.")]
[Editor(FlowStepEditor.Text)]
[Expression]
public string? SessionId { get; set; }
[Display(Name = "Message ID (Optional)", Description = "The message ID, used for duplicate detection.")]
[Editor(FlowStepEditor.Text)]
[Expression]
public string? MessageId { get; set; }
// The client owns the connection and is thread safe, senders are cheap and are created per message.
private static readonly ClientPool<string, ServiceBusClient> Clients = new ClientPool<string, ServiceBusClient>(key =>
{
return new ServiceBusClient(key);
});
public async override ValueTask<FlowStepResult> ExecuteAsync(FlowExecutionContext executionContext,
CancellationToken ct)
{
if (executionContext.IsSimulation)
{
executionContext.LogSkipSimulation();
return Next();
}
var client = await Clients.GetClientAsync(ConnectionString);
var message = new ServiceBusMessage(Payload);
if (!string.IsNullOrWhiteSpace(Subject))
{
message.Subject = Subject;
}
if (!string.IsNullOrWhiteSpace(SessionId))
{
message.SessionId = SessionId;
}
if (!string.IsNullOrWhiteSpace(MessageId))
{
message.MessageId = MessageId;
}
await using var sender = client.CreateSender(QueueOrTopic);
await sender.SendMessageAsync(message, ct);
executionContext.Log($"Message sent to '{QueueOrTopic}'.");
return Next();
}
}

20
backend/extensions/Squidex.Extensions/Actions/AzureServiceBus/AzureServiceBusPlugin.cs

@ -0,0 +1,20 @@
// ==========================================================================
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex UG (haftungsbeschraenkt)
// All rights reserved. Licensed under the MIT license.
// ==========================================================================
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Squidex.Infrastructure.Plugins;
namespace Squidex.Extensions.Actions.AzureServiceBus;
public sealed class AzureServiceBusPlugin : IPlugin
{
public void ConfigureServices(IServiceCollection services, IConfiguration config)
{
services.AddFlowStep<AzureServiceBusFlowStep>();
}
}

68
backend/extensions/Squidex.Extensions/Actions/CreateContent/CreateContentFlowStep.cs

@ -17,7 +17,9 @@ using Squidex.Infrastructure;
using Squidex.Infrastructure.Commands;
using Squidex.Infrastructure.Reflection;
using Squidex.Infrastructure.Validation;
using Command = Squidex.Domain.Apps.Entities.Contents.Commands.CreateContent;
using ContentDataCommand = Squidex.Domain.Apps.Entities.Contents.Commands.ContentDataCommand;
using CreateCommand = Squidex.Domain.Apps.Entities.Contents.Commands.CreateContent;
using UpsertCommand = Squidex.Domain.Apps.Entities.Contents.Commands.UpsertContent;
namespace Squidex.Extensions.Actions.CreateContent;
@ -26,7 +28,7 @@ namespace Squidex.Extensions.Actions.CreateContent;
IconImage = "<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 28 28'><path d='M21.875 28H6.125A6.087 6.087 0 010 21.875V6.125A6.087 6.087 0 016.125 0h15.75A6.087 6.087 0 0128 6.125v15.75A6.088 6.088 0 0121.875 28zM6.125 1.75A4.333 4.333 0 001.75 6.125v15.75a4.333 4.333 0 004.375 4.375h15.75a4.333 4.333 0 004.375-4.375V6.125a4.333 4.333 0 00-4.375-4.375H6.125z'/><path d='M13.125 12.25H7.35c-1.575 0-2.888-1.313-2.888-2.888V7.349c0-1.575 1.313-2.888 2.888-2.888h5.775c1.575 0 2.887 1.313 2.887 2.888v2.013c0 1.575-1.312 2.888-2.887 2.888zM7.35 6.212c-.613 0-1.138.525-1.138 1.138v2.012A1.16 1.16 0 007.35 10.5h5.775a1.16 1.16 0 001.138-1.138V7.349a1.16 1.16 0 00-1.138-1.138H7.35zM22.662 16.713H5.337c-.525 0-.875-.35-.875-.875s.35-.875.875-.875h17.237c.525 0 .875.35.875.875s-.35.875-.787.875zM15.138 21.262h-9.8c-.525 0-.875-.35-.875-.875s.35-.875.875-.875h9.713c.525 0 .875.35.875.875s-.35.875-.787.875z'/></svg>",
IconColor = "#3389ff",
Display = "Create content",
Description = "Create a a new content item for any schema.")]
Description = "Create a new content item for any schema, or update it if it already exists.")]
#pragma warning disable CS0618 // Type or member is obsolete
public sealed record CreateContentFlowStep : FlowStep, IConvertibleToAction
#pragma warning restore CS0618 // Type or member is obsolete
@ -47,19 +49,34 @@ public sealed record CreateContentFlowStep : FlowStep, IConvertibleToAction
public string? Client { get; set; }
[Display(Name = "Publish", Description = "Publish the content.")]
[Editor(FlowStepEditor.Text)]
[Editor(FlowStepEditor.Checkbox)]
public bool Publish { get; set; }
[Display(Name = "ID (Optional)", Description = "The ID of the content. If set, the content is created when it does not exist and updated otherwise.")]
[Editor(FlowStepEditor.Text)]
[Expression]
public string? Id { get; set; }
[Display(Name = "Patch", Description = "Only update the fields from the data when the content already exists. Requires an ID.")]
[Editor(FlowStepEditor.Checkbox)]
public bool Patch { get; set; }
public override ValueTask ValidateAsync(FlowValidationContext validationContext, AddStepError addError,
CancellationToken ct)
{
if (Patch && string.IsNullOrWhiteSpace(Id))
{
addError(nameof(Patch), "Patch requires an ID.");
}
return base.ValidateAsync(validationContext, addError, ct);
}
public override async ValueTask<FlowStepResult> ExecuteAsync(FlowExecutionContext executionContext,
CancellationToken ct)
{
var @event = ((FlowEventContext)executionContext.Context).Event;
var command = new Command
{
AppId = @event.AppId,
};
var schema =
await executionContext.Resolve<IAppProvider>()
.GetSchemaAsync(@event.AppId.Id, Schema, true, ct);
@ -76,6 +93,26 @@ public sealed record CreateContentFlowStep : FlowStep, IConvertibleToAction
return Next();
}
var status = Publish ? Status.Published : (Status?)null;
ContentDataCommand command;
if (!string.IsNullOrWhiteSpace(Id))
{
command = new UpsertCommand
{
ContentId = DomainId.Create(Id.Trim()),
EnrichDefaults = true,
EnrichRequiredFields = false,
Patch = Patch,
Status = status
};
}
else
{
command = new CreateCommand { Status = status };
}
command.AppId = @event.AppId;
command.SchemaId = schema.NamedId();
command.FromRule = true;
command.Data = executionContext.DeserializeJson<ContentData>(Data);
@ -89,15 +126,18 @@ public sealed record CreateContentFlowStep : FlowStep, IConvertibleToAction
command.Actor = userEvent.Actor;
}
if (Publish)
{
command.Status = Status.Published;
}
await executionContext.Resolve<ICommandBus>()
.PublishAsync(command, ct);
executionContext.Log($"Content created for schema '{schema.Name}', ID: {command.ContentId}");
if (command is UpsertCommand)
{
executionContext.Log($"Content upserted for schema '{schema.Name}', ID: {command.ContentId}");
}
else
{
executionContext.Log($"Content created for schema '{schema.Name}', ID: {command.ContentId}");
}
return Next();
}

1
backend/extensions/Squidex.Extensions/Squidex.Extensions.csproj

@ -11,6 +11,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Algolia.Search" Version="6.17.0" />
<PackageReference Include="Azure.Messaging.ServiceBus" Version="7.20.1" />
<PackageReference Include="Azure.Monitor.OpenTelemetry.Exporter" Version="1.7.0" />
<PackageReference Include="Azure.Search.Documents" Version="11.7.0" />
<PackageReference Include="CoreTweet" Version="1.0.0.483" />

8
todo.md

@ -35,9 +35,9 @@ being postponed and declined. See
| [2](#2-export-and-import-content-from-the-ui-as-jobs-3461-1366-3438) | Export/import content from the UI as jobs | Declined ×2 | 5381 | large |
| [3](#3-scope-asset-permissions-to-folders-5921-5676-1229) | Scope asset permissions to folders | Open ×2 + Declined | 3857 | large |
| [4](#4-dark-mode-and-per-app-theming-5720-816) | Dark mode and per-app theming | Open + Declined | 2102 | large |
| [5](#5-azure-service-bus-flow-step-4522) | Azure Service Bus flow step | Postponed | 1838 | medium |
| [5](#5-azure-service-bus-flow-step-4522) | ✅ **Done** — Azure Service Bus flow step | Postponed | 1838 | medium |
| [6](#6-give-scripts-a-way-to-log-2822) | Give scripts a way to log | Unresolved | 2575 | medium |
| [7](#7-upsert-mode-for-the-create-content-flow-step-5616) | Upsert mode for "Create content" step | Unresolved | 786 | small |
| [7](#7-upsert-mode-for-the-create-content-flow-step-5616) | ✅ **Done** — Upsert mode for "Create content" step | Unresolved | 786 | small |
| [8](#8-regenerate-a-client-secret-from-the-ui-5807) | Regenerate a client secret from the UI | Open | 1383 | small |
| [9](#9-show-which-fields-are-required-when-publishing-4375) | ✅ **Done** — Mark "required when publishing" fields | Declined | 1707 | tiny |
| [10](#10-let-users-upload-a-duplicate-asset-anyway-3144) | ✅ **Done** — "Upload anyway" for duplicate assets | Declined | 1356 | tiny |
@ -246,6 +246,8 @@ it look expensive in 2019.
## 5. Azure Service Bus flow step (#4522)
> ✅ **Implemented.** New `AzureServiceBusFlowStep` (`Actions/AzureServiceBus/`) sends to a queue or topic, with connection string, payload, subject, session ID and message ID configurable per step.
**Asked:** contribute a Service Bus action upstream.
<https://support.squidex.io/t/inactive-azure-service-bus-action-type/4522>
· Postponed (`INACTIVE`) · 1838 views · 4 likes · **3 votes** (joint highest of
@ -324,6 +326,8 @@ has a notion of user-visible log lines to imitate.
## 7. Upsert mode for the "Create content" flow step (#5616)
> ✅ **Implemented.** `CreateContentFlowStep` has an optional `ID` (expression) and a `Patch` flag. With an ID it issues `UpsertContent` (create if missing, update or patch otherwise); without one it creates as before.
**Asked:** a rule that creates content when it does not exist and updates it
when it does.
<https://support.squidex.io/t/create-if-not-exists-or-update-content-if-exists-rule/5616>

Loading…
Cancel
Save