AB4549 - Moved more models

This commit is contained in:
Bjarke Berg
2020-01-20 15:20:21 +01:00
parent 5a67e5b395
commit 9fa18fe9a3
36 changed files with 41 additions and 76 deletions

View File

@@ -1,217 +0,0 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Runtime.Serialization;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.Models.ContentEditing;
using Umbraco.Core.Serialization;
using Umbraco.Web.Routing;
namespace Umbraco.Web.Models.ContentEditing
{
/// <summary>
/// A model representing a content item to be displayed in the back office
/// </summary>
[DataContract(Name = "content", Namespace = "")]
public class ContentItemDisplay : INotificationModel, IErrorModel //ListViewAwareContentItemDisplayBase<ContentPropertyDisplay, IContent>
{
public ContentItemDisplay()
{
AllowPreview = true;
Notifications = new List<BackOfficeNotification>();
Errors = new Dictionary<string, object>();
Variants = new List<ContentVariantDisplay>();
ContentApps = new List<ContentApp>();
}
[DataMember(Name = "id", IsRequired = true)]
[Required]
public int Id { get; set; }
[DataMember(Name = "udi")]
[ReadOnly(true)]
[JsonConverter(typeof(UdiJsonConverter))]
public Udi Udi { get; set; }
[DataMember(Name = "icon")]
public string Icon { get; set; }
[DataMember(Name = "trashed")]
[ReadOnly(true)]
public bool Trashed { get; set; }
/// <summary>
/// This is the unique Id stored in the database - but could also be the unique id for a custom membership provider
/// </summary>
[DataMember(Name = "key")]
public Guid Key { get; set; }
[DataMember(Name = "parentId", IsRequired = true)]
[Required]
public int ParentId { get; set; }
/// <summary>
/// The path of the entity
/// </summary>
[DataMember(Name = "path")]
public string Path { get; set; }
/// <summary>
/// A collection of content variants
/// </summary>
/// <remarks>
/// If a content item is invariant, this collection will only contain one item, else it will contain all culture variants
/// </remarks>
[DataMember(Name = "variants")]
public IEnumerable<ContentVariantDisplay> Variants { get; set; }
[DataMember(Name = "owner")]
public UserProfile Owner { get; set; }
[DataMember(Name = "updater")]
public UserProfile Updater { get; set; }
/// <summary>
/// The name of the content type
/// </summary>
[DataMember(Name = "contentTypeName")]
public string ContentTypeName { get; set; }
/// <summary>
/// Indicates if the content is configured as a list view container
/// </summary>
[DataMember(Name = "isContainer")]
public bool IsContainer { get; set; }
/// <summary>
/// Indicates if the content is configured as an element
/// </summary>
[DataMember(Name = "isElement")]
public bool IsElement { get; set; }
/// <summary>
/// Property indicating if this item is part of a list view parent
/// </summary>
[DataMember(Name = "isChildOfListView")]
public bool IsChildOfListView { get; set; }
/// <summary>
/// Property for the entity's individual tree node URL
/// </summary>
/// <remarks>
/// This is required if the item is a child of a list view since the tree won't actually be loaded,
/// so the app will need to go fetch the individual tree node in order to be able to load it's action list (menu)
/// </remarks>
[DataMember(Name = "treeNodeUrl")]
public string TreeNodeUrl { get; set; }
[DataMember(Name = "contentTypeId")]
public int ContentTypeId { get; set; }
[DataMember(Name = "contentTypeAlias", IsRequired = true)]
[Required(AllowEmptyStrings = false)]
public string ContentTypeAlias { get; set; }
[DataMember(Name = "sortOrder")]
public int SortOrder { get; set; }
/// <summary>
/// This is the last updated date for the entire content object regardless of variants
/// </summary>
/// <remarks>
/// Each variant has it's own update date assigned as well
/// </remarks>
[DataMember(Name = "updateDate")]
public DateTime UpdateDate { get; set; }
[DataMember(Name = "template")]
public string TemplateAlias { get; set; }
[DataMember(Name = "templateId")]
public int TemplateId { get; set; }
[DataMember(Name = "allowedTemplates")]
public IDictionary<string, string> AllowedTemplates { get; set; }
[DataMember(Name = "documentType")]
public ContentTypeBasic DocumentType { get; set; }
[DataMember(Name = "urls")]
public UrlInfo[] Urls { get; set; }
/// <summary>
/// Determines whether previewing is allowed for this node
/// </summary>
/// <remarks>
/// By default this is true but by using events developers can toggle this off for certain documents if there is nothing to preview
/// </remarks>
[DataMember( Name = "allowPreview" )]
public bool AllowPreview { get; set; }
/// <summary>
/// The allowed 'actions' based on the user's permissions - Create, Update, Publish, Send to publish
/// </summary>
/// <remarks>
/// Each char represents a button which we can then map on the front-end to the correct actions
/// </remarks>
[DataMember(Name = "allowedActions")]
public IEnumerable<string> AllowedActions { get; set; }
[DataMember(Name = "isBlueprint")]
public bool IsBlueprint { get; set; }
[DataMember(Name = "apps")]
public IEnumerable<ContentApp> ContentApps { get; set; }
/// <summary>
/// The real persisted content object - used during inbound model binding
/// </summary>
/// <remarks>
/// This is not used for outgoing model information.
/// </remarks>
[IgnoreDataMember]
internal IContent PersistedContent { get; set; }
/// <summary>
/// The DTO object used to gather all required content data including data type information etc... for use with validation - used during inbound model binding
/// </summary>
/// <remarks>
/// We basically use this object to hydrate all required data from the database into one object so we can validate everything we need
/// instead of having to look up all the data individually.
/// This is not used for outgoing model information.
/// </remarks>
[IgnoreDataMember]
internal ContentPropertyCollectionDto ContentDto { get; set; }
/// <summary>
/// This is used to add custom localized messages/strings to the response for the app to use for localized UI purposes.
/// </summary>
[DataMember(Name = "notifications")]
[ReadOnly(true)]
public List<BackOfficeNotification> Notifications { get; private set; }
/// <summary>
/// This is used for validation of a content item.
/// </summary>
/// <remarks>
/// A content item can be invalid but still be saved. This occurs when there's property validation errors, we will
/// still save the item but it cannot be published. So we need a way of returning validation errors as well as the
/// updated model.
///
/// NOTE: The ProperCase is important because when we return ModeState normally it will always be proper case.
/// </remarks>
[DataMember(Name = "ModelState")]
[ReadOnly(true)]
public IDictionary<string, object> Errors { get; set; }
/// <summary>
/// A collection of extra data that is available for this specific entity/entity type
/// </summary>
[DataMember(Name = "metaData")]
[ReadOnly(true)]
public IDictionary<string, object> AdditionalData { get; private set; }
}
}

