Skip to content

Commit

Permalink
introduce parser service and interfaces, parser executor,
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanwoulfe committed Aug 26, 2021
1 parent 4439746 commit 3b43b3f
Show file tree
Hide file tree
Showing 57 changed files with 1,235 additions and 763 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
"tab": "General",
"order": 2,
"view": "checkboxlist",
"core": true
"core": true,
"value": "Umbraco.Grid,Umbraco.TinyMCE,Umbraco.TextArea,Umbraco.TextBox,Umbraco.NestedContent"
},
{
"label": "User group opt in/out",
Expand Down
2 changes: 1 addition & 1 deletion Preflight.Site.V8/App_Data/Models/all.dll.path
Original file line number Diff line number Diff line change
@@ -1 +1 @@
C:\Users\nwoulfe1\AppData\Local\Temp\Temporary ASP.NET Files\vs\3f510f17\6a0262c9\App_Web_all.generated.cs.8f9494c4.thjsv7f5.dll
C:\Users\nwoulfe1\AppData\Local\Temp\Temporary ASP.NET Files\vs\3f510f17\6a0262c9\App_Web_all.generated.cs.8f9494c4.qdu7a-xv.dll
Binary file modified Preflight.Site.V8/App_Data/Umbraco.sdf
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
"tab": "General",
"order": 2,
"view": "checkboxlist",
"core": true
"core": true,
"value": "Umbraco.Grid,Umbraco.TinyMCE,Umbraco.TextArea,Umbraco.TextBox,Umbraco.NestedContent"
},
{
"label": "User group opt in/out",
Expand Down
9 changes: 5 additions & 4 deletions src/Preflight/Constants/KnownPropertyAlias.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using System.Collections.Generic;
using System.Linq;
#if NET472
using UmbConstants = Umbraco.Core.Constants;
#else
#if NETCOREAPP
using UmbConstants = Umbraco.Cms.Core.Constants;
#else
using UmbConstants = Umbraco.Core.Constants;
#endif

namespace Preflight.Constants
namespace Preflight
{
public static class KnownPropertyAlias
{
Expand All @@ -15,6 +15,7 @@ public static class KnownPropertyAlias
public const string Textarea = UmbConstants.PropertyEditors.Aliases.TextArea;
public const string Textbox = UmbConstants.PropertyEditors.Aliases.TextBox;
public const string NestedContent = UmbConstants.PropertyEditors.Aliases.NestedContent;
public const string BlockList = UmbConstants.PropertyEditors.Aliases.BlockList;

public static IEnumerable<string> All = typeof(KnownPropertyAlias).GetFields()
.Where(x => x.IsLiteral).Select(x => x.GetRawConstantValue().ToString());
Expand Down
27 changes: 14 additions & 13 deletions src/Preflight/Constants/KnownSettings.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
namespace Preflight.Constants
namespace Preflight
{
public static class KnownSettings
{
public const string BindSaveHandler = "Run Preflight on save";
public const string EnsureSafeLinks = "Ensure safe links";
public const string CancelSaveOnFail = "Cancel save when Preflight tests fail";
public const string ReadabilityMin = "Readability target - minimum";
public const string ReadabilityMax = "Readability target - maximum";
public const string LongWordSyllables = "Long word syllable count";
public const string NiceList = "Nice words";
public const string NaughtyList = "Naughty words";
public const string AutocorrectTerms = "Autocorrect terms";
public const string GoogleApiKey = "Google SafeBrowsing API key";
public const string UserGroupOptIn = "User group opt in/out";
public const string PropertiesToTest = "Properties to test";
// guid strings are used to identify the setting and for storing the related value
public const string BindSaveHandler = "a5b02d88-4555-4c81-8973-6119feb3da20";
public const string EnsureSafeLinks = "2f1f3b0f-f6c6-45ea-a9fa-f342372c4208";
public const string CancelSaveOnFail = "0483a065-9504-48e4-861d-6149b2e37cd3";
public const string ReadabilityMin = "ad1ac044-5a44-45aa-86a8-ab1a1fedada2";
public const string ReadabilityMax = "f3ab7fe3-0d29-4450-b07c-92a61a23e123";
public const string LongWordSyllables = "a62b0522-88d8-4b80-b3e9-ef1e81ec7baa";
public const string NiceList = "1a465035-41d4-44a4-bf64-87ede0cea3be";
public const string NaughtyList = "edb82950-9d0b-4d1d-b727-96915014db4b";
public const string AutocorrectTerms = "9e94c320-b1bf-4318-a331-00d35eb762fc";
public const string GoogleApiKey = "bc6dff82-beac-4c5d-8d4e-e33559c78666";
public const string UserGroupOptIn = "d1e534d6-cc35-4cba-bb14-dc4afeada605";
public const string PropertiesToTest = "0e210e54-6936-444f-af8e-ae9e29cfb6eb";
}
}
29 changes: 8 additions & 21 deletions src/Preflight/Constants/KnownStrings.cs
Original file line number Diff line number Diff line change
@@ -1,41 +1,28 @@
namespace Preflight.Constants
namespace Preflight
{
public static class KnownStrings
{
public const string Name = "Preflight";
public const string Alias = "preflight";
public const string Icon = "icon-paper-plane";
public const string AppSettingKey = "PreflightInstalled";
public const string SettingsTable = "PreflightSettings";

public const string ContentFailedChecks = "Content failed Preflight checks";
public const string GridRteJsonPath = "$..controls[?(@.editor.view == 'rte' || @.editor.view == 'textstring' || @.editor.view == 'textarea' || @.editor.alias == 'rte' || @.editor.alias == 'headline' || @.editor.alias == 'quote')]";
public const string GridValueJsonPath = "$..value";

public const string NcAlias = "ncContentTypeAlias";

public const string Comma = ",";
public const string One = "1";
public const string Zero = "0";

public const string CORE = "CORE";
public const string FRAMEWORK = "FRAMEWORK";

public const string GridTextstringJsonPath = "$..controls[?(@.editor.alias == 'textstring')]";

public const string ClosingHtmlTags = @"(<\/li>|<\/h[1-6]{1}>)";
public const string CharsToRemove = @"(<.*?>|\(|\)|\[|\]|,|\w'|'\w|\w""|""\w)";
public const string DuplicateSpaces = @"\s+";
public const string NewLine = "\n";

public const string HrefXPath = "//a[@href]";

public const string CacheKey = "Preflight_SafeBrowsing_";
public const string SettingsCacheKey = "Preflight_Settings_";

public const string SafeBrowsingUrl = "https://safebrowsing.googleapis.com/v4/threatMatches:find?key=";
public const string PropertiesToTestSuffix = "PropertiesToTest";
}

public static readonly char[] Vowels = { 'a', 'e', 'i', 'o', 'u', 'y' };
public static readonly char[] WordDelimiters = { '.', '!', '?', ':', ';' };
public static readonly string[] Endings = { "es", "ed" };
public static partial class Constants
{

public static readonly string SettingsFilePath = "~/App_Plugins/Preflight/Backoffice/settings.json";
}
}
24 changes: 24 additions & 0 deletions src/Preflight/Constants/Readability.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
namespace Preflight
{
public static partial class Constants
{
public class Readability
{
public static readonly char[] Vowels = { 'a', 'e', 'i', 'o', 'u', 'y' };
public static readonly char[] WordDelimiters = { '.', '!', '?', ':', ';' };
public static readonly string[] Endings = { "es", "ed" };

public const string ClosingHtmlTags = @"(<\/li>|<\/h[1-6]{1}>)";
public const string CharsToRemove = @"(<.*?>|\(|\)|\[|\]|,|\w'|'\w|\w""|""\w)";
public const string DuplicateSpaces = @"\s+";
public const string Ied = "ied";
public const string Space = " ";
public const string Period = ".";
public const string Ampersand = "&";
public const string AmpersandEntity = "&amp;";

public const char l = 'l';
public const char e = 'e';
}
}
}
12 changes: 6 additions & 6 deletions src/Preflight/Constants/SettingType.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
namespace Preflight.Constants
namespace Preflight
{
public static class SettingType
{
public const string Boolean = "views/propertyeditors/boolean/boolean.html";
public const string Slider = "views/propertyeditors/slider/slider.html";
public const string String = "views/propertyeditors/textbox/textbox.html";
public const string MultipleTextbox = "views/propertyeditors/multipletextbox/multipletextbox.html";
public const string CheckboxList = "views/propertyeditors/checkboxlist/checkboxlist.html";
public const string Boolean = "boolean";
public const string Slider = "slider";
public const string String = "textbox";
public const string MultipleTextbox = "multipletextbox";
public const string CheckboxList = "checkboxlist";
}
}
12 changes: 6 additions & 6 deletions src/Preflight/Controllers/PreflightApiController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
using Preflight.Services;
using System;
using System.Net;
#if NET472
#if NETCOREAPP
using Microsoft.AspNetCore.Mvc;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Web.BackOffice.Controllers;
using Umbraco.Cms.Web.Common.Attributes;
#else
using System.Web.Http;
using Umbraco.Core.Services;
using Umbraco.Web.Mvc;
using Umbraco.Web.WebApi;
using IActionResult = System.Web.Http.IHttpActionResult;
#else
using Microsoft.AspNetCore.Mvc;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Web.BackOffice.Controllers;
using Umbraco.Cms.Web.Common.Attributes;
#endif

namespace Preflight.Controllers
Expand Down
49 changes: 24 additions & 25 deletions src/Preflight/Controllers/PreflightTreeController.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
using Preflight.Constants;
#if NET472
using System.Net.Http.Formatting;
using System.Web.Http.ModelBinding;
using Umbraco.Web.Models.Trees;
using Umbraco.Web.Mvc;
using Umbraco.Web.Trees;
using Umbraco.Web.WebApi.Filters;
using UmbConstants = Umbraco.Core.Constants;
#else
#if NETCOREAPP
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Umbraco.Cms.Web.BackOffice.Trees;
Expand All @@ -18,6 +9,14 @@
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Trees;
using UmbConstants = Umbraco.Cms.Core.Constants;
#else
using System.Net.Http.Formatting;
using System.Web.Http.ModelBinding;
using Umbraco.Web.Models.Trees;
using Umbraco.Web.Mvc;
using Umbraco.Web.Trees;
using Umbraco.Web.WebApi.Filters;
using UmbConstants = Umbraco.Core.Constants;
#endif

namespace Preflight.Controllers
Expand All @@ -38,21 +37,7 @@ private void SetRootNode(TreeNode root)
root.HasChildren = false;
root.MenuUrl = null;
}

#if NET472
protected override TreeNode CreateRootNode(FormDataCollection queryStrings)
{
TreeNode root = base.CreateRootNode(queryStrings);
SetRootNode(root);

return root;
}

protected override MenuItemCollection GetMenuForNode(string id, [ModelBinder(typeof(HttpQueryStringModelBinder))] FormDataCollection queryStrings) => null;

protected override TreeNodeCollection GetTreeNodes(string id, [ModelBinder(typeof(HttpQueryStringModelBinder))] FormDataCollection queryStrings) =>
new TreeNodeCollection();
#else
#if NETCOREAPP
public PreflightTreeController(ILocalizedTextService textService, UmbracoApiControllerTypeCollection umbracoApiControllerTypeCollection,
IEventAggregator eventAggregator) : base(textService, umbracoApiControllerTypeCollection, eventAggregator)
{
Expand All @@ -70,6 +55,20 @@ protected override ActionResult<TreeNode> CreateRootNode(FormCollection queryStr

protected override ActionResult<TreeNodeCollection> GetTreeNodes(string id, [ModelBinder(typeof(HttpQueryStringModelBinder))] FormCollection queryStrings) =>
new TreeNodeCollection();
#else
protected override TreeNode CreateRootNode(FormDataCollection queryStrings)
{
TreeNode root = base.CreateRootNode(queryStrings);
SetRootNode(root);

return root;
}

protected override MenuItemCollection GetMenuForNode(string id, [ModelBinder(typeof(HttpQueryStringModelBinder))] FormDataCollection queryStrings) => null;

protected override TreeNodeCollection GetTreeNodes(string id, [ModelBinder(typeof(HttpQueryStringModelBinder))] FormDataCollection queryStrings) =>
new TreeNodeCollection();

#endif
}
}
26 changes: 7 additions & 19 deletions src/Preflight/Executors/IContentSavingExecutor.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
using Preflight.Constants;
using Preflight.Extensions;
using Preflight.Extensions;
using Preflight.Models;
using Preflight.Services;
using System;
using System.Collections.Generic;
using System.Linq;
#if NET472
using Umbraco.Core.Events;
using Umbraco.Core.Models;
using Preflight.Security;
using CharArrays = Umbraco.Core.Constants.CharArrays;
#else
#if NETCOREAPP
using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Security;
using CharArrays = Umbraco.Cms.Core.Constants.CharArrays;
#else
using Umbraco.Core.Events;
using Umbraco.Core.Models;
using Preflight.Security;
using CharArrays = Umbraco.Core.Constants.CharArrays;
#endif

namespace Preflight.Executors
Expand Down Expand Up @@ -70,17 +69,6 @@ public bool SaveCancelledDueToFailedTests(IContent content, out EventMessage mes
// at least one property on the current document fails the preflight check
if (!failed) return false;

// these values are retrieved in the notifications handler, and passed down to the client
// TODO => make it work
//HttpContext.Current.Items["PreflightFailed"] = true;
//HttpContext.Current.Items["PreflightCancelSaveOnFail"] = cancelSaveOnFail;
//HttpContext.Current.Items["PreflightNodeId"] = content.Id;

//if (e.CanCancel && cancelSaveOnFail)
//{
// e.CancelOperation(new EventMessage("PreflightFailed", content.Id.ToString()));
//}

message = new EventMessage("Save cancelled", content.Id.ToString());

return true;
Expand Down
28 changes: 14 additions & 14 deletions src/Preflight/Executors/ILinkGenerator.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
using System;
using System.Linq.Expressions;
#if NET472
#if NETCOREAPP
using Umbraco.Cms.Web.Common.Controllers;
using Umbraco.Extensions;
using CoreLinkGenerator = Microsoft.AspNetCore.Routing.LinkGenerator;
#else
using Umbraco.Web;
using Umbraco.Web.WebApi;
using System.Web.Routing;
using System.Web;
using System.Web.Mvc;
#else
using Umbraco.Cms.Web.Common.Controllers;
using Umbraco.Extensions;
using CoreLinkGenerator = Microsoft.AspNetCore.Routing.LinkGenerator;
#endif

namespace Preflight.Executors
Expand All @@ -21,15 +21,7 @@ public interface ILinkGenerator

public class LinkGenerator : ILinkGenerator
{
#if NET472
public string GetUmbracoApiServiceBaseUrl<T>(Expression<Func<T, object>> methodSelector) where T : UmbracoApiController
{
RequestContext requestContext = HttpContext.Current.Request.RequestContext;
var urlHelper = new UrlHelper(requestContext);

return urlHelper.GetUmbracoApiServiceBaseUrl(methodSelector);
}
#else
#if NETCOREAPP
private readonly CoreLinkGenerator _coreLinkGenerator;

public LinkGenerator(CoreLinkGenerator coreLinkGenerator)
Expand All @@ -39,6 +31,14 @@ public LinkGenerator(CoreLinkGenerator coreLinkGenerator)

public string GetUmbracoApiServiceBaseUrl<T>(Expression<Func<T, object>> methodSelector) where T : UmbracoApiController =>
_coreLinkGenerator.GetUmbracoApiServiceBaseUrl(methodSelector);
#else
public string GetUmbracoApiServiceBaseUrl<T>(Expression<Func<T, object>> methodSelector) where T : UmbracoApiController
{
RequestContext requestContext = HttpContext.Current.Request.RequestContext;
var urlHelper = new UrlHelper(requestContext);

return urlHelper.GetUmbracoApiServiceBaseUrl(methodSelector);
}
#endif
}
}
Loading

0 comments on commit 3b43b3f

Please sign in to comment.