mirror of https://github.com/Squidex/squidex.git
Browse Source
* Update dependencies. * Use new cache settings. * Fix tests. * Fix domain object cache.- * Test subscriptions again. * Disable messaging cache. * Use random name for cluster instances. * Bind settings properly. * Update operation.pull/1084/head
committed by
GitHub
16 changed files with 662 additions and 231 deletions
@ -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); |
|||
} |
|||
} |
|||
@ -1 +1 @@ |
|||
.remirror-theme{width:100%}.remirror-theme{position:relative}.remirror-theme *{box-sizing:border-box}.remirror-theme .ProseMirror p{margin-bottom:1rem!important}.remirror-editor{min-height:300px!important;max-height:500px}.MuiStack-root>.MuiBox-root{margin-right:5px}.MuiBox-root>.MuiButtonBase-root{border-color:#dedfe3!important;border-radius:0}.MuiBox-root>.MuiButtonBase-root{border-left-width:0!important}.MuiBox-root>.MuiBox-root:first-child>.MuiButtonBase-root{border-left-width:1px!important}.MuiStack-root>.MuiBox-root>.MuiButtonBase-root:first-child{border-left-width:1px!important}.MuiButtonBase-root.Mui-selected:hover{background-color:#3284f4!important}.remirror-editor-wrapper{padding-top:0!important}.custom-icon path{fill:#0000008a}.remirror-theme div.ProseMirror{border:1px solid #dedfe3!important;border-radius:0!important;box-shadow:none!important}.MuiTooltip-popper>div{background-color:#1a2129;border-radius:0;font-size:85%;font-weight:400;padding:.5rem}.MuiMenu-paper{transform:none!important}.squidex-editor-disabled{pointer-events:none}.squidex-editor-menu{border:1px solid #dedfe3;border-bottom:0;padding:5px}.squidex-editor-menu fieldset{border-radius:0;border:0;display:flex;outline:0;padding:0}.squidex-editor-menu fieldset:disabled,.squidex-editor-menu fieldset.disabled{pointer-events:none}.squidex-editor-menu fieldset:disabled,.squidex-editor-menu fieldset.disabled{opacity:.5}.squidex-editor-counter{border:1px solid #dedfe3;border-top:0;font-size:85%;font-weight:400;opacity:.8;padding:4px 10px 4px 4px;text-align:right}.squidex-editor-image-view{border:1px solid #dedfe3;border-radius:0;display:inline-block;margin-top:15px;margin-bottom:15px;overflow:hidden}.squidex-editor-image-buttons{bottom:10px;left:10px;position:absolute}.squidex-editor-image-element{display:block;max-width:400px;max-height:400px}.squidex-editor-image-info{left:10px;top:10px;position:absolute;background-color:#3284f4;color:#fff;font-size:85%;font-weight:400;padding:2px 6px}.squidex-editor-main{position:relative}.squidex-editor-main .ace_editor{bottom:0;left:0;right:0;top:0;position:absolute;border:1px solid #dedfe3}.squidex-editor-content-link{align-items:center;border-radius:2px;border:1px solid #dedfe3;padding:10px;display:flex;flex-direction:row;flex-wrap:nowrap;margin-top:10px;margin-bottom:10px}.squidex-editor-content-schema{display:block;overflow-x:hidden;overflow-y:hidden;text-overflow:ellipsis;white-space:nowrap;max-width:100%;min-width:0;width:auto;border-right:1px solid #c2c4cc;color:#8b8f9d;flex-shrink:0;padding-left:10px;padding-right:10px;width:200px}.squidex-editor-content-name{display:block;overflow-x:hidden;overflow-y:hidden;text-overflow:ellipsis;white-space:nowrap;max-width:100%;min-width:0;width:auto;padding-left:10px;padding-right:0}.squidex-editor-html{margin-bottom:10px;margin-top:10px;position:relative}.squidex-editor-html-label{left:6px;top:0;position:absolute;color:#8b8f9d;font-size:85%;font-weight:400}.squidex-editor-html textarea{font-family:monospace;padding:30px 20px 20px}.squidex-editor-button{align-items:center;background-color:#fff;border-radius:0;border:1px solid #dedfe3;bottom:10px;display:inline-flex;font-size:85%;font-weight:400;margin-right:5px;padding:6px 12px}.squidex-editor-button:hover{background-color:#f5f5f5}.squidex-editor-input{border:1px solid #dedfe3;border-radius:0;box-sizing:border-box;height:30px;margin-left:0;margin-right:5px;outline:none;padding:6px 12px}.squidex-editor-input:active{border-color:#3284f4}.squidex-editor-floating{border:1px solid #dedfe3}.squidex-editor-floating .MuiBox-root{margin-right:0!important}.squidex-editor-floating .MuiButtonBase-root{height:30px}.squidex-editor-modal-wrapper,.squidex-editor-modal-backdrop{bottom:0;left:0;right:0;top:0;position:absolute}.squidex-editor-modal-backdrop{background-color:#00000003}.squidex-editor-modal-window{left:50%;top:50%;background-color:#fff;border:0;border-radius:.25rem;box-sizing:border-box;box-shadow:0 3px 16px #0003;margin-top:-50px;margin-left:-150px;position:absolute;width:350px}.squidex-editor-modal-body{display:flex;flex-direction:row;flex-grow:1;padding-top:0!important}.squidex-editor-modal-body,.squidex-editor-modal-title{padding:15px}.squidex-editor-modal-title{font-size:85%}.squidex-editor-modal-window input{flex-grow:1}.b:before{content:"<a>";font-family:monospace;font-size:90%}.b:after{content:"</a>";font-family:monospace;font-size:90%} |
|||
.remirror-theme{width:100%}.remirror-theme{position:relative}.remirror-theme *{box-sizing:border-box}.remirror-theme .ProseMirror p{margin-bottom:1rem!important}.remirror-editor{min-height:300px!important;max-height:500px}.MuiStack-root>.MuiBox-root{margin-right:5px}.MuiBox-root>.MuiButtonBase-root{border-color:#dedfe3!important;border-radius:0}.MuiBox-root>.MuiButtonBase-root{border-left-width:0!important}.MuiBox-root>.MuiBox-root:first-child>.MuiButtonBase-root{border-left-width:1px!important}.MuiStack-root>.MuiBox-root>.MuiButtonBase-root:first-child{border-left-width:1px!important}.MuiButtonBase-root.Mui-selected:hover{background-color:#3284f4!important}.remirror-editor-wrapper{padding-top:0!important}.custom-icon path{fill:#0000008a}.remirror-theme div.ProseMirror{border:1px solid #dedfe3!important;border-radius:0!important;box-shadow:none!important}.MuiTooltip-popper>div{background-color:#1a2129;border-radius:0;font-size:85%;font-weight:400;padding:.5rem}.MuiMenu-paper{transform:none!important}.squidex-editor-disabled{pointer-events:none}.squidex-editor-menu{border:1px solid #dedfe3;border-bottom:0;padding:5px}.squidex-editor-menu fieldset{border-radius:0;border:0;display:flex;outline:0;padding:0}.squidex-editor-menu fieldset:disabled,.squidex-editor-menu fieldset.disabled{pointer-events:none}.squidex-editor-menu fieldset:disabled,.squidex-editor-menu fieldset.disabled{opacity:.5}.squidex-editor-counter{border:1px solid #dedfe3;border-top:0;font-size:85%;font-weight:400;opacity:.8;padding:4px 10px 4px 4px;text-align:right}.squidex-editor-image-view{border:1px solid #dedfe3;border-radius:0;display:inline-block;margin-top:15px;margin-bottom:15px;overflow:hidden}.squidex-editor-image-buttons{bottom:10px;left:10px;position:absolute}.squidex-editor-image-element{display:block;max-width:400px;max-height:400px}.squidex-editor-image-info{left:10px;top:10px;position:absolute;background-color:#3284f4;color:#fff;font-size:85%;font-weight:400;padding:2px 6px}.squidex-editor-main{position:relative}.squidex-editor-main .ace_editor{bottom:0;left:0;right:0;top:0;position:absolute;border:1px solid #dedfe3}.squidex-editor-content-link{align-items:center;border-radius:2px;border:1px solid #dedfe3;padding:10px;display:flex;flex-direction:row;flex-wrap:nowrap;margin-top:10px;margin-bottom:10px}.squidex-editor-content-schema{display:block;overflow-x:hidden;overflow-y:hidden;text-overflow:ellipsis;white-space:nowrap;max-width:100%;min-width:0;width:auto;border-right:1px solid #c2c4cc;color:#8b8f9d;flex-shrink:0;padding-left:10px;padding-right:10px;width:200px}.squidex-editor-content-name{display:block;overflow-x:hidden;overflow-y:hidden;text-overflow:ellipsis;white-space:nowrap;max-width:100%;min-width:0;width:auto;padding-left:10px;padding-right:0}.squidex-editor-html{margin-bottom:10px;margin-top:10px;position:relative}.squidex-editor-html-label{left:6px;top:0;position:absolute;color:#8b8f9d;font-size:85%;font-weight:400}.squidex-editor-html textarea{border:1px solid #dedfe3;font-family:monospace;font-size:inherit;height:100px;outline:none;overflow-x:hidden;overflow-y:auto;padding:30px 14px 14px;resize:vertical;width:100%}.squidex-editor-button{align-items:center;background-color:#fff;border-radius:0;border:1px solid #dedfe3;bottom:10px;display:inline-flex;font-size:85%;font-weight:400;margin-right:5px;padding:6px 12px}.squidex-editor-button:hover{background-color:#f5f5f5}.squidex-editor-input{border:1px solid #dedfe3;border-radius:0;box-sizing:border-box;height:30px;margin-left:0;margin-right:5px;outline:none;padding:6px 12px}.squidex-editor-input:active{border-color:#3284f4}.squidex-editor-floating{border:1px solid #dedfe3}.squidex-editor-floating .MuiBox-root{margin-right:0!important}.squidex-editor-floating .MuiButtonBase-root{height:30px}.squidex-editor-modal-wrapper,.squidex-editor-modal-backdrop{bottom:0;left:0;right:0;top:0;position:absolute}.squidex-editor-modal-backdrop{background-color:#00000003}.squidex-editor-modal-window{left:50%;top:50%;background-color:#fff;border:0;border-radius:.25rem;box-sizing:border-box;box-shadow:0 3px 16px #0003;margin-top:-50px;margin-left:-150px;position:absolute;width:350px}.squidex-editor-modal-body{display:flex;flex-direction:row;flex-grow:1;padding-top:0!important}.squidex-editor-modal-body,.squidex-editor-modal-title{padding:15px}.squidex-editor-modal-title{font-size:85%}.squidex-editor-modal-window input{flex-grow:1}.b:before{content:"<a>";font-family:monospace;font-size:90%}.b:after{content:"</a>";font-family:monospace;font-size:90%} |
|||
|
|||
File diff suppressed because one or more lines are too long
@ -0,0 +1,142 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using Microsoft.Extensions.Caching.Memory; |
|||
using Microsoft.Extensions.Options; |
|||
using Squidex.Domain.Apps.Core.Contents; |
|||
using Squidex.Domain.Apps.Core.ConvertContent; |
|||
using Squidex.Domain.Apps.Core.Schemas; |
|||
using Squidex.Domain.Apps.Core.Scripting; |
|||
using Squidex.Infrastructure.Json.Objects; |
|||
|
|||
namespace Squidex.Domain.Apps.Core.Operations.ConvertContent; |
|||
|
|||
public class UpdateConverterTests |
|||
{ |
|||
private readonly IScriptEngine scriptEngine; |
|||
|
|||
public UpdateConverterTests() |
|||
{ |
|||
scriptEngine = new JintScriptEngine(new MemoryCache(Options.Create(new MemoryCacheOptions())), |
|||
Options.Create(new JintScriptOptions |
|||
{ |
|||
TimeoutScript = TimeSpan.FromSeconds(2), |
|||
TimeoutExecution = TimeSpan.FromSeconds(10) |
|||
})); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Should_update() |
|||
{ |
|||
var field1 = Fields.Number(1, "number1", Partitioning.Invariant); |
|||
|
|||
var schema = |
|||
new Schema { Name = "my-schema" } |
|||
.AddField(field1); |
|||
|
|||
var source = |
|||
new ContentData() |
|||
.AddField(field1.Name, |
|||
new ContentFieldData() |
|||
.AddLocalized("en", |
|||
JsonValue.Object() |
|||
.Add("$update", "$data.number1.en + 1"))); |
|||
|
|||
var existing = |
|||
new ContentData() |
|||
.AddField(field1.Name, |
|||
new ContentFieldData() |
|||
.AddLocalized("en", 42)); |
|||
|
|||
var actual = |
|||
new ContentConverter(ResolvedComponents.Empty, schema) |
|||
.Add(new UpdateValues(existing, scriptEngine)) |
|||
.Convert(source); |
|||
|
|||
var expected = |
|||
new ContentData() |
|||
.AddField(field1.Name, |
|||
new ContentFieldData() |
|||
.AddLocalized("en", 43)); |
|||
|
|||
Assert.Equal(expected, actual); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Should_update_with_existing_value() |
|||
{ |
|||
var field1 = Fields.Number(1, "number1", Partitioning.Invariant); |
|||
|
|||
var schema = |
|||
new Schema { Name = "my-schema" } |
|||
.AddField(field1); |
|||
|
|||
var source = |
|||
new ContentData() |
|||
.AddField(field1.Name, |
|||
new ContentFieldData() |
|||
.AddLocalized("en", |
|||
JsonValue.Object() |
|||
.Add("$update", "$data.number1.en + $self.increment") |
|||
.Add("increment", 7))); |
|||
|
|||
var existing = |
|||
new ContentData() |
|||
.AddField(field1.Name, |
|||
new ContentFieldData() |
|||
.AddLocalized("en", 42)); |
|||
|
|||
var actual = |
|||
new ContentConverter(ResolvedComponents.Empty, schema) |
|||
.Add(new UpdateValues(existing, scriptEngine)) |
|||
.Convert(source); |
|||
|
|||
var expected = |
|||
new ContentData() |
|||
.AddField(field1.Name, |
|||
new ContentFieldData() |
|||
.AddLocalized("en", 49)); |
|||
|
|||
Assert.Equal(expected, actual); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Should_unset_value() |
|||
{ |
|||
var field1 = Fields.Number(1, "number1", Partitioning.Invariant); |
|||
|
|||
var schema = |
|||
new Schema { Name = "my-schema" } |
|||
.AddField(field1); |
|||
|
|||
var source = |
|||
new ContentData() |
|||
.AddField(field1.Name, |
|||
new ContentFieldData() |
|||
.AddLocalized("en", |
|||
JsonValue.Object() |
|||
.Add("$unset", true))); |
|||
|
|||
var existing = |
|||
new ContentData() |
|||
.AddField(field1.Name, |
|||
new ContentFieldData() |
|||
.AddLocalized("en", 42)); |
|||
|
|||
var actual = |
|||
new ContentConverter(ResolvedComponents.Empty, schema) |
|||
.Add(new UpdateValues(existing, scriptEngine)) |
|||
.Convert(source); |
|||
|
|||
var expected = |
|||
new ContentData() |
|||
.AddField(field1.Name, |
|||
new ContentFieldData()); |
|||
|
|||
Assert.Equal(expected, actual); |
|||
} |
|||
} |
|||
@ -0,0 +1,53 @@ |
|||
{ |
|||
sut: { |
|||
UniqueId: Guid_1--Guid_2, |
|||
Snapshot: { |
|||
SchemaId: Guid_3,my-schema, |
|||
CurrentVersion: { |
|||
Status: Draft, |
|||
Data: { |
|||
my-field1: { |
|||
iv: 43.0 |
|||
} |
|||
} |
|||
}, |
|||
EditingData: { |
|||
my-field1: { |
|||
iv: 43.0 |
|||
} |
|||
}, |
|||
EditingStatus: Draft, |
|||
IsPublished: false, |
|||
AppId: Guid_1,my-app, |
|||
IsDeleted: false, |
|||
UniqueId: Guid_1--Guid_2, |
|||
Id: Guid_2, |
|||
CreatedBy: subject:me, |
|||
LastModifiedBy: subject:me, |
|||
Version: 1 |
|||
}, |
|||
Version: 1, |
|||
ObjectState: Created |
|||
}, |
|||
events: [ |
|||
{ |
|||
Headers: { |
|||
AggregateId: Guid_1--Guid_2, |
|||
EventId: Guid_4 |
|||
}, |
|||
Payload: { |
|||
Data: { |
|||
my-field1: { |
|||
iv: 43.0 |
|||
} |
|||
}, |
|||
NewVersion: false, |
|||
ContentId: Guid_2, |
|||
SchemaId: Guid_3,my-schema, |
|||
AppId: Guid_1,my-app, |
|||
Actor: subject:me, |
|||
FromRule: false |
|||
} |
|||
} |
|||
] |
|||
} |
|||
@ -0,0 +1,53 @@ |
|||
{ |
|||
sut: { |
|||
UniqueId: Guid_1--Guid_2, |
|||
Snapshot: { |
|||
SchemaId: Guid_3,my-schema, |
|||
CurrentVersion: { |
|||
Status: Draft, |
|||
Data: { |
|||
my-field1: { |
|||
iv: 43.0 |
|||
} |
|||
} |
|||
}, |
|||
EditingData: { |
|||
my-field1: { |
|||
iv: 43.0 |
|||
} |
|||
}, |
|||
EditingStatus: Draft, |
|||
IsPublished: false, |
|||
AppId: Guid_1,my-app, |
|||
IsDeleted: false, |
|||
UniqueId: Guid_1--Guid_2, |
|||
Id: Guid_2, |
|||
CreatedBy: subject:me, |
|||
LastModifiedBy: subject:me, |
|||
Version: 1 |
|||
}, |
|||
Version: 1, |
|||
ObjectState: Created |
|||
}, |
|||
events: [ |
|||
{ |
|||
Headers: { |
|||
AggregateId: Guid_1--Guid_2, |
|||
EventId: Guid_4 |
|||
}, |
|||
Payload: { |
|||
Data: { |
|||
my-field1: { |
|||
iv: 43.0 |
|||
} |
|||
}, |
|||
NewVersion: false, |
|||
ContentId: Guid_2, |
|||
SchemaId: Guid_3,my-schema, |
|||
AppId: Guid_1,my-app, |
|||
Actor: subject:me, |
|||
FromRule: false |
|||
} |
|||
} |
|||
] |
|||
} |
|||
Loading…
Reference in new issue