Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Apps.Contentful/Apps.Contentful.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<Nullable>enable</Nullable>
<Product>Contentful</Product>
<Description>The headless content management system</Description>
<Version>1.8.10</Version>
<Version>1.8.11</Version>
<AssemblyName>Apps.Contentful</AssemblyName>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,20 @@ public class WorkflowStepDataHandler(
public async Task<Dictionary<string, string>> GetDataAsync(DataSourceContext context,
CancellationToken cancellationToken)
{
if (string.IsNullOrEmpty(workflowStepFilterRequest.WorkflowDefinitionId))
var workflowDefinitionId = workflowStepFilterRequest.WorkflowDefinitionId?.FirstOrDefault();

if (string.IsNullOrEmpty(workflowDefinitionId))
{
throw new InvalidOperationException("You should provide a workflow definition ID first");
}

var client = new ContentfulRestClient(Creds, identifier.Environment);
var request = new ContentfulRestRequest($"/workflow_definitions/{workflowStepFilterRequest.WorkflowDefinitionId}", Method.Get, Creds);
var request = new ContentfulRestRequest($"/workflow_definitions/{workflowDefinitionId}", Method.Get, Creds);
var workflowDefinition = await client.ExecuteWithErrorHandling<WorkflowDefinitionDto>(request);

return workflowDefinition.Steps
.Where(x => context.SearchString is null ||
x.Name.Contains(context.SearchString, StringComparison.OrdinalIgnoreCase))
.ToDictionary(x => x.StepId, x => x.Name);
}
}
}
14 changes: 11 additions & 3 deletions Apps.Contentful/HtmlHelpers/EntryToJsonConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,11 @@ private static JToken ParseValueFromNode(HtmlNode node)
return ParseUlAsArray(ulChild);
}

var textValue = System.Web.HttpUtility.HtmlDecode(node.InnerText.Trim());
var textValue = HttpUtility.HtmlDecode(node.InnerText.Trim());

if (bool.TryParse(textValue, out var boolValue))
return JValue.FromObject(boolValue);

return JValue.FromObject(textValue);
}

Expand All @@ -387,8 +391,12 @@ private static JToken ParseUlAsArray(HtmlNode ulNode)
continue;
}

var textValue = System.Web.HttpUtility.HtmlDecode(li.InnerText.Trim());
array.Add(JValue.FromObject(textValue));
var textValue = HttpUtility.HtmlDecode(li.InnerText.Trim());

if (bool.TryParse(textValue, out var boolValue))
array.Add(JValue.FromObject(boolValue));
else
array.Add(JValue.FromObject(textValue));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ namespace Apps.Contentful.Models.Identifiers;
public class WorkflowDefinitionOptionalIdentifier
{
[Display("Workflow definition ID"), DataSource(typeof(WorkflowDefinitionDataHandler))]
public string? WorkflowDefinitionId { get; set; }
public IEnumerable<string>? WorkflowDefinitionId { get; set; }
}
9 changes: 2 additions & 7 deletions Apps.Contentful/Models/Requests/WorkflowStepFilterRequest.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
using Apps.Contentful.DataSourceHandlers;
using Apps.Contentful.Models.Identifiers;
using Blackbird.Applications.Sdk.Common;
using Blackbird.Applications.Sdk.Common.Dynamic;

namespace Apps.Contentful.Models.Requests;

public class WorkflowStepFilterRequest : WorkflowDefinitionOptionalIdentifier
{
[Display("Current step ID"), DataSource(typeof(WorkflowStepDataHandler))]
public string? CurrentStepId { get; set; }

[Display("Current step name", Description = "Filter by the name of the current step")]
public string? CurrentStepName { get; set; }
}
public IEnumerable<string>? CurrentStepName { get; set; }
}
27 changes: 15 additions & 12 deletions Apps.Contentful/Webhooks/WorkflowWebhookList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,18 @@ private async Task<WebhookResponse<WorkflowDefinitionResponse>> HandleWebhookRes
{
var content = webhookRequest.Body.ToString()!;
var workflowDto = JsonConvert.DeserializeObject<WorkflowDto>(content)!;
var workflowDefinitionId = workflowDto.Sys.WorkflowDefinition.Sys.Id;

if (request.WorkflowDefinitionId?.Any() == true &&
request.WorkflowDefinitionId.Contains(workflowDefinitionId) == false)
{
return new WebhookResponse<WorkflowDefinitionResponse>
{
ReceivedWebhookRequestType = WebhookRequestType.Preflight
};
}

var workflowDefinitionRequest = new ContentfulRestRequest($"/workflow_definitions/{workflowDto.Sys.WorkflowDefinition.Sys.Id}", Method.Get, Creds);
var workflowDefinitionRequest = new ContentfulRestRequest($"/workflow_definitions/{workflowDefinitionId}", Method.Get, Creds);
var client = new ContentfulRestClient(Creds, environmentIdentifier.Environment);
var workflowDefinition = await client.ExecuteWithErrorHandling<WorkflowDefinitionDto>(workflowDefinitionRequest);

Expand All @@ -44,16 +54,9 @@ private async Task<WebhookResponse<WorkflowDefinitionResponse>> HandleWebhookRes
var nextStep = nextStepIndex < workflowDefinition.Steps.Count ? workflowDefinition.Steps[nextStepIndex] : null;

var previousStep = workflowDefinition.Steps.FirstOrDefault(x => x.StepId == workflowDto.PreviousStepId);

if (request.CurrentStepId != null && request.CurrentStepId != workflowDto.StepId)
{
return new WebhookResponse<WorkflowDefinitionResponse>
{
ReceivedWebhookRequestType = WebhookRequestType.Preflight
};
}

if (request.CurrentStepName != null && request.CurrentStepName != currentStep.Name)

if (request.CurrentStepName?.Any() == true &&
request.CurrentStepName.Contains(currentStep.Name) == false)
{
return new WebhookResponse<WorkflowDefinitionResponse>
{
Expand Down Expand Up @@ -95,4 +98,4 @@ private async Task<WebhookResponse<WorkflowDefinitionResponse>> HandleWebhookRes
}
};
}
}
}