diff --git a/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/MongoContentRepository.cs b/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/MongoContentRepository.cs index 69d51774d..1e2065096 100644 --- a/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/MongoContentRepository.cs +++ b/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/MongoContentRepository.cs @@ -130,7 +130,7 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents await Collection.Find(x => x.SchemaIdId == schemaId && ids.Contains(x.Id) && x.IsDeleted == false).Only(x => x.Id) .ToListAsync(); - return ids.Except(contentEntities.Select(x => Guid.Parse(x["id"].AsString))).ToList(); + return ids.Except(contentEntities.Select(x => Guid.Parse(x["_id"].AsString))).ToList(); } public async Task FindContentAsync(IAppEntity app, ISchemaEntity schema, Guid id) diff --git a/src/Squidex.Domain.Users/IUserEvents.cs b/src/Squidex.Domain.Users/IUserEvents.cs index fc1611710..e92dc1a6a 100644 --- a/src/Squidex.Domain.Users/IUserEvents.cs +++ b/src/Squidex.Domain.Users/IUserEvents.cs @@ -12,5 +12,7 @@ namespace Squidex.Domain.Users public interface IUserEvents { void OnUserRegistered(IUser user); + + void OnConsentGiven(IUser user); } } diff --git a/src/Squidex.Domain.Users/NoopUserEvents.cs b/src/Squidex.Domain.Users/NoopUserEvents.cs index 4890f15f5..9fb142938 100644 --- a/src/Squidex.Domain.Users/NoopUserEvents.cs +++ b/src/Squidex.Domain.Users/NoopUserEvents.cs @@ -11,6 +11,10 @@ namespace Squidex.Domain.Users { public sealed class NoopUserEvents : IUserEvents { + public void OnConsentGiven(IUser user) + { + } + public void OnUserRegistered(IUser user) { } diff --git a/src/Squidex.Infrastructure/Orleans/J.cs b/src/Squidex.Infrastructure/Orleans/J.cs index 2f482d67b..da8577355 100644 --- a/src/Squidex.Infrastructure/Orleans/J.cs +++ b/src/Squidex.Infrastructure/Orleans/J.cs @@ -6,15 +6,15 @@ // ========================================================================== using System.Threading.Tasks; -using Newtonsoft.Json; - -#pragma warning disable SA1401 // Fields must be private namespace Squidex.Infrastructure.Orleans { public static class J { - public static JsonSerializer Serializer = new JsonSerializer(); + public static J AsJ(this T value) + { + return new J(value); + } public static J Of(T value) { diff --git a/src/Squidex.Infrastructure/Orleans/JExtensions.cs b/src/Squidex.Infrastructure/Orleans/JExtensions.cs deleted file mode 100644 index 49125b346..000000000 --- a/src/Squidex.Infrastructure/Orleans/JExtensions.cs +++ /dev/null @@ -1,17 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschraenkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -namespace Squidex.Infrastructure.Orleans -{ - public static class JExtensions - { - public static J AsJ(this T value) - { - return new J(value); - } - } -} diff --git a/src/Squidex.Infrastructure/Orleans/J{T}.cs b/src/Squidex.Infrastructure/Orleans/J{T}.cs index f9d9232a8..4dfbef361 100644 --- a/src/Squidex.Infrastructure/Orleans/J{T}.cs +++ b/src/Squidex.Infrastructure/Orleans/J{T}.cs @@ -8,6 +8,7 @@ using System; using System.IO; using System.Threading.Tasks; +using Microsoft.Extensions.DependencyInjection; using Newtonsoft.Json; using Orleans.CodeGeneration; using Orleans.Serialization; @@ -17,6 +18,8 @@ namespace Squidex.Infrastructure.Orleans { public struct J { + private static readonly JsonSerializer DefaultSerializer = JsonSerializer.CreateDefault(); + public T Value { get; } [JsonConstructor] @@ -56,11 +59,13 @@ namespace Squidex.Infrastructure.Orleans { using (Profile.Method(nameof(J))) { + var jsonSerializer = GetSerializer(context); + var stream = new MemoryStream(); using (var writer = new JsonTextWriter(new StreamWriter(stream))) { - J.Serializer.Serialize(writer, input); + jsonSerializer.Serialize(writer, input); writer.Flush(); } @@ -77,6 +82,8 @@ namespace Squidex.Infrastructure.Orleans { using (Profile.Method(nameof(J))) { + var jsonSerializer = GetSerializer(context); + var outLength = context.StreamReader.ReadInt(); var outBytes = context.StreamReader.ReadBytes(outLength); @@ -84,9 +91,21 @@ namespace Squidex.Infrastructure.Orleans using (var reader = new JsonTextReader(new StreamReader(stream))) { - return J.Serializer.Deserialize(reader, expected); + return jsonSerializer.Deserialize(reader, expected); } } } + + private static JsonSerializer GetSerializer(ISerializerContext context) + { + try + { + return context?.ServiceProvider?.GetService() ?? DefaultSerializer; + } + catch + { + return DefaultSerializer; + } + } } } diff --git a/src/Squidex/Areas/IdentityServer/Controllers/Account/AccountController.cs b/src/Squidex/Areas/IdentityServer/Controllers/Account/AccountController.cs index 4ee48c856..9bf58aabf 100644 --- a/src/Squidex/Areas/IdentityServer/Controllers/Account/AccountController.cs +++ b/src/Squidex/Areas/IdentityServer/Controllers/Account/AccountController.cs @@ -123,6 +123,8 @@ namespace Squidex.Areas.IdentityServer.Controllers.Account await userManager.UpdateAsync(user); + userEvents.OnConsentGiven(user); + return RedirectToReturnUrl(returnUrl); } diff --git a/src/Squidex/Config/Domain/SerializationServices.cs b/src/Squidex/Config/Domain/SerializationServices.cs index 45e7ad011..5d96ab126 100644 --- a/src/Squidex/Config/Domain/SerializationServices.cs +++ b/src/Squidex/Config/Domain/SerializationServices.cs @@ -20,7 +20,6 @@ using Squidex.Domain.Apps.Events; using Squidex.Infrastructure; using Squidex.Infrastructure.EventSourcing; using Squidex.Infrastructure.Json; -using Squidex.Infrastructure.MongoDb; namespace Squidex.Config.Domain { @@ -74,16 +73,14 @@ namespace Squidex.Config.Domain ConfigureJson(DefaultJsonSettings, TypeNameHandling.Auto); DefaultJsonSerializer = JsonSerializer.Create(DefaultJsonSettings); - - BsonJsonConvention.Register(DefaultJsonSerializer); } public static IServiceCollection AddMySerializers(this IServiceCollection services) { - services.AddSingletonAs(t => FieldRegistry); - services.AddSingletonAs(t => DefaultJsonSettings); - services.AddSingletonAs(t => DefaultJsonSerializer); - services.AddSingletonAs(t => TypeNameRegistry); + services.AddSingleton(FieldRegistry); + services.AddSingleton(DefaultJsonSettings); + services.AddSingleton(DefaultJsonSerializer); + services.AddSingleton(TypeNameRegistry); return services; } diff --git a/src/Squidex/Config/Domain/StoreServices.cs b/src/Squidex/Config/Domain/StoreServices.cs index 3e6909af1..496ce0989 100644 --- a/src/Squidex/Config/Domain/StoreServices.cs +++ b/src/Squidex/Config/Domain/StoreServices.cs @@ -30,6 +30,7 @@ using Squidex.Domain.Users.MongoDb.Infrastructure; using Squidex.Infrastructure; using Squidex.Infrastructure.EventSourcing; using Squidex.Infrastructure.Migrations; +using Squidex.Infrastructure.MongoDb; using Squidex.Infrastructure.States; using Squidex.Infrastructure.UsageTracking; using Squidex.Shared.Users; @@ -44,6 +45,8 @@ namespace Squidex.Config.Domain { ["MongoDB"] = () => { + BsonJsonConvention.Register(SerializationServices.DefaultJsonSerializer); + var mongoConfiguration = config.GetRequiredValue("store:mongoDb:configuration"); var mongoDatabaseName = config.GetRequiredValue("store:mongoDb:database"); var mongoContentDatabaseName = config.GetOptionalValue("store:mongoDb:contentDatabase", mongoDatabaseName); diff --git a/src/Squidex/Config/Orleans/ClientWrapper.cs b/src/Squidex/Config/Orleans/ClientWrapper.cs index 0dd07f79a..d6e9c35e8 100644 --- a/src/Squidex/Config/Orleans/ClientWrapper.cs +++ b/src/Squidex/Config/Orleans/ClientWrapper.cs @@ -10,6 +10,7 @@ using System.Net; using Orleans; using Orleans.Configuration; using Orleans.Runtime; +using Squidex.Config.Domain; using Squidex.Domain.Apps.Entities; using Squidex.Infrastructure; @@ -31,6 +32,10 @@ namespace Squidex.Config.Orleans { options.ClusterId = "squidex"; }) + .ConfigureServices((context, services) => + { + services.AddMySerializers(); + }) .ConfigureApplicationParts(builder => { builder.AddApplicationPart(SquidexEntities.Assembly); diff --git a/src/Squidex/Config/Orleans/SiloWrapper.cs b/src/Squidex/Config/Orleans/SiloWrapper.cs index 647dab956..96a110c08 100644 --- a/src/Squidex/Config/Orleans/SiloWrapper.cs +++ b/src/Squidex/Config/Orleans/SiloWrapper.cs @@ -53,8 +53,6 @@ namespace Squidex.Config.Orleans silo = new Lazy(() => { - J.Serializer = SerializationServices.DefaultJsonSerializer; - var hostBuilder = new SiloHostBuilder() .UseDashboard(options => options.HostSelf = false) .AddStartupTask>() diff --git a/src/Squidex/app/framework/angular/forms/jscript-editor.component.ts b/src/Squidex/app/framework/angular/forms/jscript-editor.component.ts index 9d8a506fe..fbe344263 100644 --- a/src/Squidex/app/framework/angular/forms/jscript-editor.component.ts +++ b/src/Squidex/app/framework/angular/forms/jscript-editor.component.ts @@ -9,7 +9,7 @@ import { AfterViewInit, Component, ElementRef, forwardRef, ViewChild } from '@an import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms'; import { Subject } from 'rxjs'; -import { ResourceLoaderService } from '@app/framework/internal'; +import { ResourceLoaderService, Types } from '@app/framework/internal'; declare var ace: any; @@ -40,7 +40,7 @@ export class JscriptEditorComponent implements ControlValueAccessor, AfterViewIn } public writeValue(obj: any) { - this.value = obj + ''; + this.value = Types.isString(obj) ? obj : ''; if (this.aceEditor) { this.setValue(this.value); diff --git a/src/Squidex/app/framework/angular/forms/transform-input.directive.ts b/src/Squidex/app/framework/angular/forms/transform-input.directive.ts index 891035990..44fded675 100644 --- a/src/Squidex/app/framework/angular/forms/transform-input.directive.ts +++ b/src/Squidex/app/framework/angular/forms/transform-input.directive.ts @@ -71,7 +71,7 @@ export class TransformInputDirective implements ControlValueAccessor { } public writeValue(obj: any) { - const normalizedValue = this.transformValue(obj + ''); + const normalizedValue = this.transformValue(Types.isString(obj) ? obj : ''); this.renderer.setProperty(this.element.nativeElement, 'value', normalizedValue); } diff --git a/src/Squidex/app/shared/components/markdown-editor.component.ts b/src/Squidex/app/shared/components/markdown-editor.component.ts index 9540079be..b2190d3ba 100644 --- a/src/Squidex/app/shared/components/markdown-editor.component.ts +++ b/src/Squidex/app/shared/components/markdown-editor.component.ts @@ -11,7 +11,8 @@ import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms'; import { AssetDto, ModalView, - ResourceLoaderService + ResourceLoaderService, + Types } from '@app/shared/internal'; declare var SimpleMDE: any; @@ -54,7 +55,7 @@ export class MarkdownEditorComponent implements ControlValueAccessor, AfterViewI } public writeValue(obj: any) { - this.value = obj + ''; + this.value = Types.isString(obj) ? obj : ''; if (this.simplemde) { this.simplemde.value(this.value); diff --git a/src/Squidex/app/shared/components/rich-editor.component.ts b/src/Squidex/app/shared/components/rich-editor.component.ts index 2512c325e..a0ce4f0cc 100644 --- a/src/Squidex/app/shared/components/rich-editor.component.ts +++ b/src/Squidex/app/shared/components/rich-editor.component.ts @@ -11,7 +11,8 @@ import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms'; import { AssetDto, ModalView, - ResourceLoaderService + ResourceLoaderService, + Types } from '@app/shared/internal'; declare var tinymce: any; @@ -112,7 +113,7 @@ export class RichEditorComponent implements ControlValueAccessor, AfterViewInit, } public writeValue(obj: any) { - this.value = obj + ''; + this.value = Types.isString(obj) ? obj : ''; if (this.tinyEditor) { this.tinyEditor.setContent(this.value);