View File

@@ -1,69 +0,0 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Runtime.Serialization;
using Newtonsoft.Json;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Editors;
namespace Umbraco.Web.Models.ContentEditing
{
/// <summary>
/// A model representing a content item to be saved
/// </summary>
[DataContract(Name = "content", Namespace = "")]
public class ContentItemSave : IContentSave<IContent>
{
protected ContentItemSave()
{
UploadedFiles = new List<ContentPropertyFile>();
Variants = new List<ContentVariantSave>();
}
[DataMember(Name = "id", IsRequired = true)]
[Required]
public int Id { get; set; }
[DataMember(Name = "parentId", IsRequired = true)]
[Required]
public int ParentId { get; set; }
[DataMember(Name = "variants", IsRequired = true)]
public IEnumerable<ContentVariantSave> Variants { get; set; }
[DataMember(Name = "contentTypeAlias", IsRequired = true)]
[Required(AllowEmptyStrings = false)]
public string ContentTypeAlias { get; set; }
/// <summary>
/// The template alias to save
/// </summary>
[DataMember(Name = "templateAlias")]
public string TemplateAlias { get; set; }
#region IContentSave
[DataMember(Name = "action", IsRequired = true)]
[Required]
public ContentSaveAction Action { get; set; }
[IgnoreDataMember]
public List<ContentPropertyFile> UploadedFiles { get; }
//These need explicit implementation because we are using internal models
/// <inheritdoc />
[IgnoreDataMember]
IContent IContentSave<IContent>.PersistedContent { get; set; }
//Non explicit internal getter so we don't need to explicitly cast in our own code
[IgnoreDataMember]
internal IContent PersistedContent
{
get => ((IContentSave<IContent>)this).PersistedContent;
set => ((IContentSave<IContent>)this).PersistedContent = value;
}
#endregion
}
}

View File

@@ -1,125 +0,0 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Runtime.Serialization;
using Umbraco.Core;
using Umbraco.Web.Composing;
namespace Umbraco.Web.Models.ContentEditing
{
/// <summary>
/// A basic version of a content type
/// </summary>
/// <remarks>
/// Generally used to return the minimal amount of data about a content type
/// </remarks>
[DataContract(Name = "contentType", Namespace = "")]
public class ContentTypeBasic : EntityBasic
{
public ContentTypeBasic()
{
Blueprints = new Dictionary<int, string>();
}
/// <summary>
/// Overridden to apply our own validation attributes since this is not always required for other classes
/// </summary>
[Required]
[RegularExpression(@"^([a-zA-Z]\w.*)$", ErrorMessage = "Invalid alias")]
[DataMember(Name = "alias")]
public override string Alias { get; set; }
[DataMember(Name = "updateDate")]
[ReadOnly(true)]
public DateTime UpdateDate { get; set; }
[DataMember(Name = "createDate")]
[ReadOnly(true)]
public DateTime CreateDate { get; set; }
[DataMember(Name = "description")]
public string Description { get; set; }
[DataMember(Name = "thumbnail")]
public string Thumbnail { get; set; }
/// <summary>
/// Returns true if the icon represents a CSS class instead of a file path
/// </summary>
[DataMember(Name = "iconIsClass")]
[ReadOnly(true)]
public bool IconIsClass
{
get
{
if (Icon.IsNullOrWhiteSpace())
{
return true;
}
//if it starts with a '.' or doesn't contain a '.' at all then it is a class
return Icon.StartsWith(".") || Icon.Contains(".") == false;
}
}
/// <summary>
/// Returns the icon file path if the icon is not a class, otherwise returns an empty string
/// </summary>
[DataMember(Name = "iconFilePath")]
[ReadOnly(true)]
public string IconFilePath
{
get
{
return IconIsClass
? string.Empty
: string.Format("{0}images/umbraco/{1}", Current.Configs.Global().Path.EnsureEndsWith("/"), Icon);
}
}
/// <summary>
/// Returns true if the icon represents a CSS class instead of a file path
/// </summary>
[DataMember(Name = "thumbnailIsClass")]
[ReadOnly(true)]
public bool ThumbnailIsClass
{
get
{
if (Thumbnail.IsNullOrWhiteSpace())
{
return true;
}
//if it starts with a '.' or doesn't contain a '.' at all then it is a class
return Thumbnail.StartsWith(".") || Thumbnail.Contains(".") == false;
}
}
/// <summary>
/// Returns the icon file path if the icon is not a class, otherwise returns an empty string
/// </summary>
[DataMember(Name = "thumbnailFilePath")]
[ReadOnly(true)]
public string ThumbnailFilePath
{
get
{
return ThumbnailIsClass
? string.Empty
: Current.IOHelper.ResolveUrl("~/umbraco/images/thumbnails/" + Thumbnail);
}
}
[DataMember(Name = "blueprints")]
[ReadOnly(true)]
public IDictionary<int, string> Blueprints { get; set; }
[DataMember(Name = "isContainer")]
[ReadOnly(true)]
public bool IsContainer { get; set; }
[DataMember(Name = "isElement")]
[ReadOnly(true)]
public bool IsElement { get; set; }
}
}

