Moves ContentType, MemberType, MediaType, etc... less casting, less internals

This commit is contained in:
Shannon
2020-05-20 11:59:41 +10:00
parent d444dfd441
commit 8134a35fe0
11 changed files with 35 additions and 33 deletions

View File

@@ -65,11 +65,9 @@ namespace Umbraco.Core.Models
get { return AllowedTemplates.FirstOrDefault(x => x != null && x.Id == DefaultTemplateId); }
}
/// <summary>
/// Internal property to store the Id of the default template
/// </summary>
[DataMember]
internal int DefaultTemplateId
public int DefaultTemplateId
{
get => _defaultTemplate;
set => SetPropertyValueAndDetectChanges(value, ref _defaultTemplate, nameof(DefaultTemplateId));

View File

@@ -7,6 +7,11 @@ namespace Umbraco.Core.Models
/// </summary>
public interface IContentType : IContentTypeComposition
{
/// <summary>
/// Internal property to store the Id of the default template
/// </summary>
int DefaultTemplateId { get; set; }
/// <summary>
/// Gets the default Template of the ContentType
/// </summary>

View File

@@ -21,7 +21,7 @@ namespace Umbraco.Core.Models
public MemberType(IShortStringHelper shortStringHelper, int parentId) : base(shortStringHelper, parentId)
{
_shortStringHelper = shortStringHelper;
MemberTypePropertyTypes = new Dictionary<string, MemberTypePropertyProfileAccess>();
_memberTypePropertyTypes = new Dictionary<string, MemberTypePropertyProfileAccess>();
}
public MemberType(IShortStringHelper shortStringHelper, IContentTypeComposition parent) : this(shortStringHelper, parent, null)
@@ -32,7 +32,7 @@ namespace Umbraco.Core.Models
: base(shortStringHelper, parent, alias)
{
_shortStringHelper = shortStringHelper;
MemberTypePropertyTypes = new Dictionary<string, MemberTypePropertyProfileAccess>();
_memberTypePropertyTypes = new Dictionary<string, MemberTypePropertyProfileAccess>();
}
/// <inheritdoc />
@@ -80,8 +80,7 @@ namespace Umbraco.Core.Models
/// <summary>
/// Gets or Sets a Dictionary of Tuples (MemberCanEdit, VisibleOnProfile, IsSensitive) by the PropertyTypes' alias.
/// </summary>
[DataMember]
internal IDictionary<string, MemberTypePropertyProfileAccess> MemberTypePropertyTypes { get; private set; }
private IDictionary<string, MemberTypePropertyProfileAccess> _memberTypePropertyTypes;
/// <summary>
/// Gets a boolean indicating whether a Property is editable by the Member.
@@ -90,7 +89,7 @@ namespace Umbraco.Core.Models
/// <returns></returns>
public bool MemberCanEditProperty(string propertyTypeAlias)
{
return MemberTypePropertyTypes.TryGetValue(propertyTypeAlias, out var propertyProfile) && propertyProfile.IsEditable;
return _memberTypePropertyTypes.TryGetValue(propertyTypeAlias, out var propertyProfile) && propertyProfile.IsEditable;
}
/// <summary>
@@ -100,7 +99,7 @@ namespace Umbraco.Core.Models
/// <returns></returns>
public bool MemberCanViewProperty(string propertyTypeAlias)
{
return MemberTypePropertyTypes.TryGetValue(propertyTypeAlias, out var propertyProfile) && propertyProfile.IsVisible;
return _memberTypePropertyTypes.TryGetValue(propertyTypeAlias, out var propertyProfile) && propertyProfile.IsVisible;
}
/// <summary>
/// Gets a boolean indicating whether a Property is marked as storing sensitive values on the Members profile.
@@ -109,7 +108,7 @@ namespace Umbraco.Core.Models
/// <returns></returns>
public bool IsSensitiveProperty(string propertyTypeAlias)
{
return MemberTypePropertyTypes.TryGetValue(propertyTypeAlias, out var propertyProfile) && propertyProfile.IsSensitive;
return _memberTypePropertyTypes.TryGetValue(propertyTypeAlias, out var propertyProfile) && propertyProfile.IsSensitive;
}
/// <summary>
@@ -119,14 +118,14 @@ namespace Umbraco.Core.Models
/// <param name="value">Boolean value, true or false</param>
public void SetMemberCanEditProperty(string propertyTypeAlias, bool value)
{
if (MemberTypePropertyTypes.TryGetValue(propertyTypeAlias, out var propertyProfile))
if (_memberTypePropertyTypes.TryGetValue(propertyTypeAlias, out var propertyProfile))
{
propertyProfile.IsEditable = value;
}
else
{
var tuple = new MemberTypePropertyProfileAccess(false, value, false);
MemberTypePropertyTypes.Add(propertyTypeAlias, tuple);
_memberTypePropertyTypes.Add(propertyTypeAlias, tuple);
}
}
@@ -137,14 +136,14 @@ namespace Umbraco.Core.Models
/// <param name="value">Boolean value, true or false</param>
public void SetMemberCanViewProperty(string propertyTypeAlias, bool value)
{
if (MemberTypePropertyTypes.TryGetValue(propertyTypeAlias, out var propertyProfile))
if (_memberTypePropertyTypes.TryGetValue(propertyTypeAlias, out var propertyProfile))
{
propertyProfile.IsVisible = value;
}
else
{
var tuple = new MemberTypePropertyProfileAccess(value, false, false);
MemberTypePropertyTypes.Add(propertyTypeAlias, tuple);
_memberTypePropertyTypes.Add(propertyTypeAlias, tuple);
}
}
@@ -155,14 +154,14 @@ namespace Umbraco.Core.Models
/// <param name="value">Boolean value, true or false</param>
public void SetIsSensitiveProperty(string propertyTypeAlias, bool value)
{
if (MemberTypePropertyTypes.TryGetValue(propertyTypeAlias, out var propertyProfile))
if (_memberTypePropertyTypes.TryGetValue(propertyTypeAlias, out var propertyProfile))
{
propertyProfile.IsSensitive = value;
}
else
{
var tuple = new MemberTypePropertyProfileAccess(false, false, true);
MemberTypePropertyTypes.Add(propertyTypeAlias, tuple);
_memberTypePropertyTypes.Add(propertyTypeAlias, tuple);
}
}
}

View File

@@ -22,12 +22,6 @@ namespace Umbraco.Web.Models.ContentEditing
[DataMember(Name = "compositeContentTypes")]
public IEnumerable<string> CompositeContentTypes { get; set; }
[DataMember(Name = "isContainer")]
public bool IsContainer { get; set; }
[DataMember(Name = "isElement")]
public bool IsElement { get; set; }
[DataMember(Name = "allowAsRoot")]
public bool AllowAsRoot { get; set; }

View File

@@ -8,6 +8,8 @@ using Umbraco.Core.PropertyEditors;
namespace Umbraco.Core.Models
{
// TODO: This should exist within Umbraco.Core not infrastructure however there's a dependency on Newtonsoft here, how can we refactor that requirement?
/// <summary>
/// Implements <see cref="IDataType"/>.
/// </summary>

View File

@@ -136,7 +136,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
foreach (var c in contentTypes.Values)
{
if (!(c is ContentType contentType)) continue;
if (!(c is IContentType contentType)) continue;
// map allowed templates
var allowedTemplates = new List<ITemplate>();
@@ -247,7 +247,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
contentType.NoGroupPropertyTypes = noGroupPropertyTypes;
// ensure builtin properties
if (contentType is MemberType memberType)
if (contentType is IMemberType memberType)
{
// ensure that the group exists (ok if it already exists)
memberType.AddPropertyGroup(Constants.Conventions.Member.StandardPropertiesGroupName);
@@ -259,8 +259,9 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
if (added)
{
var access = new MemberTypePropertyProfileAccess(false, false, false);
memberType.MemberTypePropertyTypes[alias] = access;
memberType.SetIsSensitiveProperty(alias, false);
memberType.SetMemberCanEditProperty(alias, false);
memberType.SetMemberCanViewProperty(alias, false);
}
}
}
@@ -285,10 +286,11 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
var readonlyStorageType = builtinProperties.TryGetValue(dto.Alias, out var propertyType);
var storageType = readonlyStorageType ? propertyType.ValueStorageType : Enum<ValueStorageType>.Parse(dto.DataTypeDto.DbType);
if (contentType is MemberType memberType)
if (contentType is IMemberType memberType)
{
var access = new MemberTypePropertyProfileAccess(dto.ViewOnProfile, dto.CanEdit, dto.IsSensitive);
memberType.MemberTypePropertyTypes[dto.Alias] = access;
memberType.SetIsSensitiveProperty(dto.Alias, dto.IsSensitive);
memberType.SetMemberCanEditProperty(dto.Alias, dto.CanEdit);
memberType.SetMemberCanViewProperty(dto.Alias, dto.ViewOnProfile);
}
return new PropertyType(_shortStringHelper, dto.DataTypeDto.EditorAlias, storageType, readonlyStorageType, dto.Alias)

View File

@@ -247,7 +247,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
Database.Delete<ContentTypeTemplateDto>("WHERE contentTypeNodeId = @Id", new { Id = entity.Id });
// we could do it all in foreach if we assume that the default template is an allowed template??
var defaultTemplateId = ((ContentType) entity).DefaultTemplateId;
var defaultTemplateId = entity.DefaultTemplateId;
if (defaultTemplateId > 0)
{
Database.Insert(new ContentTypeTemplateDto

View File

@@ -275,7 +275,6 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Infrastructure.Models
Assert.AreEqual(clone.Thumbnail, contentType.Thumbnail);
Assert.AreEqual(clone.Icon, contentType.Icon);
Assert.AreEqual(clone.IsContainer, contentType.IsContainer);
Assert.AreEqual(clone.MemberTypePropertyTypes, contentType.MemberTypePropertyTypes);
// This double verifies by reflection
var allProps = clone.GetType().GetProperties();

View File

@@ -302,7 +302,10 @@ namespace Umbraco.Tests.Models.Mapping
// setup the mocks to return the data we want to test against...
var memberType = MockedContentTypes.CreateSimpleMemberType();
memberType.MemberTypePropertyTypes[memberType.PropertyTypes.Last().Alias] = new MemberTypePropertyProfileAccess(true, true, true);
var alias = memberType.PropertyTypes.Last().Alias;
memberType.SetIsSensitiveProperty(alias, true);
memberType.SetMemberCanEditProperty(alias, true);
memberType.SetMemberCanViewProperty(alias, true);
MockedContentTypes.EnsureAllIds(memberType, 8888);