V14: Add clearer error for invalid property type (#16530)
* Add clearer error for invalid property type * Update test
This commit is contained in:
@@ -41,6 +41,10 @@ public abstract class DocumentTypeControllerBase : ManagementApiControllerBase
|
||||
.WithTitle("Invalid property type alias")
|
||||
.WithDetail("One or more property type aliases are invalid")
|
||||
.Build()),
|
||||
ContentTypeOperationStatus.PropertyTypeAliasCannotEqualContentTypeAlias => new BadRequestObjectResult(problemDetailsBuilder
|
||||
.WithTitle("Invalid property type alias")
|
||||
.WithDetail("The property type alias cannot be the same as the content type alias")
|
||||
.Build()),
|
||||
ContentTypeOperationStatus.InvalidContainerName => new BadRequestObjectResult(problemDetailsBuilder
|
||||
.WithTitle("Invalid container name")
|
||||
.WithDetail("One or more container names are invalid")
|
||||
|
||||
@@ -200,6 +200,12 @@ internal abstract class ContentTypeEditingServiceBase<TContentType, TContentType
|
||||
return ContentTypeOperationStatus.InvalidAlias;
|
||||
}
|
||||
|
||||
// Validate content type alias is not in use.
|
||||
if (model.Properties.Any(propertyType => propertyType.Alias.Equals(model.Alias, StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
return ContentTypeOperationStatus.PropertyTypeAliasCannotEqualContentTypeAlias;
|
||||
}
|
||||
|
||||
// Validate properties for reserved aliases.
|
||||
if (ContainsReservedPropertyTypeAlias(model))
|
||||
{
|
||||
@@ -410,8 +416,7 @@ internal abstract class ContentTypeEditingServiceBase<TContentType, TContentType
|
||||
.Union(typeof(IPublishedContent).GetPublicMethods().Select(x => x.Name))
|
||||
.ToArray();
|
||||
|
||||
return model.Properties.Any(propertyType => propertyType.Alias.Equals(model.Alias, StringComparison.OrdinalIgnoreCase)
|
||||
|| reservedPropertyTypeNames.InvariantContains(propertyType.Alias));
|
||||
return model.Properties.Any(propertyType => reservedPropertyTypeNames.InvariantContains(propertyType.Alias));
|
||||
}
|
||||
|
||||
private bool IsUnsafeAlias(string alias) => alias.IsNullOrWhiteSpace()
|
||||
|
||||
@@ -6,6 +6,7 @@ public enum ContentTypeOperationStatus
|
||||
DuplicateAlias,
|
||||
InvalidAlias,
|
||||
InvalidPropertyTypeAlias,
|
||||
PropertyTypeAliasCannotEqualContentTypeAlias,
|
||||
DuplicatePropertyTypeAlias,
|
||||
DataTypeNotFound,
|
||||
InvalidInheritance,
|
||||
|
||||
@@ -774,7 +774,7 @@ public partial class ContentTypeEditingServiceTests
|
||||
|
||||
var result = await ContentTypeEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey);
|
||||
Assert.IsFalse(result.Success);
|
||||
Assert.AreEqual(ContentTypeOperationStatus.InvalidPropertyTypeAlias, result.Status);
|
||||
Assert.AreEqual(ContentTypeOperationStatus.PropertyTypeAliasCannotEqualContentTypeAlias, result.Status);
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
Reference in New Issue
Block a user