View File

@@ -1,74 +0,0 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.Serialization;
namespace Umbraco.Web.Models.ContentEditing
{
public abstract class ContentTypeCompositionDisplay : ContentTypeBasic, INotificationModel
{
protected ContentTypeCompositionDisplay()
{
//initialize collections so at least their never null
AllowedContentTypes = new List<int>();
CompositeContentTypes = new List<string>();
Notifications = new List<BackOfficeNotification>();
}
//name, alias, icon, thumb, desc, inherited from basic
[DataMember(Name = "listViewEditorName")]
[ReadOnly(true)]
public string ListViewEditorName { get; set; }
//Allowed child types
[DataMember(Name = "allowedContentTypes")]
public IEnumerable<int> AllowedContentTypes { get; set; }
//Compositions
[DataMember(Name = "compositeContentTypes")]
public IEnumerable<string> CompositeContentTypes { get; set; }
//Locked compositions
[DataMember(Name = "lockedCompositeContentTypes")]
public IEnumerable<string> LockedCompositeContentTypes { get; set; }
[DataMember(Name = "allowAsRoot")]
public bool AllowAsRoot { get; set; }
/// <summary>
/// This is used to add custom localized messages/strings to the response for the app to use for localized UI purposes.
/// </summary>
[DataMember(Name = "notifications")]
[ReadOnly(true)]
public List<BackOfficeNotification> Notifications { get; private set; }
/// <summary>
/// This is used for validation of a content item.
/// </summary>
/// <remarks>
/// A content item can be invalid but still be saved. This occurs when there's property validation errors, we will
/// still save the item but it cannot be published. So we need a way of returning validation errors as well as the
/// updated model.
///
/// NOTE: The ProperCase is important because when we return ModeState normally it will always be proper case.
/// </remarks>
[DataMember(Name = "ModelState")]
[ReadOnly(true)]
public IDictionary<string, object> Errors { get; set; }
}
[DataContract(Name = "contentType", Namespace = "")]
public abstract class ContentTypeCompositionDisplay<TPropertyTypeDisplay> : ContentTypeCompositionDisplay
where TPropertyTypeDisplay : PropertyTypeDisplay
{
protected ContentTypeCompositionDisplay()
{
//initialize collections so at least their never null
Groups = new List<PropertyGroupDisplay<TPropertyTypeDisplay>>();
}
//Tabs
[DataMember(Name = "groups")]
public IEnumerable<PropertyGroupDisplay<TPropertyTypeDisplay>> Groups { get; set; }
}
}

View File

@@ -1,114 +0,0 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Runtime.Serialization;
using Umbraco.Core;
namespace Umbraco.Web.Models.ContentEditing
{
/// <summary>
/// Abstract model used to save content types
/// </summary>
[DataContract(Name = "contentType", Namespace = "")]
public abstract class ContentTypeSave : ContentTypeBasic, IValidatableObject
{
protected ContentTypeSave()
{
AllowedContentTypes = new List<int>();
CompositeContentTypes = new List<string>();
}
//Compositions
[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; }
//Allowed child types
[DataMember(Name = "allowedContentTypes")]
public IEnumerable<int> AllowedContentTypes { get; set; }
/// <summary>
/// Custom validation
/// </summary>
/// <param name="validationContext"></param>
/// <returns></returns>
public virtual IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
if (CompositeContentTypes.Any(x => x.IsNullOrWhiteSpace()))
yield return new ValidationResult("Composite Content Type value cannot be null", new[] {"CompositeContentTypes"});
}
}
/// <summary>
/// Abstract model used to save content types
/// </summary>
/// <typeparam name="TPropertyType"></typeparam>
[DataContract(Name = "contentType", Namespace = "")]
public abstract class ContentTypeSave<TPropertyType> : ContentTypeSave
where TPropertyType : PropertyTypeBasic
{
protected ContentTypeSave()
{
Groups = new List<PropertyGroupBasic<TPropertyType>>();
}
/// <summary>
/// A rule for defining how a content type can be varied
/// </summary>
/// <remarks>
/// This is only supported on document types right now but in the future it could be media types too
/// </remarks>
[DataMember(Name = "allowCultureVariant")]
public bool AllowCultureVariant { get; set; }
//Tabs
[DataMember(Name = "groups")]
public IEnumerable<PropertyGroupBasic<TPropertyType>> Groups { get; set; }
/// <summary>
/// Custom validation
/// </summary>
/// <param name="validationContext"></param>
/// <returns></returns>
public override IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
foreach (var validationResult in base.Validate(validationContext))
{
yield return validationResult;
}
var duplicateGroups = Groups.GroupBy(x => x.Name).Where(x => x.Count() > 1).ToArray();
if (duplicateGroups.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 names not allowed", new[]
{
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())
{
//we need to return the field name with an index so it's wired up correctly
var lastProperty = duplicateProperties.Last().Last();
var propertyGroup = Groups.Single(x => x.Properties.Contains(lastProperty));
yield return new ValidationResult("Duplicate property aliases not allowed: " + lastProperty.Alias, new[]
{
string.Format("Groups[{0}].Properties[{1}].Alias", propertyGroup.SortOrder, lastProperty.SortOrder)
});
}
}
}
}

View File

