Sanitize content types .ContentTypeComposition and .PropertyTypes

This commit is contained in:
Stephan
2015-11-17 19:01:19 +01:00
parent ee72621042
commit 3fe235fa35
8 changed files with 41 additions and 46 deletions

View File

@@ -378,27 +378,25 @@ namespace Umbraco.Core.Models
}
/// <summary>
/// List of PropertyTypes available on this ContentType.
/// This list aggregates PropertyTypes across the PropertyGroups.
/// Gets all property types, across all property groups.
/// </summary>
/// <remarks>
///
/// The setter is used purely to set the property types that DO NOT belong to a group!
///
/// Marked as DoNotClone because the result of this property is not the natural result of the data, it is
/// a union of data so when auto-cloning if the setter is used it will be setting the unnatural result of the
/// data. We manually clone this instead.
/// </remarks>
[IgnoreDataMember]
[DoNotClone]
public virtual IEnumerable<PropertyType> PropertyTypes
{
get
{
var types = _propertyTypes.Union(PropertyGroups.SelectMany(x => x.PropertyTypes));
return types;
return _propertyTypes.Union(PropertyGroups.SelectMany(x => x.PropertyTypes));
}
internal set
}
/// <summary>
/// Gets or sets the property types that are not in a group.
/// </summary>
public IEnumerable<PropertyType> NoGroupPropertyTypes
{
get { return _propertyTypes; }
set
{
_propertyTypes = new PropertyTypeCollection(value);
_propertyTypes.CollectionChanged += PropertyTypesChanged;
@@ -406,14 +404,6 @@ namespace Umbraco.Core.Models
}
}
/// <summary>
/// Returns the property type collection containing types that are non-groups - used for tests
/// </summary>
internal IEnumerable<PropertyType> NonGroupedPropertyTypes
{
get { return _propertyTypes; }
}
/// <summary>
/// A boolean flag indicating if a property type has been removed from this instance.
/// </summary>

View File

@@ -37,16 +37,21 @@ namespace Umbraco.Core.Models
x => x.ContentTypeComposition);
/// <summary>
/// List of ContentTypes that make up a composition of PropertyGroups and PropertyTypes for the current ContentType
/// Gets or sets the content types that compose this content type.
/// </summary>
[DataMember]
public IEnumerable<IContentTypeComposition> ContentTypeComposition
{
get { return _contentTypeComposition; }
set
{
_contentTypeComposition = value.ToList();
OnPropertyChanged(ContentTypeCompositionSelector);
}
}
/// <summary>
/// Returns a list of <see cref="PropertyGroup"/> objects from the composition
/// Gets the property groups for the entire composition.
/// </summary>
[IgnoreDataMember]
public IEnumerable<PropertyGroup> CompositionPropertyGroups
@@ -59,7 +64,7 @@ namespace Umbraco.Core.Models
}
/// <summary>
/// Returns a list of <see cref="PropertyType"/> objects from the composition
/// Gets the property types for the entire composition.
/// </summary>
[IgnoreDataMember]
public IEnumerable<PropertyType> CompositionPropertyTypes
@@ -72,10 +77,10 @@ namespace Umbraco.Core.Models
}
/// <summary>
/// Adds a new ContentType to the list of composite ContentTypes
/// Adds a content type to the composition.
/// </summary>
/// <param name="contentType"><see cref="ContentType"/> to add</param>
/// <returns>True if ContentType was added, otherwise returns False</returns>
/// <param name="contentType">The content type to add.</param>
/// <returns>True if the content type was added, otherwise false.</returns>
public bool AddContentType(IContentTypeComposition contentType)
{
if (contentType.ContentTypeComposition.Any(x => x.CompositionAliases().Any(ContentTypeCompositionExists)))
@@ -104,10 +109,10 @@ namespace Umbraco.Core.Models
}
/// <summary>
/// Removes a ContentType with the supplied alias from the the list of composite ContentTypes
/// Removes a content type with a specified alias from the composition.
/// </summary>
/// <param name="alias">Alias of a <see cref="ContentType"/></param>
/// <returns>True if ContentType was removed, otherwise returns False</returns>
/// <param name="alias">The alias of the content type to remove.</param>
/// <returns>True if the content type was removed, otherwise false.</returns>
public bool RemoveContentType(string alias)
{
if (ContentTypeCompositionExists(alias))

View File

@@ -54,10 +54,15 @@ namespace Umbraco.Core.Models
PropertyGroupCollection PropertyGroups { get; set; }
/// <summary>
/// Gets an enumerable list of Property Types aggregated for all groups
/// Gets all property types, across all property groups.
/// </summary>
IEnumerable<PropertyType> PropertyTypes { get; }
/// <summary>
/// Gets or sets the property types that are not in a group.
/// </summary>
IEnumerable<PropertyType> NoGroupPropertyTypes { get; set; }
/// <summary>
/// Removes a PropertyType from the current ContentType
/// </summary>

View File

@@ -8,17 +8,17 @@ namespace Umbraco.Core.Models
public interface IContentTypeComposition : IContentTypeBase
{
/// <summary>
/// Gets a list of ContentTypes that make up a composition of PropertyGroups and PropertyTypes for the current ContentType
/// Gets or sets the content types that compose this content type.
/// </summary>
IEnumerable<IContentTypeComposition> ContentTypeComposition { get; }
IEnumerable<IContentTypeComposition> ContentTypeComposition { get; set; }
/// <summary>
/// Gets a list of <see cref="PropertyGroup"/> objects from the composition
/// Gets the property groups for the entire composition.
/// </summary>
IEnumerable<PropertyGroup> CompositionPropertyGroups { get; }
/// <summary>
/// Gets a list of <see cref="PropertyType"/> objects from the composition
/// Gets the property types for the entire composition.
/// </summary>
IEnumerable<PropertyType> CompositionPropertyTypes { get; }

View File

@@ -51,7 +51,7 @@ namespace Umbraco.Core.Persistence.Factories
memberType.MemberTypePropertyTypes.Add(standardPropertyType.Key,
new MemberTypePropertyProfileAccess(false, false));
}
memberType.PropertyTypes = propertyTypes;
memberType.NoGroupPropertyTypes = propertyTypes;
return memberType;
}

