Browse Source

More placeholder fixes.

pull/867/head
Sebastian 4 years ago
parent
commit
129edd724c
  1. 30
      backend/src/Squidex.Domain.Apps.Core.Operations/HandleRules/RuleEventFormatter.cs
  2. 17
      backend/src/Squidex.Domain.Apps.Core.Operations/Scripting/EventScriptVars.cs
  3. 10
      backend/src/Squidex.Domain.Apps.Core.Operations/Scripting/ScriptingCompleter.cs
  4. 2
      frontend/src/app/features/rules/shared/triggers/asset-changed-trigger.component.html
  5. 2
      frontend/src/app/features/rules/shared/triggers/comment-trigger.component.html
  6. 6
      frontend/src/app/features/rules/shared/triggers/content-changed-trigger.component.html
  7. 2
      frontend/src/app/features/rules/shared/triggers/schema-changed-trigger.component.html

30
backend/src/Squidex.Domain.Apps.Core.Operations/HandleRules/RuleEventFormatter.cs

@ -6,6 +6,7 @@
// ========================================================================== // ==========================================================================
using System.Globalization; using System.Globalization;
using System.Security.Claims;
using System.Text; using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using Newtonsoft.Json; using Newtonsoft.Json;
@ -14,6 +15,8 @@ using Squidex.Domain.Apps.Core.Rules.EnrichedEvents;
using Squidex.Domain.Apps.Core.Scripting; using Squidex.Domain.Apps.Core.Scripting;
using Squidex.Domain.Apps.Core.Templates; using Squidex.Domain.Apps.Core.Templates;
using Squidex.Infrastructure.Json; using Squidex.Infrastructure.Json;
using Squidex.Shared;
using Squidex.Shared.Identity;
using Squidex.Text; using Squidex.Text;
using ValueTaskSupplement; using ValueTaskSupplement;
@ -76,12 +79,16 @@ namespace Squidex.Domain.Apps.Core.HandleRules
public virtual string ToPayload<T>(T @event) public virtual string ToPayload<T>(T @event)
{ {
return jsonSerializer.Serialize(@event); var payload = @event;
return jsonSerializer.Serialize(payload);
} }
public virtual string ToEnvelope(EnrichedEvent @event) public virtual string ToEnvelope(EnrichedEvent @event)
{ {
return jsonSerializer.Serialize(new { type = @event.Name, payload = @event, timestamp = @event.Timestamp }); var payload = new { type = @event.Name, payload = @event, timestamp = @event.Timestamp };
return jsonSerializer.Serialize(payload);
} }
public async ValueTask<string?> FormatAsync(string text, EnrichedEvent @event) public async ValueTask<string?> FormatAsync(string text, EnrichedEvent @event)
@ -106,12 +113,13 @@ namespace Squidex.Domain.Apps.Core.HandleRules
// Script vars are just wrappers over dictionaries for better performance. // Script vars are just wrappers over dictionaries for better performance.
var vars = new EventScriptVars var vars = new EventScriptVars
{ {
Event = @event Event = @event,
AppId = @event.AppId.Id,
AppName = @event.AppId.Name,
User = Admin()
}; };
#pragma warning disable MA0042 // Do not use blocking calls in an async method var result = (await scriptEngine.ExecuteAsync(vars, script)).ToString();
var result = scriptEngine.Execute(vars, script).ToString();
#pragma warning restore MA0042 // Do not use blocking calls in an async method
if (result == "undefined") if (result == "undefined")
{ {
@ -131,6 +139,16 @@ namespace Squidex.Domain.Apps.Core.HandleRules
return CombineParts(text, parts); return CombineParts(text, parts);
} }
private static ClaimsPrincipal Admin()
{
var claimsIdentity = new ClaimsIdentity();
var claimsPrincipal = new ClaimsPrincipal(claimsIdentity);
claimsIdentity.AddClaim(new Claim(SquidexClaimTypes.Permissions, Permissions.All));
return claimsPrincipal;
}
private static string CombineParts(string text, List<TextPart> parts) private static string CombineParts(string text, List<TextPart> parts)
{ {
var span = text.AsSpan(); var span = text.AsSpan();

17
backend/src/Squidex.Domain.Apps.Core.Operations/Scripting/EventScriptVars.cs

@ -5,12 +5,29 @@
// All rights reserved. Licensed under the MIT license. // All rights reserved. Licensed under the MIT license.
// ========================================================================== // ==========================================================================
using System.Security.Claims;
using Squidex.Domain.Apps.Core.Rules.EnrichedEvents; using Squidex.Domain.Apps.Core.Rules.EnrichedEvents;
using Squidex.Infrastructure;
namespace Squidex.Domain.Apps.Core.Scripting namespace Squidex.Domain.Apps.Core.Scripting
{ {
public sealed class EventScriptVars : ScriptVars public sealed class EventScriptVars : ScriptVars
{ {
public DomainId AppId
{
set => SetValue(value);
}
public string AppName
{
set => SetValue(value);
}
public ClaimsPrincipal User
{
set => SetValue(value);
}
public EnrichedEvent Event public EnrichedEvent Event
{ {
set => SetValue(value); set => SetValue(value);

10
backend/src/Squidex.Domain.Apps.Core.Operations/Scripting/ScriptingCompleter.cs

@ -119,7 +119,7 @@ namespace Squidex.Domain.Apps.Core.Scripting
public IReadOnlyList<ScriptingValue> SchemaTrigger() public IReadOnlyList<ScriptingValue> SchemaTrigger()
{ {
AddHelpers(ScriptScope.SchemaTrigger); AddHelpers(ScriptScope.SchemaTrigger | ScriptScope.Async);
AddObject("event", FieldDescriptions.Event, () => AddObject("event", FieldDescriptions.Event, () =>
{ {
@ -131,7 +131,7 @@ namespace Squidex.Domain.Apps.Core.Scripting
public IReadOnlyList<ScriptingValue> CommentTrigger() public IReadOnlyList<ScriptingValue> CommentTrigger()
{ {
AddHelpers(ScriptScope.CommentTrigger); AddHelpers(ScriptScope.CommentTrigger | ScriptScope.Async);
AddObject("event", FieldDescriptions.Event, () => AddObject("event", FieldDescriptions.Event, () =>
{ {
@ -143,7 +143,7 @@ namespace Squidex.Domain.Apps.Core.Scripting
public IReadOnlyList<ScriptingValue> UsageTrigger() public IReadOnlyList<ScriptingValue> UsageTrigger()
{ {
AddHelpers(ScriptScope.UsageTrigger); AddHelpers(ScriptScope.UsageTrigger | ScriptScope.Async);
AddObject("event", FieldDescriptions.Event, () => AddObject("event", FieldDescriptions.Event, () =>
{ {
@ -169,7 +169,7 @@ namespace Squidex.Domain.Apps.Core.Scripting
public IReadOnlyList<ScriptingValue> ContentTrigger() public IReadOnlyList<ScriptingValue> ContentTrigger()
{ {
var scope = ScriptScope.ContentTrigger; var scope = ScriptScope.ContentTrigger | ScriptScope.Async;
AddHelpers(scope); AddHelpers(scope);
@ -183,7 +183,7 @@ namespace Squidex.Domain.Apps.Core.Scripting
public IReadOnlyList<ScriptingValue> AssetTrigger() public IReadOnlyList<ScriptingValue> AssetTrigger()
{ {
AddHelpers(ScriptScope.AssetTrigger); AddHelpers(ScriptScope.AssetTrigger | ScriptScope.Async);
AddObject("event", FieldDescriptions.Event, () => AddObject("event", FieldDescriptions.Event, () =>
{ {

2
frontend/src/app/features/rules/shared/triggers/asset-changed-trigger.component.html

@ -4,7 +4,7 @@
<sqx-control-errors for="condition"></sqx-control-errors> <sqx-control-errors for="condition"></sqx-control-errors>
<textarea class="form-control code" id="condition" formControlName="condition" placeholder="i18n:rules.conditionHint"></textarea> <textarea class="form-control code" id="condition" formControlName="condition" placeholder="{{ 'i18n:rules.conditionHint' | sqxTranslate }}"></textarea>
</div> </div>
<div class="help"> <div class="help">

2
frontend/src/app/features/rules/shared/triggers/comment-trigger.component.html

@ -4,7 +4,7 @@
<sqx-control-errors for="condition"></sqx-control-errors> <sqx-control-errors for="condition"></sqx-control-errors>
<textarea class="form-control code" id="condition" formControlName="condition" placeholder="i18n:rules.conditionHint"></textarea> <textarea class="form-control code" id="condition" formControlName="condition" placeholder="{{ 'i18n:rules.conditionHint' | sqxTranslate }}"></textarea>
</div> </div>
<div class="help"> <div class="help">

6
frontend/src/app/features/rules/shared/triggers/content-changed-trigger.component.html

@ -21,7 +21,11 @@
<span class="truncate">{{triggerSchema.schema.displayName}}</span> <span class="truncate">{{triggerSchema.schema.displayName}}</span>
</td> </td>
<td class="text-center"> <td class="text-center">
<input type="text" class="form-control code" placeholder="i18n:rules.conditionHint" [disabled]="triggerForm.form.disabled" [ngModelOptions]="{ updateOn: 'blur' }" [ngModel]="triggerSchema.condition" (ngModelChange)="updateCondition(triggerSchema.schema, $event)"> <input type="text" class="form-control code" placeholder="{{ 'i18n:rules.conditionHint' | sqxTranslate }}"
[disabled]="triggerForm.form.disabled"
[ngModelOptions]="{ updateOn: 'blur' }"
[ngModel]="triggerSchema.condition"
(ngModelChange)="updateCondition(triggerSchema.schema, $event)">
</td> </td>
<td class="text-center"> <td class="text-center">
<button type="button" class="btn btn-text-secondary" (click)="removeSchema(triggerSchema)" [disabled]="triggerForm.form.disabled"> <button type="button" class="btn btn-text-secondary" (click)="removeSchema(triggerSchema)" [disabled]="triggerForm.form.disabled">

2
frontend/src/app/features/rules/shared/triggers/schema-changed-trigger.component.html

@ -4,7 +4,7 @@
<sqx-control-errors for="condition"></sqx-control-errors> <sqx-control-errors for="condition"></sqx-control-errors>
<textarea class="form-control code" id="condition" formControlName="condition" placeholder="i18n:rules.conditionHint"></textarea> <textarea class="form-control code" id="condition" formControlName="condition" placeholder="{{ 'i18n:rules.conditionHint' | sqxTranslate }}"></textarea>
</div> </div>
<div class="help"> <div class="help">

Loading…
Cancel
Save