@@ -1,68 +0,0 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Runtime.Serialization;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Validation;
namespace Umbraco.Web.Models.ContentEditing
{
[DataContract(Name = "contentVariant", Namespace = "")]
public class ContentVariantSave : IContentProperties<ContentPropertyBasic>
{
public ContentVariantSave()
{
Properties = new List<ContentPropertyBasic>();
}
[DataMember(Name = "name", IsRequired = true)]
[RequiredForPersistence(AllowEmptyStrings = false, ErrorMessage = "Required")]
[MaxLength(255, ErrorMessage ="Name must be less than 255 characters")]
public string Name { get; set; }
[DataMember(Name = "properties")]
public IEnumerable<ContentPropertyBasic> Properties { get; set; }
/// <summary>
/// The culture of this variant, if this is invariant than this is null or empty
/// </summary>
[DataMember(Name = "culture")]
public string Culture { get; set; }
/// <summary>
/// Indicates if the variant should be updated
/// </summary>
/// <remarks>
/// If this is false, this variant data will not be updated at all
/// </remarks>
[DataMember(Name = "save")]
public bool Save { get; set; }
/// <summary>
/// Indicates if the variant should be published
/// </summary>
/// <remarks>
/// This option will have no affect if <see cref="Save"/> is false.
/// This is not used to unpublish.
/// </remarks>
[DataMember(Name = "publish")]
public bool Publish { get; set; }
[DataMember(Name = "expireDate")]
public DateTime? ExpireDate { get; set; }
[DataMember(Name = "releaseDate")]
public DateTime? ReleaseDate { get; set; }
/// <summary>
/// The property DTO object is used to gather all required property data including data type information etc... for use with validation - used during inbound model binding
/// </summary>
/// <remarks>
/// We basically use this object to hydrate all required data from the database into one object so we can validate everything we need
/// instead of having to look up all the data individually.
/// This is not used for outgoing model information.
/// </remarks>
[IgnoreDataMember]
internal ContentPropertyCollectionDto PropertyCollectionDto { get; set; }
}
}

View File

@@ -1,27 +0,0 @@
using System.ComponentModel;
using System.Runtime.Serialization;
namespace Umbraco.Web.Models.ContentEditing
{
/// <summary>
/// The basic data type information
/// </summary>
[DataContract(Name = "dataType", Namespace = "")]
public class DataTypeBasic : EntityBasic
{
/// <summary>
/// Whether or not this is a system data type, in which case it cannot be deleted
/// </summary>
[DataMember(Name = "isSystem")]
[ReadOnly(true)]
public bool IsSystemDataType { get; set; }
[DataMember(Name = "group")]
[ReadOnly(true)]
public string Group { get; set; }
[DataMember(Name = "hasPrevalues")]
[ReadOnly(true)]
public bool HasPrevalues { get; set; }
}
}

View File

@@ -1,43 +0,0 @@
using System.Collections.Generic;
using System.Runtime.Serialization;
namespace Umbraco.Web.Models.ContentEditing
{
/// <summary>
/// Represents a datatype configuration field model for editing.
/// </summary>
[DataContract(Name = "preValue", Namespace = "")]
public class DataTypeConfigurationFieldDisplay : DataTypeConfigurationFieldSave
{
/// <summary>
/// The name to display for this pre-value field
/// </summary>
[DataMember(Name = "label", IsRequired = true)]
public string Name { get; set; }
/// <summary>
/// The description to display for this pre-value field
/// </summary>
[DataMember(Name = "description")]
public string Description { get; set; }
/// <summary>
/// Specifies whether to hide the label for the pre-value
/// </summary>
[DataMember(Name = "hideLabel")]
public bool HideLabel { get; set; }
/// <summary>
/// The view to render for the field
/// </summary>
[DataMember(Name = "view", IsRequired = true)]
public string View { get; set; }
/// <summary>
/// This allows for custom configuration to be injected into the pre-value editor
/// </summary>
[DataMember(Name = "config")]
public IDictionary<string, object> Config { get; set; }
}
}

View File

@@ -1,39 +0,0 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Runtime.Serialization;
namespace Umbraco.Web.Models.ContentEditing
{
/// <summary>
/// Represents a data type that is being edited
/// </summary>
[DataContract(Name = "dataType", Namespace = "")]
public class DataTypeDisplay : DataTypeBasic, INotificationModel
{
public DataTypeDisplay()
{
Notifications = new List<BackOfficeNotification>();
}
/// <summary>
/// The alias of the property editor
/// </summary>
[DataMember(Name = "selectedEditor", IsRequired = true)]
[Required]
public string SelectedEditor { get; set; }
[DataMember(Name = "availableEditors")]
public IEnumerable<PropertyEditorBasic> AvailableEditors { get; set; }
[DataMember(Name = "preValues")]
public IEnumerable<DataTypeConfigurationFieldDisplay> PreValues { get; set; }
/// <summary>
/// This is used to add custom localized messages/strings to the response for the app to use for localized UI purposes.
/// </summary>
[DataMember(Name = "notifications")]
public List<BackOfficeNotification> Notifications { get; private set; }
}
}

View File

@@ -1,28 +0,0 @@
using System.Collections.Generic;
using System.Runtime.Serialization;
namespace Umbraco.Web.Models.ContentEditing
{
[DataContract(Name = "contentType", Namespace = "")]
public class DocumentTypeDisplay : ContentTypeCompositionDisplay<PropertyTypeDisplay>
{
public DocumentTypeDisplay()
{
//initialize collections so at least their never null
AllowedTemplates = new List<EntityBasic>();
}
//name, alias, icon, thumb, desc, inherited from the content type
// Templates
[DataMember(Name = "allowedTemplates")]
public IEnumerable<EntityBasic> AllowedTemplates { get; set; }
[DataMember(Name = "defaultTemplate")]
public EntityBasic DefaultTemplate { get; set; }
[DataMember(Name = "allowCultureVariant")]
public bool AllowCultureVariant { get; set; }
}
}

View File