View File

@@ -671,7 +671,7 @@ AND umbracoNode.id <> @id",
foreach (var contentType in contentTypes)
{
contentType.PropertyGroups = allPropGroups[contentType.Id];
((ContentTypeBase)contentType).PropertyTypes = allPropTypes[contentType.Id];
contentType.NoGroupPropertyTypes = allPropTypes[contentType.Id];
}
//NOTE: SQL call #3++

View File

@@ -205,7 +205,7 @@ namespace Umbraco.Tests.Models
}
Assert.AreNotSame(clone.PropertyTypes, contentType.PropertyTypes);
Assert.AreEqual(clone.PropertyTypes.Count(), contentType.PropertyTypes.Count());
Assert.AreEqual(0, ((ContentTypeBase)clone).NonGroupedPropertyTypes.Count());
Assert.AreEqual(0, clone.NoGroupPropertyTypes.Count());
for (var index = 0; index < contentType.PropertyTypes.Count(); index++)
{
Assert.AreNotSame(clone.PropertyTypes.ElementAt(index), contentType.PropertyTypes.ElementAt(index));

View File

@@ -120,6 +120,7 @@ namespace Umbraco.Web.Models.Mapping
.ForMember(dto => dto.SortOrder, expression => expression.Ignore())
//ignore, we'll do this in after map
.ForMember(dto => dto.PropertyGroups, expression => expression.Ignore())
.ForMember(dto => dto.NoGroupPropertyTypes, expression => expression.Ignore())
.ForMember(
dto => dto.AllowedContentTypes,
@@ -145,7 +146,7 @@ namespace Umbraco.Web.Models.Mapping
// handle actual groups (non-generic-properties)
var destOrigGroups = dest.PropertyGroups.ToArray(); // local groups
var destOrigProperties = dest.PropertyTypes.ToArray(); // get_PropertyTypes returns grouped props too
var destOrigProperties = dest.PropertyTypes.ToArray(); // all properties, in groups or not
var destGroups = new List<PropertyGroup>();
var sourceGroups = source.Groups.Where(x => x.IsGenericProperties == false).ToArray();
foreach (var sourceGroup in sourceGroups)
@@ -189,13 +190,7 @@ namespace Umbraco.Web.Models.Mapping
// ensure no duplicate alias, then assign the generic properties collection
EnsureUniqueAliases(destProperties);
// set_PropertyTypes sets generic properties *only*
// this is all very awkward
var dest2 = dest as ContentTypeBase;
if (dest2 == null)
throw new InvalidOperationException("Cannot map if dest is not ContentTypeBase.");
dest2.PropertyTypes = new PropertyTypeCollection(destProperties);
dest.NoGroupPropertyTypes = new PropertyTypeCollection(destProperties);
}
// because all property collections were rebuilt, there is no need to remove