From 399968ef9c7442387d010406d18775c10b61b8ad Mon Sep 17 00:00:00 2001 From: Sebastian Date: Sat, 8 Oct 2022 20:17:29 +0200 Subject: [PATCH] Fix rtule creation. --- ...Squidex.Domain.Apps.Core.Operations.csproj | 2 +- .../Squidex.Domain.Apps.Entities.csproj | 2 +- .../Squidex.Infrastructure.csproj | 12 ++-- .../ApiModelValidationAttribute.cs | 67 +++++++++---------- .../Config/Domain/SerializationServices.cs | 1 + .../Config/Messaging/MessagingServices.cs | 11 +-- backend/src/Squidex/Squidex.csproj | 24 +++---- .../administration/state/users.state.ts | 2 +- .../rules/pages/rule/rule-page.component.html | 20 +++--- .../rules/pages/rule/rule-page.component.ts | 60 ++++++++--------- .../content-changed-trigger.component.ts | 4 +- .../src/app/shared/state/languages.state.ts | 3 +- frontend/src/app/shared/state/rules.forms.ts | 4 +- 13 files changed, 106 insertions(+), 106 deletions(-) diff --git a/backend/src/Squidex.Domain.Apps.Core.Operations/Squidex.Domain.Apps.Core.Operations.csproj b/backend/src/Squidex.Domain.Apps.Core.Operations/Squidex.Domain.Apps.Core.Operations.csproj index b8f65e7e4..439726aac 100644 --- a/backend/src/Squidex.Domain.Apps.Core.Operations/Squidex.Domain.Apps.Core.Operations.csproj +++ b/backend/src/Squidex.Domain.Apps.Core.Operations/Squidex.Domain.Apps.Core.Operations.csproj @@ -28,7 +28,7 @@ - + diff --git a/backend/src/Squidex.Domain.Apps.Entities/Squidex.Domain.Apps.Entities.csproj b/backend/src/Squidex.Domain.Apps.Entities/Squidex.Domain.Apps.Entities.csproj index ae8cd96e5..5260fae79 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Squidex.Domain.Apps.Entities.csproj +++ b/backend/src/Squidex.Domain.Apps.Entities/Squidex.Domain.Apps.Entities.csproj @@ -29,7 +29,7 @@ - + diff --git a/backend/src/Squidex.Infrastructure/Squidex.Infrastructure.csproj b/backend/src/Squidex.Infrastructure/Squidex.Infrastructure.csproj index 682998398..c2f78a254 100644 --- a/backend/src/Squidex.Infrastructure/Squidex.Infrastructure.csproj +++ b/backend/src/Squidex.Infrastructure/Squidex.Infrastructure.csproj @@ -24,12 +24,12 @@ - - - - - - + + + + + + diff --git a/backend/src/Squidex.Web/ApiModelValidationAttribute.cs b/backend/src/Squidex.Web/ApiModelValidationAttribute.cs index 0108e8495..4f6abf1f7 100644 --- a/backend/src/Squidex.Web/ApiModelValidationAttribute.cs +++ b/backend/src/Squidex.Web/ApiModelValidationAttribute.cs @@ -27,60 +27,57 @@ namespace Squidex.Web public override void OnActionExecuting(ActionExecutingContext context) { - if (!context.ModelState.IsValid) + if (context.ModelState.IsValid) { - var errors = new List(); + return; + } + + var errors = new List(); - foreach (var (key, value) in context.ModelState) + foreach (var (key, value) in context.ModelState) + { + if (value.ValidationState == ModelValidationState.Invalid) { - if (value.ValidationState == ModelValidationState.Invalid) + foreach (var error in value.Errors) { - foreach (var error in value.Errors) + if (error.ErrorMessage?.Contains(RequestBodyTooLarge, StringComparison.OrdinalIgnoreCase) == true) { - if (error.ErrorMessage?.Contains(RequestBodyTooLarge, StringComparison.OrdinalIgnoreCase) == true) - { - throw new BadHttpRequestException(error.ErrorMessage, 413); - } + throw new BadHttpRequestException(error.ErrorMessage, 413); } + } + + if (string.IsNullOrWhiteSpace(key)) + { + errors.Add(new ValidationError(T.Get("common.httpInvalidRequestFormat"))); + } + else + { + var properties = Array.Empty(); - if (string.IsNullOrWhiteSpace(key)) + if (!string.IsNullOrWhiteSpace(key)) { - errors.Add(new ValidationError(T.Get("common.httpInvalidRequestFormat"))); + properties = new[] { key.ToCamelCase() }; } - else - { - var properties = Array.Empty(); - if (!string.IsNullOrWhiteSpace(key)) + foreach (var error in value.Errors) + { + if (!string.IsNullOrWhiteSpace(error.ErrorMessage) && allErrors) { - properties = new[] { key.ToCamelCase() }; + errors.Add(new ValidationError(error.ErrorMessage, properties)); } - - foreach (var error in value.Errors) + else if (error.Exception is JsonException jsonException) { - if (!string.IsNullOrWhiteSpace(error.ErrorMessage) && ShouldExpose(error)) - { - errors.Add(new ValidationError(error.ErrorMessage, properties)); - } - else if (error.Exception is JsonException jsonException) - { - errors.Add(new ValidationError(jsonException.Message)); - } + errors.Add(new ValidationError(jsonException.Message)); } } } } - - if (errors.Count > 0) - { - throw new ValidationException(errors); - } } - } - private bool ShouldExpose(ModelError error) - { - return allErrors || error.Exception is JsonException; + if (errors.Count > 0) + { + throw new ValidationException(errors); + } } } } diff --git a/backend/src/Squidex/Config/Domain/SerializationServices.cs b/backend/src/Squidex/Config/Domain/SerializationServices.cs index 6c965a357..5f3c1303c 100644 --- a/backend/src/Squidex/Config/Domain/SerializationServices.cs +++ b/backend/src/Squidex/Config/Domain/SerializationServices.cs @@ -117,6 +117,7 @@ namespace Squidex.Config.Domain ConfigureJson(c.GetRequiredService(), options.JsonSerializerOptions); options.JsonSerializerOptions.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull; + options.AllowInputFormatterExceptionMessages = true; }); return builder; diff --git a/backend/src/Squidex/Config/Messaging/MessagingServices.cs b/backend/src/Squidex/Config/Messaging/MessagingServices.cs index d8ee4b0ce..4886b0b27 100644 --- a/backend/src/Squidex/Config/Messaging/MessagingServices.cs +++ b/backend/src/Squidex/Config/Messaging/MessagingServices.cs @@ -95,22 +95,25 @@ namespace Squidex.Config.Messaging { options.Timeout = TimeSpan.FromHours(4); options.Scheduler = new ParallelScheduler(4); + options.LogMessage = x => true; }); services.AddMessaging(channelBackupRestore, isWorker, options => { options.Timeout = TimeSpan.FromHours(24); options.Scheduler = InlineScheduler.Instance; + options.LogMessage = x => true; }); - services.AddMessaging(channelFallback, isWorker, options => + services.AddMessaging(channelRules, isWorker, options => { - options.Scheduler = InlineScheduler.Instance; + options.Scheduler = new ParallelScheduler(4); + options.LogMessage = x => true; }); - services.AddMessaging(channelRules, isWorker, options => + services.AddMessaging(channelFallback, isWorker, options => { - options.Scheduler = new ParallelScheduler(4); + options.Scheduler = InlineScheduler.Instance; }); } } diff --git a/backend/src/Squidex/Squidex.csproj b/backend/src/Squidex/Squidex.csproj index 6415feda3..0224ff50d 100644 --- a/backend/src/Squidex/Squidex.csproj +++ b/backend/src/Squidex/Squidex.csproj @@ -69,19 +69,19 @@ - - - - - - - - + + + + + + + + - - - - + + + + diff --git a/frontend/src/app/features/administration/state/users.state.ts b/frontend/src/app/features/administration/state/users.state.ts index 37a689dbe..380476ab6 100644 --- a/frontend/src/app/features/administration/state/users.state.ts +++ b/frontend/src/app/features/administration/state/users.state.ts @@ -201,7 +201,7 @@ export class UsersState extends State { private replaceUser(user: UserDto) { return this.next(s => { - const users = s.users.map(u => (u.id === user.id ? user : u)); + const users = s.users.replacedBy('id', user); const selectedUser = s.selectedUser?.id !== user.id ? diff --git a/frontend/src/app/features/rules/pages/rule/rule-page.component.html b/frontend/src/app/features/rules/pages/rule/rule-page.component.html index ddea59a68..6ab469284 100644 --- a/frontend/src/app/features/rules/pages/rule/rule-page.component.html +++ b/frontend/src/app/features/rules/pages/rule/rule-page.component.html @@ -49,7 +49,7 @@
- +
@@ -69,18 +69,18 @@ {{ 'rules.triggerHint' | sqxTranslate }} - + - + - + + [trigger]="currentTrigger.form.value" + [triggerForm]="currentTrigger"> @@ -112,7 +112,7 @@
- +
@@ -134,9 +134,9 @@ diff --git a/frontend/src/app/features/rules/pages/rule/rule-page.component.ts b/frontend/src/app/features/rules/pages/rule/rule-page.component.ts index 146cae2d7..d816942fd 100644 --- a/frontend/src/app/features/rules/pages/rule/rule-page.component.ts +++ b/frontend/src/app/features/rules/pages/rule/rule-page.component.ts @@ -12,8 +12,6 @@ import { debounceTime, Subscription } from 'rxjs'; import { ActionForm, ALL_TRIGGERS, MessageBus, ResourceOwner, RuleDto, RuleElementDto, RulesService, RulesState, SchemasState, TriggerForm, value$ } from '@app/shared'; import { RuleConfigured } from '../messages'; -type ComponentState = { type: string; values: any; form: T }; - @Component({ selector: 'sqx-rule-page', styleUrls: ['./rule-page.component.scss'], @@ -28,8 +26,8 @@ export class RulePageComponent extends ResourceOwner implements OnInit { public rule?: RuleDto | null; - public currentTrigger?: ComponentState; - public currentAction?: ComponentState; + public currentTrigger?: TriggerForm; + public currentAction?: ActionForm; public isEnabled = false; public isEditable = false; @@ -39,11 +37,11 @@ export class RulePageComponent extends ResourceOwner implements OnInit { } public get actionElement() { - return this.supportedActions![this.currentAction?.type || '']; + return this.supportedActions![this.currentAction?.actionType || '']; } public get triggerElement() { - return this.supportedTriggers[this.currentTrigger?.type || '']; + return this.supportedTriggers[this.currentTrigger?.triggerType || '']; } constructor( @@ -92,30 +90,32 @@ export class RulePageComponent extends ResourceOwner implements OnInit { } } - public selectAction(type: string, values = {}) { - if (this.currentAction?.type !== type && this.supportedActions) { - const form = new ActionForm(this.supportedActions[type], type); + public selectAction(type: string, values?: any) { + const definition = this.supportedActions[type]; - this.currentAction = { form, type, values }; - this.currentAction.form.setEnabled(this.isEditable); + if (this.currentAction?.actionType !== type && definition) { + this.currentAction = new ActionForm(definition, type); + this.currentAction.setEnabled(this.isEditable); this.currentActionSubscription?.unsubscribe(); - this.currentActionSubscription = this.subscribe(form.form); + this.currentActionSubscription = this.subscribe(this.currentAction.form); } - this.currentAction!.form.load(values); + if (values) { + this.currentAction?.load(values); + } } - public selectTrigger(type: string, values = {}) { - if (this.currentTrigger?.type !== type) { - const form = new TriggerForm(type); - - this.currentTrigger = { form, type, values }; - this.currentTrigger.form.setEnabled(this.isEditable); + public selectTrigger(type: string, values?: any) { + if (this.currentTrigger?.triggerType !== type) { + this.currentTrigger = new TriggerForm(type); + this.currentTrigger.setEnabled(this.isEditable); this.currentTriggerSubscription?.unsubscribe(); - this.currentTriggerSubscription = this.subscribe(form.form); + this.currentTriggerSubscription = this.subscribe(this.currentTrigger.form); } - this.currentTrigger.form.load(values); + if (values) { + this.currentTrigger?.load(values || {}); + } } private subscribe(form: AbstractControl) { @@ -139,13 +139,13 @@ export class RulePageComponent extends ResourceOwner implements OnInit { return; } - const action = this.currentAction.form.submit(); + const action = this.currentAction.submit(); if (!action) { return; } - const trigger = this.currentTrigger.form.submit(); + const trigger = this.currentTrigger.submit(); if (!trigger || !action) { return; @@ -183,23 +183,23 @@ export class RulePageComponent extends ResourceOwner implements OnInit { return; } - if (!this.currentAction.form.form.valid || !this.currentTrigger.form.form.valid) { + if (!this.currentAction.form.valid || !this.currentTrigger.form.valid) { return; } this.messageBus.emit(new RuleConfigured( - this.currentTrigger.form.getValue(), - this.currentAction.form.getValue())); + this.currentTrigger.getValue(), + this.currentAction.getValue())); } private submitCompleted() { - this.currentAction?.form.submitCompleted({ noReset: true }); - this.currentTrigger?.form.submitCompleted({ noReset: true }); + this.currentAction?.submitCompleted({ noReset: true }); + this.currentTrigger?.submitCompleted({ noReset: true }); } private submitFailed(error: any) { - this.currentAction?.form?.submitFailed(error); - this.currentTrigger?.form?.submitFailed(error); + this.currentAction?.submitFailed(error); + this.currentTrigger?.submitFailed(error); } public back() { diff --git a/frontend/src/app/features/rules/shared/triggers/content-changed-trigger.component.ts b/frontend/src/app/features/rules/shared/triggers/content-changed-trigger.component.ts index 8ebef1f07..af2983159 100644 --- a/frontend/src/app/features/rules/shared/triggers/content-changed-trigger.component.ts +++ b/frontend/src/app/features/rules/shared/triggers/content-changed-trigger.component.ts @@ -75,13 +75,13 @@ export class ContentChangedTriggerComponent implements OnChanges { } public updateCondition(schema: SchemaDto, condition: string) { - this.triggerSchemas = this.triggerSchemas.map(s => (s.schema === schema ? { schema, condition } : s)); + this.triggerSchemas.replaceBy('schema', { schema, condition }); this.updateValue(); } public updateValue() { - const schemas = this.triggerSchemas.map(s => ({ schemaId: s.schema.id, condition: s.condition })); + const schemas = this.triggerSchemas.map(({ schema, condition }) => ({ schemaId: schema.id, condition })); this.triggerForm.form.patchValue({ schemas }); } diff --git a/frontend/src/app/shared/state/languages.state.ts b/frontend/src/app/shared/state/languages.state.ts index 15830e724..273656e01 100644 --- a/frontend/src/app/shared/state/languages.state.ts +++ b/frontend/src/app/shared/state/languages.state.ts @@ -189,8 +189,7 @@ export class LanguagesState extends State { .map(l => languages.find(x => x.iso2Code === l)).defined(), fallbackLanguagesNew: languages - .filter(l => language.iso2Code !== l.iso2Code && !language.fallback.includes(l.iso2Code)) - .sortByString(x => x.englishName), + .filter(l => language.iso2Code !== l.iso2Code && !language.fallback.includes(l.iso2Code)).sortByString(x => x.englishName), }; } } diff --git a/frontend/src/app/shared/state/rules.forms.ts b/frontend/src/app/shared/state/rules.forms.ts index 53475ffa4..a68de081c 100644 --- a/frontend/src/app/shared/state/rules.forms.ts +++ b/frontend/src/app/shared/state/rules.forms.ts @@ -11,7 +11,7 @@ import { RuleElementDto } from '../services/rules.service'; export class ActionForm extends Form { constructor(public readonly definition: RuleElementDto, - private readonly actionType: string, + public readonly actionType: string, ) { super(ActionForm.builForm(definition)); } @@ -40,7 +40,7 @@ export class ActionForm extends Form { export class TriggerForm extends Form { constructor( - private readonly triggerType: string, + public readonly triggerType: string, ) { super(TriggerForm.builForm(triggerType)); }