@@ -1,43 +0,0 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Runtime.Serialization;
using Umbraco.Core;
namespace Umbraco.Web.Models.ContentEditing
{
/// <summary>
/// Model used to save a document type
/// </summary>
[DataContract(Name = "contentType", Namespace = "")]
public class DocumentTypeSave : ContentTypeSave<PropertyTypeBasic>
{
/// <summary>
/// The list of allowed templates to assign (template alias)
/// </summary>
[DataMember(Name = "allowedTemplates")]
public IEnumerable<string> AllowedTemplates { get; set; }
/// <summary>
/// The default template to assign (template alias)
/// </summary>
[DataMember(Name = "defaultTemplate")]
public string DefaultTemplate { get; set; }
/// <summary>
/// Custom validation
/// </summary>
/// <param name="validationContext"></param>
/// <returns></returns>
public override IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
if (AllowedTemplates.Any(x => x.IsNullOrWhiteSpace()))
yield return new ValidationResult("Template value cannot be null", new[] { "AllowedTemplates" });
foreach (var v in base.Validate(validationContext))
{
yield return v;
}
}
}
}

View File

@@ -1,29 +0,0 @@
using System.Runtime.Serialization;
using Umbraco.Core.Models;
namespace Umbraco.Web.Models.ContentEditing
{
/// <summary>
/// An abstract model representing a content item that can be contained in a list view
/// </summary>
/// <typeparam name="T"></typeparam>
public abstract class ListViewAwareContentItemDisplayBase<T> : ContentItemDisplayBase<T>
where T : ContentPropertyBasic
{
/// <summary>
/// Property indicating if this item is part of a list view parent
/// </summary>
[DataMember(Name = "isChildOfListView")]
public bool IsChildOfListView { get; set; }
/// <summary>
/// Property for the entity's individual tree node URL
/// </summary>
/// <remarks>
/// This is required if the item is a child of a list view since the tree won't actually be loaded,
/// so the app will need to go fetch the individual tree node in order to be able to load it's action list (menu)
/// </remarks>
[DataMember(Name = "treeNodeUrl")]
public string TreeNodeUrl { get; set; }
}
}

View File

@@ -1,67 +0,0 @@
using System.Collections.Generic;
using System.Runtime.Serialization;
namespace Umbraco.Web.Models.ContentEditing
{
/// <summary>
/// The macro display model
/// </summary>
[DataContract(Name = "dictionary", Namespace = "")]
public class MacroDisplay : EntityBasic, INotificationModel
{
/// <summary>
/// Initializes a new instance of the <see cref="MacroDisplay"/> class.
/// </summary>
public MacroDisplay()
{
this.Notifications = new List<BackOfficeNotification>();
this.Parameters = new List<MacroParameterDisplay>();
}
/// <inheritdoc />
[DataMember(Name = "notifications")]
public List<BackOfficeNotification> Notifications { get; }
/// <summary>
/// Gets or sets a value indicating whether the macro can be used in a rich text editor.
/// </summary>
[DataMember(Name = "useInEditor")]
public bool UseInEditor { get; set; }
/// <summary>
/// Gets or sets a value indicating whether the macro should be rendered a rich text editor.
/// </summary>
[DataMember(Name = "renderInEditor")]
public bool RenderInEditor { get; set; }
/// <summary>
/// Gets or sets the cache period.
/// </summary>
[DataMember(Name = "cachePeriod")]
public int CachePeriod { get; set; }
/// <summary>
/// Gets or sets a value indicating whether the macro should be cached by page
/// </summary>
[DataMember(Name = "cacheByPage")]
public bool CacheByPage { get; set; }
/// <summary>
/// Gets or sets a value indicating whether the macro should be cached by user
/// </summary>
[DataMember(Name = "cacheByUser")]
public bool CacheByUser { get; set; }
/// <summary>
/// Gets or sets the view.
/// </summary>
[DataMember(Name = "view")]
public string View { get; set; }
/// <summary>
/// Gets or sets the parameters.
/// </summary>
[DataMember(Name = "parameters")]
public IEnumerable<MacroParameterDisplay> Parameters { get; set; }
}
}

View File

@@ -1,29 +0,0 @@
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using Umbraco.Core.Models;
using Umbraco.Core.Models.ContentEditing;
namespace Umbraco.Web.Models.ContentEditing
{
/// <summary>
/// A model representing a content item to be displayed in the back office
/// </summary>
[DataContract(Name = "content", Namespace = "")]
public class MediaItemDisplay : ListViewAwareContentItemDisplayBase<ContentPropertyDisplay>
{
public MediaItemDisplay()
{
ContentApps = new List<ContentApp>();
}
[DataMember(Name = "contentType")]
public ContentTypeBasic ContentType { get; set; }
[DataMember(Name = "mediaLink")]
public string MediaLink { get; set; }
[DataMember(Name = "apps")]
public IEnumerable<ContentApp> ContentApps { get; set; }
}
}

View File

@@ -1,14 +0,0 @@
using System.Runtime.Serialization;
using Umbraco.Core.Models;
using Umbraco.Web.WebApi.Filters;
namespace Umbraco.Web.Models.ContentEditing
{
/// <summary>
/// A model representing a media item to be saved
/// </summary>
[DataContract(Name = "content", Namespace = "")]
public class MediaItemSave : ContentBaseSave<IMedia>
{
}
}

View File

@@ -1,10 +0,0 @@
using System.Runtime.Serialization;
namespace Umbraco.Web.Models.ContentEditing
{
[DataContract(Name = "contentType", Namespace = "")]
public class MediaTypeDisplay : ContentTypeCompositionDisplay<PropertyTypeDisplay>
{
}
}

View File

@@ -1,12 +0,0 @@
using System.Runtime.Serialization;
namespace Umbraco.Web.Models.ContentEditing
{
/// <summary>
/// Model used to save a media type
/// </summary>
[DataContract(Name = "contentType", Namespace = "")]
public class MediaTypeSave : ContentTypeSave<PropertyTypeBasic>
{
}
}

