Browse Source

Fix prefix check.

pull/1129/head
Sebastian Stehle 2 years ago
parent
commit
b96bc52c08
  1. 1
      .github/workflows/dev.yml
  2. 20
      backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/Operations/Extensions.cs
  3. 20
      backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/MongoDb/ExtensionsTests.cs
  4. 2
      frontend/src/app/features/content/shared/forms/field-editor.component.scss

1
.github/workflows/dev.yml

@ -36,7 +36,6 @@ jobs:
uses: docker/build-push-action@v6.7.0
with:
load: true
build-args: "SQUIDEX__RUNTIME__VERSION=7.0.0-dev-${{ env.BUILD_NUMBER }}"
cache-from: type=gha
cache-to: type=gha,mode=max
tags: squidex-local

20
backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/Operations/Extensions.cs

@ -129,7 +129,7 @@ public static class Extensions
PipelineDefinitionBuilder.For<MongoContentEntity>()
.Match(LookupMatch)
.Project(
BuildProjection2<MongoContentEntity>(q.Fields)),
BuildProjection<MongoContentEntity>(q.Fields)),
x => x.Joined)
.Project<IdOnly>(
Builders<IdOnly>.Projection.Include(x => x.Joined))
@ -165,15 +165,15 @@ public static class Extensions
public static IFindFluent<T, T> SelectFields<T>(this IFindFluent<T, T> find, IEnumerable<string>? fields)
{
return find.Project<T>(BuildProjection2<T>(fields));
return find.Project<T>(BuildProjection<T>(fields));
}
public static IAggregateFluent<T> SelectFields<T>(this IAggregateFluent<T> find, IEnumerable<string>? fields)
{
return find.Project<T>(BuildProjection2<T>(fields));
return find.Project<T>(BuildProjection<T>(fields));
}
public static ProjectionDefinition<T, T> BuildProjection2<T>(IEnumerable<string>? fields)
public static ProjectionDefinition<T, T> BuildProjection<T>(IEnumerable<string>? fields)
{
var projector = Builders<T>.Projection;
var projections = new List<ProjectionDefinition<T>>();
@ -210,7 +210,7 @@ public static class Extensions
foreach (var field in allFields)
{
// If there is at least one field that is a prefix of the current field, we cannot add that.
if (addedFields.Exists(x => field.StartsWith(x, StringComparison.Ordinal)))
if (addedFields.Exists(x => IsPrefix(field, x)))
{
continue;
}
@ -227,5 +227,15 @@ public static class Extensions
}
return projector.Combine(projections);
static bool IsPrefix(string field, string prefix)
{
if (!field.StartsWith(prefix, StringComparison.Ordinal))
{
return false;
}
return field.Length == prefix.Length || field[prefix.Length] == '.';
}
}
}

20
backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/MongoDb/ExtensionsTests.cs

