diff --git a/backend/src/Squidex.Domain.Apps.Entities/Schemas/DomainObject/Guards/GuardHelper.cs b/backend/src/Squidex.Domain.Apps.Entities/Schemas/DomainObject/Guards/GuardHelper.cs index a11d05751..674034698 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Schemas/DomainObject/Guards/GuardHelper.cs +++ b/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; } diff --git a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Schemas/DomainObject/Guards/GuardSchemaFieldTests.cs b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Schemas/DomainObject/Guards/GuardSchemaFieldTests.cs index 3fa964540..22b2ef9ee 100644 --- a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Schemas/DomainObject/Guards/GuardSchemaFieldTests.cs +++ b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Schemas/DomainObject/Guards/GuardSchemaFieldTests.cs @@ -197,6 +197,24 @@ public class GuardSchemaFieldTests : GivenContext, IClassFixture(() => 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(() => 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(() => 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(() => 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() {