Browse Source

Enforce the field lock for nested fields of array fields (#1381)

Co-authored-by: claude[bot] <claude[bot]@users.noreply.github.com>
pull/1389/head
github-actions[bot] 6 days ago
committed by GitHub
parent
commit
9541cbbb5f
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 5
      backend/src/Squidex.Domain.Apps.Entities/Schemas/DomainObject/Guards/GuardHelper.cs
  2. 38
      backend/tests/Squidex.Domain.Apps.Entities.Tests/Schemas/DomainObject/Guards/GuardSchemaFieldTests.cs

5
backend/src/Squidex.Domain.Apps.Entities/Schemas/DomainObject/Guards/GuardHelper.cs

@ -40,6 +40,11 @@ public static class GuardHelper
throw new DomainObjectNotFoundException(fieldId.ToString(CultureInfo.InvariantCulture));
}
if (!allowLocked)
{
EnsureNotLocked(nestedField);
}
return nestedField;
}

38
backend/tests/Squidex.Domain.Apps.Entities.Tests/Schemas/DomainObject/Guards/GuardSchemaFieldTests.cs

@ -197,6 +197,24 @@ public class GuardSchemaFieldTests : GivenContext, IClassFixture<TranslationsFix
Assert.Throws<DomainException>(() => GuardSchemaField.CanDelete(command, Schema));
}
[Fact]
public void CanDelete_should_throw_exception_if_nested_field_locked()
{
var command = new DeleteField { ParentFieldId = 3, FieldId = 301 };
Schema = Schema.LockField(301, 3);
Assert.Throws<DomainException>(() => GuardSchemaField.CanDelete(command, Schema));
}
[Fact]
public void CanDelete_should_not_throw_exception_if_nested_field_not_locked()
{
var command = new DeleteField { ParentFieldId = 3, FieldId = 301 };
GuardSchemaField.CanDelete(command, Schema);
}
[Fact]
public void CanDelete_should_not_throw_exception_if_not_locked()
{
@ -215,6 +233,26 @@ public class GuardSchemaFieldTests : GivenContext, IClassFixture<TranslationsFix
Assert.Throws<DomainException>(() => GuardSchemaField.CanUpdate(command, Schema));
}
[Fact]
public void CanUpdate_should_throw_exception_if_nested_field_locked()
{
var command = new UpdateField { ParentFieldId = 3, FieldId = 301, Properties = new NumberFieldProperties() };
Schema = Schema.LockField(301, 3);
Assert.Throws<DomainException>(() => GuardSchemaField.CanUpdate(command, Schema));
}
[Fact]
public void CanLock_should_not_throw_exception_if_nested_field_locked()
{
var command = new LockField { ParentFieldId = 3, FieldId = 301 };
Schema = Schema.LockField(301, 3);
GuardSchemaField.CanLock(command, Schema);
}
[Fact]
public void CanUpdate_should_not_throw_exception_if_not_locked()
{

Loading…
Cancel
Save