Skip to content

Commit

Permalink
Fix training comma issue
Browse files Browse the repository at this point in the history
Fix #16542
  • Loading branch information
MikeAlhayek committed Aug 8, 2024
1 parent ecfd665 commit c281e99
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 95 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public override async Task<IDisplayResult> UpdateAsync(ContentPartFieldDefinitio
}
else
{
var jsonSettings = JObject.Parse(model.Options);
var jsonSettings = JObject.Parse(model.Options, JOptions.Node, JOptions.Document);
jsonSettings["language"] = "html";
var settings = new HtmlFieldMonacoEditorSettings
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,119 +12,118 @@
using OrchardCore.Workflows.Models;
using OrchardCore.Workflows.Services;

namespace OrchardCore.Contents.Workflows.Activities
namespace OrchardCore.Contents.Workflows.Activities;

public class CreateContentTask : ContentTask
{
public class CreateContentTask : ContentTask
private readonly IWorkflowExpressionEvaluator _expressionEvaluator;
private readonly JavaScriptEncoder _javaScriptEncoder;

public CreateContentTask(
IContentManager contentManager,
IWorkflowExpressionEvaluator expressionEvaluator,
IWorkflowScriptEvaluator scriptEvaluator,
IStringLocalizer<CreateContentTask> localizer,
JavaScriptEncoder javaScriptEncoder)
: base(contentManager, scriptEvaluator, localizer)
{
private readonly IWorkflowExpressionEvaluator _expressionEvaluator;
private readonly JavaScriptEncoder _javaScriptEncoder;

public CreateContentTask(
IContentManager contentManager,
IWorkflowExpressionEvaluator expressionEvaluator,
IWorkflowScriptEvaluator scriptEvaluator,
IStringLocalizer<CreateContentTask> localizer,
JavaScriptEncoder javaScriptEncoder)
: base(contentManager, scriptEvaluator, localizer)
{
_expressionEvaluator = expressionEvaluator;
_javaScriptEncoder = javaScriptEncoder;
}
_expressionEvaluator = expressionEvaluator;
_javaScriptEncoder = javaScriptEncoder;
}

public override string Name => nameof(CreateContentTask);
public override string Name => nameof(CreateContentTask);

public override LocalizedString Category => S["Content"];
public override LocalizedString Category => S["Content"];

public override LocalizedString DisplayText => S["Create Content Task"];
public override LocalizedString DisplayText => S["Create Content Task"];

public string ContentType
{
get => GetProperty<string>();
set => SetProperty(value);
}
public string ContentType
{
get => GetProperty<string>();
set => SetProperty(value);
}

public bool Publish
{
get => GetProperty<bool>();
set => SetProperty(value);
}
public bool Publish
{
get => GetProperty<bool>();
set => SetProperty(value);
}

public WorkflowExpression<string> ContentProperties
{
get => GetProperty(() => new WorkflowExpression<string>(JConvert.SerializeObject(new { DisplayText = S["Enter a title"].Value }, JOptions.Indented)));
set => SetProperty(value);
}
public WorkflowExpression<string> ContentProperties
{
get => GetProperty(() => new WorkflowExpression<string>(JConvert.SerializeObject(new { DisplayText = S["Enter a title"].Value }, JOptions.Indented)));
set => SetProperty(value);
}

public override bool CanExecute(WorkflowExecutionContext workflowContext, ActivityContext activityContext)
public override bool CanExecute(WorkflowExecutionContext workflowContext, ActivityContext activityContext)
{
return !string.IsNullOrEmpty(ContentType);
}

public override IEnumerable<Outcome> GetPossibleOutcomes(WorkflowExecutionContext workflowContext, ActivityContext activityContext)
{
return Outcomes(S["Done"], S["Failed"]);
}

public async override Task<ActivityExecutionResult> ExecuteAsync(WorkflowExecutionContext workflowContext, ActivityContext activityContext)
{
if (InlineEvent.IsStart && InlineEvent.ContentType == ContentType)
{
return !string.IsNullOrEmpty(ContentType);
if (InlineEvent.Name == nameof(ContentUpdatedEvent))
{
throw new InvalidOperationException($"The '{nameof(CreateContentTask)}' can't update the content item as it is executed inline from a starting '{nameof(ContentUpdatedEvent)}' of the same content type, which would result in an infinitive loop.");
}

if (InlineEvent.Name == nameof(ContentCreatedEvent))
{
throw new InvalidOperationException($"The '{nameof(CreateContentTask)}' can't create the content item as it is executed inline from a starting '{nameof(ContentCreatedEvent)}' of the same content type, which would result in an infinitive loop.");
}

if (Publish && InlineEvent.Name == nameof(ContentPublishedEvent))
{
throw new InvalidOperationException($"The '{nameof(CreateContentTask)}' can't publish the content item as it is executed inline from a starting '{nameof(ContentPublishedEvent)}' of the same content type, which would result in an infinitive loop.");
}

if (!Publish && InlineEvent.Name == nameof(ContentDraftSavedEvent))
{
throw new InvalidOperationException($"The '{nameof(CreateContentTask)}' can't create the content item as it is executed inline from a starting '{nameof(ContentDraftSavedEvent)}' of the same content type, which would result in an infinitive loop.");
}
}

public override IEnumerable<Outcome> GetPossibleOutcomes(WorkflowExecutionContext workflowContext, ActivityContext activityContext)
var contentItem = await ContentManager.NewAsync(ContentType);

if (!string.IsNullOrWhiteSpace(ContentProperties.Expression))
{
return Outcomes(S["Done"], S["Failed"]);
var contentProperties = await _expressionEvaluator.EvaluateAsync(ContentProperties, workflowContext, _javaScriptEncoder);
contentItem.Merge(JObject.Parse(contentProperties, JOptions.Node, JOptions.Document));
}

public async override Task<ActivityExecutionResult> ExecuteAsync(WorkflowExecutionContext workflowContext, ActivityContext activityContext)
var result = await ContentManager.UpdateValidateAndCreateAsync(contentItem, VersionOptions.Draft);

if (result.Succeeded)
{
if (InlineEvent.IsStart && InlineEvent.ContentType == ContentType)
if (Publish)
{
if (InlineEvent.Name == nameof(ContentUpdatedEvent))
{
throw new InvalidOperationException($"The '{nameof(CreateContentTask)}' can't update the content item as it is executed inline from a starting '{nameof(ContentUpdatedEvent)}' of the same content type, which would result in an infinitive loop.");
}

if (InlineEvent.Name == nameof(ContentCreatedEvent))
{
throw new InvalidOperationException($"The '{nameof(CreateContentTask)}' can't create the content item as it is executed inline from a starting '{nameof(ContentCreatedEvent)}' of the same content type, which would result in an infinitive loop.");
}

if (Publish && InlineEvent.Name == nameof(ContentPublishedEvent))
{
throw new InvalidOperationException($"The '{nameof(CreateContentTask)}' can't publish the content item as it is executed inline from a starting '{nameof(ContentPublishedEvent)}' of the same content type, which would result in an infinitive loop.");
}

if (!Publish && InlineEvent.Name == nameof(ContentDraftSavedEvent))
{
throw new InvalidOperationException($"The '{nameof(CreateContentTask)}' can't create the content item as it is executed inline from a starting '{nameof(ContentDraftSavedEvent)}' of the same content type, which would result in an infinitive loop.");
}
await ContentManager.PublishAsync(contentItem);
}

var contentItem = await ContentManager.NewAsync(ContentType);

if (!string.IsNullOrWhiteSpace(ContentProperties.Expression))
else
{
var contentProperties = await _expressionEvaluator.EvaluateAsync(ContentProperties, workflowContext, _javaScriptEncoder);
contentItem.Merge(JObject.Parse(contentProperties));
await ContentManager.SaveDraftAsync(contentItem);
}

var result = await ContentManager.UpdateValidateAndCreateAsync(contentItem, VersionOptions.Draft);

if (result.Succeeded)
if (string.IsNullOrEmpty(workflowContext.CorrelationId))
{
if (Publish)
{
await ContentManager.PublishAsync(contentItem);
}
else
{
await ContentManager.SaveDraftAsync(contentItem);
}

if (string.IsNullOrEmpty(workflowContext.CorrelationId))
{
workflowContext.CorrelationId = contentItem.ContentItemId;
}

workflowContext.Properties[ContentEventConstants.ContentItemInputKey] = contentItem;
workflowContext.LastResult = contentItem;

return Outcomes("Done");
workflowContext.CorrelationId = contentItem.ContentItemId;
}

workflowContext.LastResult = result;
workflowContext.Properties[ContentEventConstants.ContentItemInputKey] = contentItem;
workflowContext.LastResult = contentItem;

return Outcomes("Failed");
return Outcomes("Done");
}

workflowContext.LastResult = result;

return Outcomes("Failed");
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Threading.Tasks;

Expand All @@ -12,7 +13,7 @@ public Task ProcessDeploymentStepAsync(DeploymentStep deploymentStep, Deployment
return Task.CompletedTask;
}

result.Steps.Add(JObject.Parse(jsonRecipeStep.Json));
result.Steps.Add(JObject.Parse(jsonRecipeStep.Json, JOptions.Node, JOptions.Document));

return Task.CompletedTask;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Threading.Tasks;
using Microsoft.Extensions.Localization;
Expand Down Expand Up @@ -63,7 +64,7 @@ public override async Task<IDisplayResult> UpdateAsync(JsonRecipeDeploymentStep

try
{
var jObject = JObject.Parse(model.Json);
var jObject = JObject.Parse(model.Json, JOptions.Node, JOptions.Document);
if (!jObject.ContainsKey("name"))
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public override async Task<IDisplayResult> UpdateAsync(ContentTypePartDefinition
}
else
{
var jsonSettings = JObject.Parse(model.Options);
var jsonSettings = JObject.Parse(model.Options, JOptions.Node, JOptions.Document);
jsonSettings["language"] = "html";
var settings = new HtmlBodyPartMonacoEditorSettings
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public async Task BuildAsync(ISchema schema)

try
{
var querySchema = JObject.Parse(query.Schema);
var querySchema = JObject.Parse(query.Schema, JOptions.Node, JOptions.Document);
if (!querySchema.ContainsKey("type"))
{
_logger.LogError("The Query '{Name}' schema is invalid, the 'type' property was not found.", name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public async Task BuildAsync(ISchema schema)

try
{
var querySchema = JObject.Parse(query.Schema);
var querySchema = JObject.Parse(query.Schema, JOptions.Node, JOptions.Document);
if (!querySchema.ContainsKey("type"))
{
_logger.LogError("The Query '{Name}' schema is invalid, the 'type' property was not found.", query.Name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ ShellSettings shellSettings
File.WriteAllText(_indexSettingsFilename, new JsonObject().ToJsonString(JOptions.Indented));
}

_content = JObject.Parse(File.ReadAllText(_indexSettingsFilename));
_content = JObject.Parse(File.ReadAllText(_indexSettingsFilename), JOptions.Node, JOptions.Document);
}

public long GetLastTaskId(string indexName)
Expand Down

0 comments on commit c281e99

Please sign in to comment.