View File

@@ -1,17 +0,0 @@
using System.Runtime.Serialization;
using Umbraco.Core.Models;
namespace Umbraco.Web.Models.ContentEditing
{
/// <summary>
/// Used for basic member information
/// </summary>
public class MemberBasic : ContentItemBasic<ContentPropertyBasic>
{
[DataMember(Name = "username")]
public string Username { get; set; }
[DataMember(Name = "email")]
public string Email { get; set; }
}
}

View File

@@ -1,41 +0,0 @@
using System.Collections.Generic;
using System.Runtime.Serialization;
using Umbraco.Core.Models;
using Umbraco.Core.Models.ContentEditing;
using Umbraco.Core.Models.Membership;
namespace Umbraco.Web.Models.ContentEditing
{
/// <summary>
/// A model representing a member to be displayed in the back office
/// </summary>
[DataContract(Name = "content", Namespace = "")]
public class MemberDisplay : ListViewAwareContentItemDisplayBase<ContentPropertyDisplay>
{
public MemberDisplay()
{
// MemberProviderFieldMapping = new Dictionary<string, string>();
ContentApps = new List<ContentApp>();
}
[DataMember(Name = "username")]
public string Username { get; set; }
[DataMember(Name = "email")]
public string Email { get; set; }
//[DataMember(Name = "membershipScenario")]
//public MembershipScenario MembershipScenario { get; set; }
// /// <summary>
// /// This is used to indicate how to map the membership provider properties to the save model, this mapping
// /// will change if a developer has opted to have custom member property aliases specified in their membership provider config,
// /// or if we are editing a member that is not an Umbraco member (custom provider)
// /// </summary>
// [DataMember(Name = "fieldConfig")]
// public IDictionary<string, string> MemberProviderFieldMapping { get; set; }
[DataMember(Name = "apps")]
public IEnumerable<ContentApp> ContentApps { get; set; }
}
}

View File

@@ -1,17 +0,0 @@
using System.Collections.Generic;
using System.Runtime.Serialization;
using Umbraco.Core.Models;
using Umbraco.Core.Models.ContentEditing;
namespace Umbraco.Web.Models.ContentEditing
{
/// <summary>
/// A model representing a member list to be displayed in the back office
/// </summary>
[DataContract(Name = "content", Namespace = "")]
public class MemberListDisplay : ContentItemDisplayBase<ContentPropertyDisplay>
{
[DataMember(Name = "apps")]
public IEnumerable<ContentApp> ContentApps { get; set; }
}
}

View File

@@ -1,20 +0,0 @@
using System.Runtime.Serialization;
namespace Umbraco.Web.Models.ContentEditing
{
/// <summary>
/// Basic member property type
/// </summary>
[DataContract(Name = "contentType", Namespace = "")]
public class MemberPropertyTypeBasic : PropertyTypeBasic
{
[DataMember(Name = "showOnMemberProfile")]
public bool MemberCanViewProperty { get; set; }
[DataMember(Name = "memberCanEdit")]
public bool MemberCanEditProperty { get; set; }
[DataMember(Name = "isSensitiveData")]
public bool IsSensitiveData { get; set; }
}
}

View File

@@ -1,17 +0,0 @@
using System.Runtime.Serialization;
namespace Umbraco.Web.Models.ContentEditing
{
[DataContract(Name = "propertyType")]
public class MemberPropertyTypeDisplay : PropertyTypeDisplay
{
[DataMember(Name = "showOnMemberProfile")]
public bool MemberCanViewProperty { get; set; }
[DataMember(Name = "memberCanEdit")]
public bool MemberCanEditProperty { get; set; }
[DataMember(Name = "isSensitiveData")]
public bool IsSensitiveData { get; set; }
}
}

View File

@@ -1,57 +0,0 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Runtime.Serialization;
using Newtonsoft.Json.Linq;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Editors;
using Umbraco.Core.Models.Validation;
using Umbraco.Web.WebApi.Filters;
using Umbraco.Core;
namespace Umbraco.Web.Models.ContentEditing
{
/// <inheritdoc />
public class MemberSave : ContentBaseSave<IMember>
{
[DataMember(Name = "username", IsRequired = true)]
[RequiredForPersistence(AllowEmptyStrings = false, ErrorMessage = "Required")]
public string Username { get; set; }
[DataMember(Name = "email", IsRequired = true)]
[RequiredForPersistence(AllowEmptyStrings = false, ErrorMessage = "Required")]
[EmailAddress]
public string Email { get; set; }
[DataMember(Name = "password")]
public ChangingPasswordModel Password { get; set; }
[DataMember(Name = "memberGroups")]
public IEnumerable<string> Groups { get; set; }
/// <summary>
/// Returns the value from the Comments property
/// </summary>
public string Comments => GetPropertyValue<string>(Constants.Conventions.Member.Comments);
/// <summary>
/// Returns the value from the IsLockedOut property
/// </summary>
public bool IsLockedOut => GetPropertyValue<bool>(Constants.Conventions.Member.IsLockedOut);
/// <summary>
/// Returns the value from the IsApproved property
/// </summary>
public bool IsApproved => GetPropertyValue<bool>(Constants.Conventions.Member.IsApproved);
private T GetPropertyValue<T>(string alias)
{
var prop = Properties.FirstOrDefault(x => x.Alias == alias);
if (prop == null) return default;
var converted = prop.Value.TryConvertTo<T>();
return converted.ResultOr(default);
}
}
}

View File

@@ -1,10 +0,0 @@
using System.Runtime.Serialization;
namespace Umbraco.Web.Models.ContentEditing
{
[DataContract(Name = "contentType", Namespace = "")]
public class MemberTypeDisplay : ContentTypeCompositionDisplay<MemberPropertyTypeDisplay>
{
}
}

