From 3ee1013bdb5466bdff9280c89537ae54803492e2 Mon Sep 17 00:00:00 2001 From: Ronald Barendse Date: Wed, 4 Aug 2021 16:39:36 +0200 Subject: [PATCH] Validate unique group names per parent --- .../Models/ContentEditing/ContentTypeSave.cs | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/Umbraco.Web/Models/ContentEditing/ContentTypeSave.cs b/src/Umbraco.Web/Models/ContentEditing/ContentTypeSave.cs index 6a8746292f..1de5a67372 100644 --- a/src/Umbraco.Web/Models/ContentEditing/ContentTypeSave.cs +++ b/src/Umbraco.Web/Models/ContentEditing/ContentTypeSave.cs @@ -88,17 +88,31 @@ namespace Umbraco.Web.Models.ContentEditing yield return validationResult; } - var duplicateGroups = Groups.GroupBy(x => x.Alias).Where(x => x.Count() > 1).ToArray(); - if (duplicateGroups.Any()) + var duplicateGroupAliasses = Groups.GroupBy(x => x.Alias).Where(x => x.Count() > 1).ToArray(); + if (duplicateGroupAliasses.Any()) { //we need to return the field name with an index so it's wired up correctly - var lastIndex = Groups.IndexOf(duplicateGroups.Last().Last()); - yield return new ValidationResult("Duplicate group aliases not allowed", new[] + var lastIndex = Groups.IndexOf(duplicateGroupAliasses.Last().Last()); + yield return new ValidationResult("Duplicate aliases are not allowed", new[] { // TODO We don't display the alias yet, so add the validation message to the name string.Format("Groups[{0}].Name", lastIndex) }); } + else + { + var duplicateGroupNames = Groups.GroupBy(x => (x.GetParentAlias(), x.Name)).Where(x => x.Count() > 1).ToArray(); + if (duplicateGroupNames.Any()) + { + //we need to return the field name with an index so it's wired up correctly + var lastIndex = Groups.IndexOf(duplicateGroupNames.Last().Last()); + yield return new ValidationResult("Duplicate names are not allowed", new[] + { + // TODO We don't display the alias yet, so add the validation message to the name + string.Format("Groups[{0}].Name", lastIndex) + }); + } + } var duplicateProperties = Groups.SelectMany(x => x.Properties).Where(x => x.Inherited == false).GroupBy(x => x.Alias).Where(x => x.Count() > 1).ToArray(); if (duplicateProperties.Any())