Fix logic with check for duplicate container name at level (#19803)

Fix logic with check for duplicate container name at level.
This commit is contained in:
Andy Butland
2025-08-06 16:14:02 +02:00
committed by GitHub
parent 046a3d9aad
commit e5d1c67c36
3 changed files with 22 additions and 3 deletions

View File

@@ -107,7 +107,7 @@ internal abstract class EntityTypeContainerService<TTreeEntity, TEntityContainer
return EntityContainerOperationStatus.ParentNotFound;
}
if (_entityContainerRepository.HasDuplicateName(container.ParentId, container.Name!))
if (_entityContainerRepository.HasDuplicateName(parentContainer?.Id ?? Constants.System.Root, container.Name!))
{
return EntityContainerOperationStatus.DuplicateName;
}

View File

@@ -149,7 +149,7 @@ internal class EntityContainerRepository : EntityRepositoryBase<int, EntityConta
{
NodeDto nodeDto = Database.FirstOrDefault<NodeDto>(Sql().SelectAll()
.From<NodeDto>()
.Where<NodeDto>(dto => dto.Text == name && dto.NodeObjectType == NodeObjectTypeId && dto.ParentId == parentId));
.Where<NodeDto>(dto => dto.Text == name && dto.NodeObjectType == NodeObjectTypeId && dto.ParentId == parentId));
return nodeDto is not null;
}

View File

@@ -5,7 +5,6 @@ using Umbraco.Cms.Core.PropertyEditors;
using Umbraco.Cms.Core.Serialization;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Services.OperationStatus;
using Umbraco.Cms.Infrastructure.Services;
using Umbraco.Cms.Tests.Common.Testing;
using Umbraco.Cms.Tests.Integration.Testing;
@@ -54,6 +53,26 @@ internal sealed class DataTypeContainerServiceTests : UmbracoIntegrationTest
Assert.AreEqual(root.Id, created.ParentId);
}
[TestCase("Existing Child Container", false)]
[TestCase("New Child Container", true)]
[TestCase("Root Container", true)]
public async Task Can_Create_Child_Container_Without_Duplicate_Name_At_Level(string containerName, bool expectSuccess)
{
EntityContainer root = (await DataTypeContainerService.CreateAsync(null, "Root Container", null, Constants.Security.SuperUserKey)).Result;
EntityContainer existingChild = (await DataTypeContainerService.CreateAsync(null, "Existing Child Container", root.Key, Constants.Security.SuperUserKey)).Result;
var result = await DataTypeContainerService.CreateAsync(null, containerName, root.Key, Constants.Security.SuperUserKey);
Assert.AreEqual(expectSuccess, result.Success);
if (expectSuccess)
{
Assert.AreEqual(EntityContainerOperationStatus.Success, result.Status);
}
else
{
Assert.AreEqual(EntityContainerOperationStatus.DuplicateName, result.Status);
}
}
[Test]
public async Task Can_Create_Container_With_Explicit_Key()
{