From 7105aa4b646713c342a13f38cd32b31cb0e9d5a6 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Tue, 3 Nov 2020 23:17:17 +0100 Subject: [PATCH 1/2] Fix asset context issue. --- .../Controllers/Assets/AssetContentController.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/backend/src/Squidex/Areas/Api/Controllers/Assets/AssetContentController.cs b/backend/src/Squidex/Areas/Api/Controllers/Assets/AssetContentController.cs index 879e42ee1..213a8bfd0 100644 --- a/backend/src/Squidex/Areas/Api/Controllers/Assets/AssetContentController.cs +++ b/backend/src/Squidex/Areas/Api/Controllers/Assets/AssetContentController.cs @@ -80,7 +80,12 @@ namespace Squidex.Areas.Api.Controllers.Assets asset = await assetRepository.FindAssetBySlugAsync(AppId, idOrSlug); } - return await DeliverAssetAsync(asset, queries); + if (asset != null && queries.Version > EtagVersion.Any && asset.Version != queries.Version) + { + asset = await assetLoader.GetAsync(App.Id, asset.Id, queries.Version); + } + + return DeliverAsset(asset, queries); } /// @@ -103,10 +108,10 @@ namespace Squidex.Areas.Api.Controllers.Assets { var asset = await assetRepository.FindAssetAsync(id); - return await DeliverAssetAsync(asset, queries); + return DeliverAsset(asset, queries); } - private async Task DeliverAssetAsync(IAssetEntity? asset, AssetContentQueryDto queries) + private IActionResult DeliverAsset(IAssetEntity? asset, AssetContentQueryDto queries) { queries ??= new AssetContentQueryDto(); @@ -122,11 +127,6 @@ namespace Squidex.Areas.Api.Controllers.Assets return StatusCode(403); } - if (queries.Version > EtagVersion.Any && asset.Version != queries.Version) - { - asset = await assetLoader.GetAsync(App.Id, asset.Id, queries.Version); - } - var resizeOptions = queries.ToResizeOptions(asset); FileCallback callback; From 36a4401019b069f66dfaa551ce6fe858246a4748 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Tue, 3 Nov 2020 23:43:23 +0100 Subject: [PATCH 2/2] Ignore calculated members during serialization. --- .../Apps/Commands/AppCommand.cs | 2 ++ .../Apps/Commands/AppUpdateCommand.cs | 2 ++ .../Squidex.Domain.Apps.Entities/Apps/Commands/CreateApp.cs | 2 ++ .../src/Squidex.Domain.Apps.Entities/Apps/State/AppState.cs | 2 ++ .../Assets/Commands/AssetCommand.cs | 2 ++ .../Assets/Commands/AssetFolderCommand.cs | 2 ++ .../Assets/State/AssetFolderState.cs | 2 ++ .../Squidex.Domain.Apps.Entities/Assets/State/AssetState.cs | 3 +++ .../Contents/Commands/ContentCommand.cs | 2 ++ .../Contents/State/ContentState.cs | 6 ++++++ .../Squidex.Domain.Apps.Entities/Rules/State/RuleState.cs | 3 +++ .../Schemas/Commands/CreateSchema.cs | 2 ++ .../Schemas/Commands/SchemaUpdateCommand.cs | 2 ++ .../Schemas/State/SchemaState.cs | 2 ++ 14 files changed, 34 insertions(+) diff --git a/backend/src/Squidex.Domain.Apps.Entities/Apps/Commands/AppCommand.cs b/backend/src/Squidex.Domain.Apps.Entities/Apps/Commands/AppCommand.cs index 09d401854..78613817a 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Apps/Commands/AppCommand.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Apps/Commands/AppCommand.cs @@ -5,6 +5,7 @@ // All rights reserved. Licensed under the MIT license. // ========================================================================== +using System.Runtime.Serialization; using Squidex.Infrastructure; using Squidex.Infrastructure.Commands; @@ -12,6 +13,7 @@ namespace Squidex.Domain.Apps.Entities.Apps.Commands { public abstract class AppCommand : SquidexCommand, IAggregateCommand { + [IgnoreDataMember] public abstract DomainId AggregateId { get; } } } diff --git a/backend/src/Squidex.Domain.Apps.Entities/Apps/Commands/AppUpdateCommand.cs b/backend/src/Squidex.Domain.Apps.Entities/Apps/Commands/AppUpdateCommand.cs index 24b0a6b32..f7f9705f7 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Apps/Commands/AppUpdateCommand.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Apps/Commands/AppUpdateCommand.cs @@ -5,6 +5,7 @@ // All rights reserved. Licensed under the MIT license. // ========================================================================== +using System.Runtime.Serialization; using Squidex.Infrastructure; namespace Squidex.Domain.Apps.Entities.Apps.Commands @@ -13,6 +14,7 @@ namespace Squidex.Domain.Apps.Entities.Apps.Commands { public NamedId AppId { get; set; } + [IgnoreDataMember] public override DomainId AggregateId { get { return AppId.Id; } diff --git a/backend/src/Squidex.Domain.Apps.Entities/Apps/Commands/CreateApp.cs b/backend/src/Squidex.Domain.Apps.Entities/Apps/Commands/CreateApp.cs index 0e6a404ad..dc303a240 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Apps/Commands/CreateApp.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Apps/Commands/CreateApp.cs @@ -5,6 +5,7 @@ // All rights reserved. Licensed under the MIT license. // ========================================================================== +using System.Runtime.Serialization; using Squidex.Infrastructure; using Squidex.Infrastructure.Commands; @@ -18,6 +19,7 @@ namespace Squidex.Domain.Apps.Entities.Apps.Commands public string? Template { get; set; } + [IgnoreDataMember] public override DomainId AggregateId { get { return AppId; } diff --git a/backend/src/Squidex.Domain.Apps.Entities/Apps/State/AppState.cs b/backend/src/Squidex.Domain.Apps.Entities/Apps/State/AppState.cs index f7869d4cf..a86e6bce7 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Apps/State/AppState.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Apps/State/AppState.cs @@ -6,6 +6,7 @@ // ========================================================================== using System; +using System.Runtime.Serialization; using Squidex.Domain.Apps.Core.Apps; using Squidex.Domain.Apps.Core.Contents; using Squidex.Domain.Apps.Events.Apps; @@ -46,6 +47,7 @@ namespace Squidex.Domain.Apps.Entities.Apps.State public bool IsArchived { get; set; } + [IgnoreDataMember] public DomainId UniqueId { get { return Id; } diff --git a/backend/src/Squidex.Domain.Apps.Entities/Assets/Commands/AssetCommand.cs b/backend/src/Squidex.Domain.Apps.Entities/Assets/Commands/AssetCommand.cs index 528c7f854..f51b114d0 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Assets/Commands/AssetCommand.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Assets/Commands/AssetCommand.cs @@ -5,6 +5,7 @@ // All rights reserved. Licensed under the MIT license. // ========================================================================== +using System.Runtime.Serialization; using Squidex.Infrastructure; using Squidex.Infrastructure.Commands; @@ -16,6 +17,7 @@ namespace Squidex.Domain.Apps.Entities.Assets.Commands public DomainId AssetId { get; set; } + [IgnoreDataMember] public DomainId AggregateId { get { return DomainId.Combine(AppId, AssetId); } diff --git a/backend/src/Squidex.Domain.Apps.Entities/Assets/Commands/AssetFolderCommand.cs b/backend/src/Squidex.Domain.Apps.Entities/Assets/Commands/AssetFolderCommand.cs index 305c68547..883edfc1c 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Assets/Commands/AssetFolderCommand.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Assets/Commands/AssetFolderCommand.cs @@ -5,6 +5,7 @@ // All rights reserved. Licensed under the MIT license. // ========================================================================== +using System.Runtime.Serialization; using Squidex.Infrastructure; using Squidex.Infrastructure.Commands; @@ -16,6 +17,7 @@ namespace Squidex.Domain.Apps.Entities.Assets.Commands public DomainId AssetFolderId { get; set; } + [IgnoreDataMember] public DomainId AggregateId { get { return DomainId.Combine(AppId, AssetFolderId); } diff --git a/backend/src/Squidex.Domain.Apps.Entities/Assets/State/AssetFolderState.cs b/backend/src/Squidex.Domain.Apps.Entities/Assets/State/AssetFolderState.cs index b3eb77306..239b2e360 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Assets/State/AssetFolderState.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Assets/State/AssetFolderState.cs @@ -5,6 +5,7 @@ // All rights reserved. Licensed under the MIT license. // ========================================================================== +using System.Runtime.Serialization; using Squidex.Domain.Apps.Events.Assets; using Squidex.Infrastructure; using Squidex.Infrastructure.Commands; @@ -23,6 +24,7 @@ namespace Squidex.Domain.Apps.Entities.Assets.State public DomainId ParentId { get; set; } + [IgnoreDataMember] public DomainId UniqueId { get { return DomainId.Combine(AppId, Id); } diff --git a/backend/src/Squidex.Domain.Apps.Entities/Assets/State/AssetState.cs b/backend/src/Squidex.Domain.Apps.Entities/Assets/State/AssetState.cs index 5fff9a467..3996576ca 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Assets/State/AssetState.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Assets/State/AssetState.cs @@ -6,6 +6,7 @@ // ========================================================================== using System.Collections.Generic; +using System.Runtime.Serialization; using Squidex.Domain.Apps.Core.Assets; using Squidex.Domain.Apps.Events.Assets; using Squidex.Infrastructure; @@ -45,11 +46,13 @@ namespace Squidex.Domain.Apps.Entities.Assets.State public AssetType Type { get; set; } + [IgnoreDataMember] public DomainId AssetId { get { return Id; } } + [IgnoreDataMember] public DomainId UniqueId { get { return DomainId.Combine(AppId, Id); } diff --git a/backend/src/Squidex.Domain.Apps.Entities/Contents/Commands/ContentCommand.cs b/backend/src/Squidex.Domain.Apps.Entities/Contents/Commands/ContentCommand.cs index f9176103e..9dde313e5 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Contents/Commands/ContentCommand.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Contents/Commands/ContentCommand.cs @@ -5,6 +5,7 @@ // All rights reserved. Licensed under the MIT license. // ========================================================================== +using System.Runtime.Serialization; using Squidex.Infrastructure; using Squidex.Infrastructure.Commands; @@ -20,6 +21,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.Commands public bool DoNotScript { get; set; } + [IgnoreDataMember] public DomainId AggregateId { get { return DomainId.Combine(AppId, ContentId); } diff --git a/backend/src/Squidex.Domain.Apps.Entities/Contents/State/ContentState.cs b/backend/src/Squidex.Domain.Apps.Entities/Contents/State/ContentState.cs index 09049adfd..8f7a3bad1 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Contents/State/ContentState.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Contents/State/ContentState.cs @@ -5,6 +5,7 @@ // All rights reserved. Licensed under the MIT license. // ========================================================================== +using System.Runtime.Serialization; using Squidex.Domain.Apps.Core.Contents; using Squidex.Domain.Apps.Events.Contents; using Squidex.Infrastructure; @@ -27,26 +28,31 @@ namespace Squidex.Domain.Apps.Entities.Contents.State public ScheduleJob? ScheduleJob { get; set; } + [IgnoreDataMember] public DomainId UniqueId { get { return DomainId.Combine(AppId, Id); } } + [IgnoreDataMember] public NamedContentData Data { get { return NewVersion?.Data ?? CurrentVersion.Data; } } + [IgnoreDataMember] public Status EditingStatus { get { return NewStatus ?? Status; } } + [IgnoreDataMember] public Status Status { get { return CurrentVersion.Status; } } + [IgnoreDataMember] public Status? NewStatus { get { return NewVersion?.Status; } diff --git a/backend/src/Squidex.Domain.Apps.Entities/Rules/State/RuleState.cs b/backend/src/Squidex.Domain.Apps.Entities/Rules/State/RuleState.cs index 232f80c3b..e5d83423c 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Rules/State/RuleState.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Rules/State/RuleState.cs @@ -5,6 +5,8 @@ // All rights reserved. Licensed under the MIT license. // ========================================================================== +using System; +using System.Runtime.Serialization; using Squidex.Domain.Apps.Core.Rules; using Squidex.Domain.Apps.Events.Rules; using Squidex.Infrastructure; @@ -22,6 +24,7 @@ namespace Squidex.Domain.Apps.Entities.Rules.State public Rule RuleDef { get; set; } + [IgnoreDataMember] public DomainId UniqueId { get { return DomainId.Combine(AppId, Id); } diff --git a/backend/src/Squidex.Domain.Apps.Entities/Schemas/Commands/CreateSchema.cs b/backend/src/Squidex.Domain.Apps.Entities/Schemas/Commands/CreateSchema.cs index 1a8a0ba94..ae785eb2f 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Schemas/Commands/CreateSchema.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Schemas/Commands/CreateSchema.cs @@ -6,6 +6,7 @@ // ========================================================================== using System.Collections.Generic; +using System.Runtime.Serialization; using Squidex.Domain.Apps.Core.Schemas; using Squidex.Infrastructure; using Squidex.Infrastructure.Commands; @@ -39,6 +40,7 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Commands public Dictionary? PreviewUrls { get; set; } + [IgnoreDataMember] public override DomainId AggregateId { get { return DomainId.Combine(AppId, SchemaId); } diff --git a/backend/src/Squidex.Domain.Apps.Entities/Schemas/Commands/SchemaUpdateCommand.cs b/backend/src/Squidex.Domain.Apps.Entities/Schemas/Commands/SchemaUpdateCommand.cs index cbd6a5ed6..fbbc82eb8 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Schemas/Commands/SchemaUpdateCommand.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Schemas/Commands/SchemaUpdateCommand.cs @@ -5,6 +5,7 @@ // All rights reserved. Licensed under the MIT license. // ========================================================================== +using System.Runtime.Serialization; using Squidex.Infrastructure; namespace Squidex.Domain.Apps.Entities.Schemas.Commands @@ -13,6 +14,7 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Commands { public NamedId SchemaId { get; set; } + [IgnoreDataMember] public override DomainId AggregateId { get { return DomainId.Combine(AppId, SchemaId.Id); } diff --git a/backend/src/Squidex.Domain.Apps.Entities/Schemas/State/SchemaState.cs b/backend/src/Squidex.Domain.Apps.Entities/Schemas/State/SchemaState.cs index 6f6633f20..d67ba0f01 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Schemas/State/SchemaState.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Schemas/State/SchemaState.cs @@ -7,6 +7,7 @@ using System; using System.Linq; +using System.Runtime.Serialization; using Squidex.Domain.Apps.Core; using Squidex.Domain.Apps.Core.Schemas; using Squidex.Domain.Apps.Events.Schemas; @@ -27,6 +28,7 @@ namespace Squidex.Domain.Apps.Entities.Schemas.State public long SchemaFieldsTotal { get; set; } + [IgnoreDataMember] public DomainId UniqueId { get { return DomainId.Combine(AppId, Id); }