@ -22,7 +22,7 @@ public class ExtensionsTests
[Fact]
public void Should_build_projection_without_fields()
{
var projection = ExtensionSut.BuildProjection2<MongoContentEntity>(null);
var projection = ExtensionSut.BuildProjection<MongoContentEntity>(null);
AssertProjection(projection, "{ 'dd' : 0 }");
}
@ -30,7 +30,7 @@ public class ExtensionsTests
[Fact]
public void Should_build_projection_with_data_prefix()
{
var projection = ExtensionSut.BuildProjection2<MongoContentEntity>(["data.myField"]);
var projection = ExtensionSut.BuildProjection<MongoContentEntity>(["data.myField"]);
AssertProjection(projection, "{ '_ai' : 1, '_id' : 1, '_si' : 1, 'ai' : 1, 'cb' : 1, 'ct' : 1, 'dl' : 1, 'do.myField' : 1, 'id' : 1, 'is' : 1, 'mb' : 1, 'mt' : 1, 'ns' : 1, 'rf' : 1, 'sa' : 1, 'si' : 1, 'sj' : 1, 'ss' : 1, 'ts' : 1, 'vs' : 1 }");
}
@ -38,7 +38,7 @@ public class ExtensionsTests
[Fact]
public void Should_build_projection_without_data_prefix()
{
var projection = ExtensionSut.BuildProjection2<MongoContentEntity>(["myField"]);
var projection = ExtensionSut.BuildProjection<MongoContentEntity>(["myField"]);
AssertProjection(projection, "{ '_ai' : 1, '_id' : 1, '_si' : 1, 'ai' : 1, 'cb' : 1, 'ct' : 1, 'dl' : 1, 'do.myField' : 1, 'id' : 1, 'is' : 1, 'mb' : 1, 'mt' : 1, 'ns' : 1, 'rf' : 1, 'sa' : 1, 'si' : 1, 'sj' : 1, 'ss' : 1, 'ts' : 1, 'vs' : 1 }");
}
@ -46,15 +46,23 @@ public class ExtensionsTests
[Fact]
public void Should_build_projection_without_included_field()
{
var projection = ExtensionSut.BuildProjection2<MongoContentEntity>(["myField.special", "myField"]);
var projection = ExtensionSut.BuildProjection<MongoContentEntity>(["myField.special", "myField"]);
AssertProjection(projection, "{ '_ai' : 1, '_id' : 1, '_si' : 1, 'ai' : 1, 'cb' : 1, 'ct' : 1, 'dl' : 1, 'do.myField' : 1, 'id' : 1, 'is' : 1, 'mb' : 1, 'mt' : 1, 'ns' : 1, 'rf' : 1, 'sa' : 1, 'si' : 1, 'sj' : 1, 'ss' : 1, 'ts' : 1, 'vs' : 1 }");
}
[Fact]
public void Should_build_projection_with_prefix_field()
{
var projection = ExtensionSut.BuildProjection<MongoContentEntity>(["myField", "myField2"]);
AssertProjection(projection, "{ '_ai' : 1, '_id' : 1, '_si' : 1, 'ai' : 1, 'cb' : 1, 'ct' : 1, 'dl' : 1, 'do.myField' : 1, 'do.myField2' : 1, 'id' : 1, 'is' : 1, 'mb' : 1, 'mt' : 1, 'ns' : 1, 'rf' : 1, 'sa' : 1, 'si' : 1, 'sj' : 1, 'ss' : 1, 'ts' : 1, 'vs' : 1 }");
}
[Fact]
public void Should_build_projection_with_status_data_field()
{
var projection = ExtensionSut.BuildProjection2<MongoContentEntity>(["data.Status"]);
var projection = ExtensionSut.BuildProjection<MongoContentEntity>(["data.Status"]);
AssertProjection(projection, "{ '_ai' : 1, '_id' : 1, '_si' : 1, 'ai' : 1, 'cb' : 1, 'ct' : 1, 'dl' : 1, 'do.Status' : 1, 'id' : 1, 'is' : 1, 'mb' : 1, 'mt' : 1, 'ns' : 1, 'rf' : 1, 'sa' : 1, 'si' : 1, 'sj' : 1, 'ss' : 1, 'ts' : 1, 'vs' : 1 }");
}
@ -62,7 +70,7 @@ public class ExtensionsTests
[Fact]
public void Should_build_projection_with_meta_status_field()
{
var projection = ExtensionSut.BuildProjection2<MongoContentEntity>(["status"]);
var projection = ExtensionSut.BuildProjection<MongoContentEntity>(["status"]);
AssertProjection(projection, "{ '_ai' : 1, '_id' : 1, '_si' : 1, 'ai' : 1, 'cb' : 1, 'ct' : 1, 'dl' : 1, 'do.status' : 1, 'id' : 1, 'is' : 1, 'mb' : 1, 'mt' : 1, 'ns' : 1, 'rf' : 1, 'sa' : 1, 'si' : 1, 'sj' : 1, 'ss' : 1, 'ts' : 1, 'vs' : 1 }");
}

2
frontend/src/app/features/content/shared/forms/field-editor.component.scss

@ -7,7 +7,7 @@
}
&-disabled {
color: $color-border-dark;
color: $color-text-decent;
font-size: $font-smallest;
font-weight: normal;
}

Loading…
Cancel
Save