diff --git a/src/Articulate/Controllers/MardownEditorApiController.cs b/src/Articulate/Controllers/MardownEditorApiController.cs index a535accd..8c2e1956 100644 --- a/src/Articulate/Controllers/MardownEditorApiController.cs +++ b/src/Articulate/Controllers/MardownEditorApiController.cs @@ -70,6 +70,7 @@ public class ParseImageResponse public async Task PostNew() { + await Task.CompletedTask; if (!Request.HasFormContentType && !Request.Form.Files.Any()) { @@ -235,7 +236,10 @@ private ParseImageResponse ParseImages(string body, IFormFileCollection formFile private static bool CheckPermissions(IUser user, IUserService userService, char[] permissionsToCheck, IContent contentItem) { - if (permissionsToCheck == null || !permissionsToCheck.Any()) return true; + if (permissionsToCheck == null || !permissionsToCheck.Any()) + { + return true; + } var entityPermission = userService.GetPermissions(user, new[] { contentItem.Id }).FirstOrDefault(); @@ -243,7 +247,9 @@ private static bool CheckPermissions(IUser user, IUserService userService, char[ foreach (var ch in permissionsToCheck) { if (entityPermission == null || !entityPermission.AssignedPermissions.Contains(ch.ToString(CultureInfo.InvariantCulture))) + { flag = false; + } } return flag; diff --git a/src/Articulate/ImportExport/BlogMlImporter.cs b/src/Articulate/ImportExport/BlogMlImporter.cs index 3e6f129e..46a26c4b 100644 --- a/src/Articulate/ImportExport/BlogMlImporter.cs +++ b/src/Articulate/ImportExport/BlogMlImporter.cs @@ -15,11 +15,11 @@ using Umbraco.Cms.Core.IO; using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.PropertyEditors; -using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Core.Serialization; using Umbraco.Cms.Core.Services; using Umbraco.Cms.Core.Strings; using Umbraco.Cms.Infrastructure.Persistence; +using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Extensions; using File = System.IO.File; using Task = System.Threading.Tasks.Task; @@ -121,11 +121,8 @@ public async Task Import( throw new FileNotFoundException("File not found: " + fileName); } - var root = _contentService.GetById(blogRootNode); - if (root == null) - { - throw new InvalidOperationException("No node found with id " + blogRootNode); - } + var root = _contentService.GetById(blogRootNode) + ?? throw new InvalidOperationException("No node found with id " + blogRootNode); if (!root.ContentType.Alias.InvariantEquals("Articulate")) { @@ -187,17 +184,11 @@ private IDictionary ImportAuthors(int userId, IContent rootNode, { var result = new Dictionary(); - var authorType = _contentTypeService.Get("ArticulateAuthor"); - if (authorType == null) - { - throw new InvalidOperationException("Articulate is not installed properly, the ArticulateAuthor doc type could not be found"); - } + var authorType = _contentTypeService.Get("ArticulateAuthor") + ?? throw new InvalidOperationException("Articulate is not installed properly, the ArticulateAuthor doc type could not be found"); - var authorsType = _contentTypeService.Get(ArticulateConstants.ArticulateAuthorsContentTypeAlias); - if (authorsType == null) - { - throw new InvalidOperationException("Articulate is not installed properly, the ArticulateAuthors doc type could not be found"); - } + var authorsType = _contentTypeService.Get(ArticulateConstants.ArticulateAuthorsContentTypeAlias) + ?? throw new InvalidOperationException("Articulate is not installed properly, the ArticulateAuthors doc type could not be found"); // get the authors container node for this articulate root var allAuthorsNodes = _contentService.GetPagedOfType( @@ -270,11 +261,8 @@ private async Task> ImportPosts(int userId, XDocument xdoc { var result = new List(); - var postType = _contentTypeService.Get("ArticulateRichText"); - if (postType == null) - { - throw new InvalidOperationException("Articulate is not installed properly, the ArticulateRichText doc type could not be found"); - } + var postType = _contentTypeService.Get("ArticulateRichText") + ?? throw new InvalidOperationException("Articulate is not installed properly, the ArticulateRichText doc type could not be found"); var archiveDocType = _contentTypeService.Get(ArticulateConstants.ArticulateArchiveContentTypeAlias); @@ -543,13 +531,10 @@ private void ImportTags(XDocument xdoc, IContent postNode, BlogMLPost post, ICon var xmlPost = xdoc.Descendants(XName.Get("post", xdoc.Root.Name.NamespaceName)) .SingleOrDefault(x => ((string)x.Attribute("id")) == post.Id); - if (xmlPost == null) - { - xmlPost = xdoc.Descendants(XName.Get("post", xdoc.Root.Name.NamespaceName)) + xmlPost ??= xdoc.Descendants(XName.Get("post", xdoc.Root.Name.NamespaceName)) .SingleOrDefault(x => x.Descendants(XName.Get("post-name", xdoc.Root.Name.NamespaceName)) .SingleOrDefault(s => s.Value == post.Name.Content) != null - ); - }; + );; if (xmlPost == null) { diff --git a/src/Articulate/PropertyEditors/ArticulateMarkdownPropertyEditor.cs b/src/Articulate/PropertyEditors/ArticulateMarkdownPropertyEditor.cs index 8991a004..bb048d5c 100644 --- a/src/Articulate/PropertyEditors/ArticulateMarkdownPropertyEditor.cs +++ b/src/Articulate/PropertyEditors/ArticulateMarkdownPropertyEditor.cs @@ -1,9 +1,9 @@ -using Markdig; -using Microsoft.AspNetCore.Html; +using System; using Umbraco.Cms.Core.IO; using Umbraco.Cms.Core.Models.PublishedContent; using Umbraco.Cms.Core.PropertyEditors; using Umbraco.Cms.Core.PropertyEditors.ValueConverters; +using Umbraco.Cms.Core.Services; using Umbraco.Cms.Core.Strings; using Umbraco.Cms.Core.Templates; @@ -13,7 +13,14 @@ namespace Articulate.PropertyEditors [DataEditor("Articulate.MarkdownEditor", "Articulate Markdown editor", "markdowneditor", ValueType = "TEXT")] public class ArticulateMarkdownPropertyEditor : MarkdownPropertyEditor { - public ArticulateMarkdownPropertyEditor(IDataValueEditorFactory dataValueEditorFactory, IIOHelper ioHelper) : base(dataValueEditorFactory, ioHelper) + [Obsolete] + public ArticulateMarkdownPropertyEditor(IDataValueEditorFactory dataValueEditorFactory, IIOHelper ioHelper) + : base(dataValueEditorFactory, ioHelper) + { + } + + public ArticulateMarkdownPropertyEditor(IDataValueEditorFactory dataValueEditorFactory, IIOHelper ioHelper, IEditorConfigurationParser editorConfigurationParser) + : base(dataValueEditorFactory, ioHelper, editorConfigurationParser) { } } diff --git a/src/Articulate/Routing/DateFormattedPostContentFinder.cs b/src/Articulate/Routing/DateFormattedPostContentFinder.cs index 91025984..aaaa169c 100644 --- a/src/Articulate/Routing/DateFormattedPostContentFinder.cs +++ b/src/Articulate/Routing/DateFormattedPostContentFinder.cs @@ -16,11 +16,16 @@ public DateFormattedPostContentFinder(ILogger logger, IUmbra public override async Task TryFindContent(IPublishedRequestBuilder contentRequest) { + await Task.CompletedTask; + // This simple logic should do the trick: basically if I find an url with more than 4 segments (the 3 date parts and the slug) // I leave the last segment (the slug), remove the 3 date parts, and keep all the rest. var segmentLength = contentRequest.Uri.Segments.Length; - if (segmentLength <= 4) return false; - + if (segmentLength <= 4) + { + return false; + } + var stringDate = contentRequest.Uri.Segments[segmentLength - 4] + contentRequest.Uri.Segments[segmentLength - 3] + contentRequest.Uri.Segments[segmentLength - 2].TrimEnd('/'); DateTime postDate; try @@ -36,7 +41,9 @@ public override async Task TryFindContent(IPublishedRequestBuilder content for (var i = 0; i < segmentLength; i++) { if (i < segmentLength - 4 || i > segmentLength - 2) + { newRoute += contentRequest.Uri.Segments[i].ToLowerInvariant(); + } } // if there's a domain attached we need to lookup the content with the domain Id @@ -49,9 +56,20 @@ public override async Task TryFindContent(IPublishedRequestBuilder content var node = FindContent(contentRequest, newRoute); // If by chance something matches the format pattern I check again if there is sucn a node and if it's an articulate post - if (node == null || (node.ContentType.Alias != "ArticulateRichText" && node.ContentType.Alias != "ArticulateMarkdown")) return false; - if (!node.Parent.Parent.Value("useDateFormatForUrl")) return false; - if (node.Value("publishedDate").Date != postDate.Date) return false; + if (node == null || (node.ContentType.Alias != "ArticulateRichText" && node.ContentType.Alias != "ArticulateMarkdown")) + { + return false; + } + + if (!node.Parent.Parent.Value("useDateFormatForUrl")) + { + return false; + } + + if (node.Value("publishedDate").Date != postDate.Date) + { + return false; + } contentRequest.SetPublishedContent(node); return true; diff --git a/src/Articulate/Services/ArticulateTagService.cs b/src/Articulate/Services/ArticulateTagService.cs index f059334c..4f3a957d 100644 --- a/src/Articulate/Services/ArticulateTagService.cs +++ b/src/Articulate/Services/ArticulateTagService.cs @@ -3,8 +3,8 @@ using Microsoft.Extensions.Logging; using Umbraco.Cms.Core.Events; using Umbraco.Cms.Core.PublishedCache; -using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Core.Services; +using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Cms.Web.Common; namespace Articulate.Services @@ -19,7 +19,9 @@ public ArticulateTagService( ILoggerFactory loggerFactory, IEventMessagesFactory eventMessagesFactory) : base(provider, loggerFactory, eventMessagesFactory) - => _repository = repository; + { + _repository = repository; + } // TODO: Wrap the repo