View File

@@ -1,10 +0,0 @@
namespace Umbraco.Web.Models.ContentEditing
{
/// <summary>
/// Model used to save a member type
/// </summary>
public class MemberTypeSave : ContentTypeSave<MemberPropertyTypeBasic>
{
}
}

View File

@@ -1,71 +0,0 @@

using System.Linq;
using Umbraco.Core;
namespace Umbraco.Web.Models.ContentEditing
{
public static class MessagesExtensions
{
public static void AddNotification(this INotificationModel model, string header, string msg, NotificationStyle type)
{
if (model.Exists(header, msg, type)) return;
model.Notifications.Add(new BackOfficeNotification()
{
Header = header,
Message = msg,
NotificationType = type
});
}
public static void AddSuccessNotification(this INotificationModel model, string header, string msg)
{
if (model.Exists(header, msg, NotificationStyle.Success)) return;
model.Notifications.Add(new BackOfficeNotification()
{
Header = header,
Message = msg,
NotificationType = NotificationStyle.Success
});
}
public static void AddErrorNotification(this INotificationModel model, string header, string msg)
{
if (model.Exists(header, msg, NotificationStyle.Error)) return;
model.Notifications.Add(new BackOfficeNotification()
{
Header = header,
Message = msg,
NotificationType = NotificationStyle.Error
});
}
public static void AddWarningNotification(this INotificationModel model, string header, string msg)
{
if (model.Exists(header, msg, NotificationStyle.Warning)) return;
model.Notifications.Add(new BackOfficeNotification()
{
Header = header,
Message = msg,
NotificationType = NotificationStyle.Warning
});
}
public static void AddInfoNotification(this INotificationModel model, string header, string msg)
{
if (model.Exists(header, msg, NotificationStyle.Info)) return;
model.Notifications.Add(new BackOfficeNotification()
{
Header = header,
Message = msg,
NotificationType = NotificationStyle.Info
});
}
private static bool Exists(this INotificationModel model, string header, string message, NotificationStyle notificationType) => model.Notifications.Any(x => x.Header.InvariantEquals(header) && x.Message.InvariantEquals(message) && x.NotificationType == notificationType);
}
}

View File

@@ -1,31 +0,0 @@
using System.Collections.Generic;
using System.Runtime.Serialization;
namespace Umbraco.Web.Models.ContentEditing
{
/// <summary>
/// A generic model supporting notifications, this is useful for returning any model type to include notifications from api controllers
/// </summary>
/// <typeparam name="T"></typeparam>
[DataContract(Name = "model", Namespace = "")]
public class ModelWithNotifications<T> : INotificationModel
{
public ModelWithNotifications(T value)
{
Value = value;
Notifications = new List<BackOfficeNotification>();
}
/// <summary>
/// The generic value
/// </summary>
[DataMember(Name = "value")]
public T Value { get; private set; }
/// <summary>
/// The notifications
/// </summary>
[DataMember(Name = "notifications")]
public List<BackOfficeNotification> Notifications { get; private set; }
}
}

View File

@@ -1,24 +0,0 @@
using System.Collections.Generic;
using System.Runtime.Serialization;
using Umbraco.Core.Models.Editors;
namespace Umbraco.Web.Models.ContentEditing
{
/// <summary>
/// This is used for the response of PostAddFile so that we can analyze the response in a filter and remove the
/// temporary files that were created.
/// </summary>
[DataContract]
internal class PostedFiles : IHaveUploadedFiles, INotificationModel
{
public PostedFiles()
{
UploadedFiles = new List<ContentPropertyFile>();
Notifications = new List<BackOfficeNotification>();
}
public List<ContentPropertyFile> UploadedFiles { get; private set; }
[DataMember(Name = "notifications")]
public List<BackOfficeNotification> Notifications { get; private set; }
}
}

View File

@@ -1,39 +0,0 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.Serialization;
namespace Umbraco.Web.Models.ContentEditing
{
[DataContract(Name = "propertyGroup", Namespace = "")]
public class PropertyGroupDisplay<TPropertyTypeDisplay> : PropertyGroupBasic<TPropertyTypeDisplay>
where TPropertyTypeDisplay : PropertyTypeDisplay
{
public PropertyGroupDisplay()
{
Properties = new List<TPropertyTypeDisplay>();
ParentTabContentTypeNames = new List<string>();
ParentTabContentTypes = new List<int>();
}
/// <summary>
/// Gets the context content type.
/// </summary>
[DataMember(Name = "contentTypeId")]
[ReadOnly(true)]
public int ContentTypeId { get; set; }
/// <summary>
/// Gets the identifiers of the content types that define this group.
/// </summary>
[DataMember(Name = "parentTabContentTypes")]
[ReadOnly(true)]
public IEnumerable<int> ParentTabContentTypes { get; set; }
/// <summary>
/// Gets the name of the content types that define this group.
/// </summary>
[DataMember(Name = "parentTabContentTypeNames")]
[ReadOnly(true)]
public IEnumerable<string> ParentTabContentTypeNames { get; set; }
}
}

View File

@@ -1,20 +0,0 @@
using System.Runtime.Serialization;
namespace Umbraco.Web.Models.ContentEditing
{
[DataContract(Name = "publicAccess", Namespace = "")]
public class PublicAccess
{
[DataMember(Name = "groups")]
public MemberGroupDisplay[] Groups { get; set; }
[DataMember(Name = "loginPage")]
public EntityBasic LoginPage { get; set; }
[DataMember(Name = "errorPage")]
public EntityBasic ErrorPage { get; set; }
[DataMember(Name = "members")]
public MemberDisplay[] Members { get; set; }
}
}

View File

