Browse Source

Always calculate edit token.

pull/909/head
Sebastian 3 years ago
parent
commit
a8da5c689b
  1. 9
      backend/src/Squidex.Domain.Apps.Entities/Assets/Queries/AssetEnricher.cs
  2. 6
      backend/src/Squidex.Domain.Apps.Entities/Contents/Queries/Steps/CalculateTokens.cs
  3. 6
      backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/Queries/AssetEnricherTests.cs
  4. 12
      backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/Queries/CalculateTokensTests.cs

9
backend/src/Squidex.Domain.Apps.Entities/Assets/Queries/AssetEnricher.cs

@ -64,23 +64,20 @@ namespace Squidex.Domain.Apps.Entities.Assets.Queries
await EnrichTagsAsync(results, ct);
EnrichWithMetadataText(results);
if (!context.IsFrontendClient)
{
ComputeTokens(results);
}
EnrichWithEditTokens(results);
}
return results;
}
}
private void ComputeTokens(IEnumerable<IEnrichedAssetEntity> assets)
private void EnrichWithEditTokens(IEnumerable<IEnrichedAssetEntity> assets)
{
var url = urlGenerator.Root();
foreach (var asset in assets)
{
// We have to use these short names here because they are later read like this.
var token = new
{
a = asset.AppId.Name,

6
backend/src/Squidex.Domain.Apps.Entities/Contents/Queries/Steps/CalculateTokens.cs

@ -25,15 +25,11 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries.Steps
public Task EnrichAsync(Context context, IEnumerable<ContentEntity> contents, ProvideSchema schemas,
CancellationToken ct)
{
if (context.IsFrontendClient)
{
return Task.CompletedTask;
}
var url = urlGenerator.Root();
foreach (var content in contents)
{
// We have to use these short names here because they are later read like this.
var token = new
{
a = content.AppId.Name,

6
backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/Queries/AssetEnricherTests.cs

@ -173,7 +173,7 @@ namespace Squidex.Domain.Apps.Entities.Assets.Queries
}
[Fact]
public async Task Should_not_compute_ui_tokens_for_frontend()
public async Task Should_also_compute_ui_tokens_for_frontend()
{
var source = new AssetEntity
{
@ -182,10 +182,10 @@ namespace Squidex.Domain.Apps.Entities.Assets.Queries
var result = await sut.EnrichAsync(new[] { source }, new Context(Mocks.FrontendUser(), Mocks.App(appId)), ct);
Assert.Null(result[0].EditToken);
Assert.NotNull(result[0].EditToken);
A.CallTo(() => urlGenerator.Root())
.MustNotHaveHappened();
.MustHaveHappened();
}
[Fact]

12
backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/Queries/CalculateTokensTests.cs

@ -39,24 +39,24 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries
}
[Fact]
public async Task Should_not_compute_ui_tokens_for_frontend()
public async Task Should_compute_ui_tokens()
{
var source = CreateContent();
await sut.EnrichAsync(new Context(Mocks.FrontendUser(), Mocks.App(appId)), new[] { source }, schemaProvider, default);
await sut.EnrichAsync(requestContext, new[] { source }, schemaProvider, default);
Assert.Null(source.EditToken);
Assert.NotNull(source.EditToken);
A.CallTo(() => urlGenerator.Root())
.MustNotHaveHappened();
.MustHaveHappened();
}
[Fact]
public async Task Should_compute_ui_tokens()
public async Task Should_also_compute_ui_tokens_for_frontend()
{
var source = CreateContent();
await sut.EnrichAsync(requestContext, new[] { source }, schemaProvider, default);
await sut.EnrichAsync(new Context(Mocks.FrontendUser(), Mocks.App(appId)), new[] { source }, schemaProvider, default);
Assert.NotNull(source.EditToken);

Loading…
Cancel
Save