From 025e7eba1d22507a90a19566ccee2523c554ee0d Mon Sep 17 00:00:00 2001 From: Shannon Date: Mon, 28 Oct 2013 15:36:08 +1100 Subject: [PATCH] Separates some classes --- .../FileUploadPropertyEditor.cs | 39 --------------- ...or.cs => MultiNodePickerPreValueEditor.cs} | 0 .../UploadFileTypeValidator.cs | 49 +++++++++++++++++++ src/Umbraco.Web/Umbraco.Web.csproj | 3 +- 4 files changed, 51 insertions(+), 40 deletions(-) rename src/Umbraco.Web/PropertyEditors/{MultiNodePreValueEditor.cs => MultiNodePickerPreValueEditor.cs} (100%) create mode 100644 src/Umbraco.Web/PropertyEditors/UploadFileTypeValidator.cs diff --git a/src/Umbraco.Web/PropertyEditors/FileUploadPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/FileUploadPropertyEditor.cs index c03b7cf39e..5d9e7d0a85 100644 --- a/src/Umbraco.Web/PropertyEditors/FileUploadPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/FileUploadPropertyEditor.cs @@ -1,11 +1,8 @@ using System; using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; using System.Drawing; -using System.IO; using System.Linq; using System.Xml; -using Newtonsoft.Json.Linq; using Umbraco.Core; using Umbraco.Core.Configuration; using Umbraco.Core.Configuration.UmbracoSettings; @@ -14,7 +11,6 @@ using Umbraco.Core.Logging; using Umbraco.Core.Models; using Umbraco.Core.PropertyEditors; using Umbraco.Core.Services; -using umbraco; namespace Umbraco.Web.PropertyEditors { @@ -177,39 +173,4 @@ namespace Umbraco.Web.PropertyEditors } } - - internal class UploadFileTypeValidator : IPropertyValidator - { - public IEnumerable Validate(object value, PreValueCollection preValues, PropertyEditor editor) - { - - //now check the file type - var asJson = value as JObject; - if (asJson == null) yield break; - if (asJson["selectedFiles"] == null) yield break; - var fileNames = asJson["selectedFiles"].ToString().Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); - foreach (var fileName in fileNames) - { - if (ValidateFileExtension(fileName) == false) - { - yield return new ValidationResult(ui.Text("errors", "dissallowedMediaType"), - new[] - { - //we only store a single value for this editor so the 'member' or 'field' - // we'll associate this error with will simply be called 'value' - "value" - }); - } - } - - } - - internal static bool ValidateFileExtension(string fileName) - { - if (fileName.IndexOf('.') <= 0) return false; - var extension = Path.GetExtension(fileName).TrimStart("."); - return UmbracoConfig.For.UmbracoSettings().Content.DisallowedUploadFiles.Any(x => x.InvariantEquals(extension)) == false; - } - - } } diff --git a/src/Umbraco.Web/PropertyEditors/MultiNodePreValueEditor.cs b/src/Umbraco.Web/PropertyEditors/MultiNodePickerPreValueEditor.cs similarity index 100% rename from src/Umbraco.Web/PropertyEditors/MultiNodePreValueEditor.cs rename to src/Umbraco.Web/PropertyEditors/MultiNodePickerPreValueEditor.cs diff --git a/src/Umbraco.Web/PropertyEditors/UploadFileTypeValidator.cs b/src/Umbraco.Web/PropertyEditors/UploadFileTypeValidator.cs new file mode 100644 index 0000000000..1702a55650 --- /dev/null +++ b/src/Umbraco.Web/PropertyEditors/UploadFileTypeValidator.cs @@ -0,0 +1,49 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.IO; +using System.Linq; +using Newtonsoft.Json.Linq; +using Umbraco.Core; +using Umbraco.Core.Configuration; +using Umbraco.Core.Models; +using Umbraco.Core.PropertyEditors; +using umbraco; + +namespace Umbraco.Web.PropertyEditors +{ + internal class UploadFileTypeValidator : IPropertyValidator + { + public IEnumerable Validate(object value, PreValueCollection preValues, PropertyEditor editor) + { + + //now check the file type + var asJson = value as JObject; + if (asJson == null) yield break; + if (asJson["selectedFiles"] == null) yield break; + var fileNames = asJson["selectedFiles"].ToString().Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); + foreach (var fileName in fileNames) + { + if (ValidateFileExtension(fileName) == false) + { + yield return new ValidationResult(ui.Text("errors", "dissallowedMediaType"), + new[] + { + //we only store a single value for this editor so the 'member' or 'field' + // we'll associate this error with will simply be called 'value' + "value" + }); + } + } + + } + + internal static bool ValidateFileExtension(string fileName) + { + if (fileName.IndexOf('.') <= 0) return false; + var extension = Path.GetExtension(fileName).TrimStart("."); + return UmbracoConfig.For.UmbracoSettings().Content.DisallowedUploadFiles.Any(x => StringExtensions.InvariantEquals(x, extension)) == false; + } + + } +} \ No newline at end of file diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 34da596e08..a86e2d66d3 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -344,7 +344,7 @@ - + @@ -385,6 +385,7 @@ +