Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/Squidex/squidex
- Loading branch information
Showing
105 changed files
with
1,361 additions
and
883 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
backend/src/Squidex.Domain.Apps.Core.Operations/ConvertContent/UpdateValues.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// ========================================================================== | ||
// Squidex Headless CMS | ||
// ========================================================================== | ||
// Copyright (c) Squidex UG (haftungsbeschraenkt) | ||
// All rights reserved. Licensed under the MIT license. | ||
// ========================================================================== | ||
|
||
using Squidex.Domain.Apps.Core.Contents; | ||
using Squidex.Domain.Apps.Core.Schemas; | ||
using Squidex.Domain.Apps.Core.Scripting; | ||
using Squidex.Infrastructure.Json.Objects; | ||
|
||
namespace Squidex.Domain.Apps.Core.ConvertContent; | ||
|
||
public sealed class UpdateValues : IContentValueConverter | ||
{ | ||
private readonly ContentData existingData; | ||
private readonly IScriptEngine scriptEngine; | ||
private ScriptVars? vars; | ||
|
||
public UpdateValues(ContentData existingData, IScriptEngine scriptEngine) | ||
{ | ||
this.existingData = existingData; | ||
this.scriptEngine = scriptEngine; | ||
} | ||
|
||
public (bool Remove, JsonValue) ConvertValue(IField field, JsonValue source, IField? parent) | ||
{ | ||
if (source.Value is not JsonObject jsonObject) | ||
{ | ||
return (false, source); | ||
} | ||
|
||
if (jsonObject.TryGetValue("$unset", out var value1) && !Equals(value1.Value, false)) | ||
{ | ||
return (true, source); | ||
} | ||
|
||
if (!jsonObject.TryGetValue("$update", out var value2) || value2.Value is not string update) | ||
{ | ||
return (false, source); | ||
} | ||
|
||
var options = new ScriptOptions { Readonly = true }; | ||
|
||
vars ??= new ScriptVars | ||
{ | ||
["$data"] = existingData, | ||
["$self"] = jsonObject | ||
}; | ||
|
||
var result = scriptEngine.Execute(vars, update, options); | ||
|
||
return (false, result); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.