@@ -1,22 +0,0 @@
using System.Collections.Generic;
using System.Runtime.Serialization;
using Umbraco.Core.Models;
namespace Umbraco.Web.Models.ContentEditing
{
[DataContract(Name = "redirectUrlSearchResult", Namespace = "")]
public class RedirectUrlSearchResult
{
[DataMember(Name = "searchResults")]
public IEnumerable<ContentRedirectUrl> SearchResults { get; set; }
[DataMember(Name = "totalCount")]
public long TotalCount { get; set; }
[DataMember(Name = "pageCount")]
public int PageCount { get; set; }
[DataMember(Name = "currentPage")]
public int CurrentPage { get; set; }
}
}

View File

@@ -31,10 +31,10 @@ namespace Umbraco.Web.Models.ContentEditing
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
if (UserGroups.Any() == false)
yield return new ValidationResult("A user must be assigned to at least one group", new[] { "UserGroups" });
yield return new ValidationResult("A user must be assigned to at least one group", new[] { nameof(UserGroups) });
if (Current.Configs.Settings().Security.UsernameIsEmail == false && Username.IsNullOrWhiteSpace())
yield return new ValidationResult("A username cannot be empty", new[] { "Username" });
yield return new ValidationResult("A username cannot be empty", new[] { nameof(Username) });
}
}
}

View File

@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using Umbraco.Core;
using Umbraco.Core.Configuration;
using Umbraco.Web.Composing;
using Umbraco.Core.Logging;
using Umbraco.Core.Mapping;
@@ -10,6 +11,7 @@ using Umbraco.Core.PropertyEditors;
using Umbraco.Web.Models.ContentEditing;
using Umbraco.Core.Services;
using Umbraco.Core.Exceptions;
using Umbraco.Core.IO;
using Umbraco.Core.Strings;
namespace Umbraco.Web.Models.Mapping
@@ -27,11 +29,13 @@ namespace Umbraco.Web.Models.Mapping
private readonly IMemberTypeService _memberTypeService;
private readonly ILogger _logger;
private readonly IShortStringHelper _shortStringHelper;
private readonly IIOHelper _ioHelper;
private readonly IGlobalSettings _globalSettings;
public ContentTypeMapDefinition(PropertyEditorCollection propertyEditors, IDataTypeService dataTypeService, IFileService fileService,
IContentTypeService contentTypeService, IMediaTypeService mediaTypeService, IMemberTypeService memberTypeService,
ILogger logger, IShortStringHelper shortStringHelper)
ILogger logger, IShortStringHelper shortStringHelper, IIOHelper ioHelper, IGlobalSettings globalSettings)
{
_propertyEditors = propertyEditors;
_dataTypeService = dataTypeService;
@@ -41,7 +45,8 @@ namespace Umbraco.Web.Models.Mapping
_memberTypeService = memberTypeService;
_logger = logger;
_shortStringHelper = shortStringHelper;
_ioHelper = ioHelper;
_globalSettings = globalSettings;
}
public void DefineMaps(UmbracoMapper mapper)
@@ -184,6 +189,11 @@ namespace Umbraco.Web.Models.Mapping
target.CreateDate = source.CreateDate;
target.Description = source.Description;
target.Icon = source.Icon;
target.IconFilePath = target.IconIsClass
? string.Empty
: $"{Current.Configs.Global().Path.EnsureEndsWith("/")}images/umbraco/{source.Icon}";
target.Trashed = source.Trashed;
target.Id = source.Id;
target.IsContainer = source.IsContainer;
target.IsElement = source.IsElement;
@@ -192,7 +202,9 @@ namespace Umbraco.Web.Models.Mapping
target.ParentId = source.ParentId;
target.Path = source.Path;
target.Thumbnail = source.Thumbnail;
target.Trashed = source.Trashed;
target.ThumbnailFilePath = target.ThumbnailIsClass
? string.Empty
: Current.IOHelper.ResolveUrl("~/umbraco/images/thumbnails/" + source.Thumbnail);
target.UpdateDate = source.UpdateDate;
}
@@ -487,6 +499,9 @@ namespace Umbraco.Web.Models.Mapping
target.CreateDate = source.CreateDate;
target.Description = source.Description;
target.Icon = source.Icon;
target.IconFilePath = target.IconIsClass
? string.Empty
: $"{Current.Configs.Global().Path.EnsureEndsWith("/")}images/umbraco/{source.Icon}";
target.Id = source.Id;
target.IsContainer = source.IsContainer;
target.IsElement = source.IsElement;
@@ -495,6 +510,9 @@ namespace Umbraco.Web.Models.Mapping
target.ParentId = source.ParentId;
target.Path = source.Path;
target.Thumbnail = source.Thumbnail;
target.ThumbnailFilePath = target.ThumbnailIsClass
? string.Empty
: Current.IOHelper.ResolveUrl("~/umbraco/images/thumbnails/" + source.Thumbnail);
target.Udi = MapContentTypeUdi(source);
target.UpdateDate = source.UpdateDate;
@@ -524,6 +542,9 @@ namespace Umbraco.Web.Models.Mapping
target.CompositeContentTypes = source.CompositeContentTypes;
target.Description = source.Description;
target.Icon = source.Icon;
target.IconFilePath = target.IconIsClass
? string.Empty
: $"{Current.Configs.Global().Path.EnsureEndsWith("/")}images/umbraco/{source.Icon}";
target.Id = source.Id;
target.IsContainer = source.IsContainer;
target.IsElement = source.IsElement;
@@ -532,6 +553,9 @@ namespace Umbraco.Web.Models.Mapping
target.ParentId = source.ParentId;
target.Path = source.Path;
target.Thumbnail = source.Thumbnail;
target.ThumbnailFilePath = target.ThumbnailIsClass
? string.Empty
: Current.IOHelper.ResolveUrl("~/umbraco/images/thumbnails/" + source.Thumbnail);
target.Trashed = source.Trashed;
target.Udi = source.Udi;
}