Skip to content

Commit

Permalink
Fixes a bunch of formatting/warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
Shazwazza committed Nov 2, 2023
1 parent 67da9d7 commit 779266b
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 37 deletions.
8 changes: 7 additions & 1 deletion src/Articulate/Controllers/MardownEditorApiController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public class ParseImageResponse

public async Task<ActionResult> PostNew()
{
await Task.CompletedTask;

if (!Request.HasFormContentType && !Request.Form.Files.Any())
{
Expand Down Expand Up @@ -235,15 +236,20 @@ 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();

var flag = true;
foreach (var ch in permissionsToCheck)
{
if (entityPermission == null || !entityPermission.AssignedPermissions.Contains(ch.ToString(CultureInfo.InvariantCulture)))
{
flag = false;
}
}

return flag;
Expand Down
37 changes: 11 additions & 26 deletions src/Articulate/ImportExport/BlogMlImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -121,11 +121,8 @@ public async Task<bool> 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"))
{
Expand Down Expand Up @@ -187,17 +184,11 @@ private IDictionary<string, string> ImportAuthors(int userId, IContent rootNode,
{
var result = new Dictionary<string, string>();

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(
Expand Down Expand Up @@ -270,11 +261,8 @@ private async Task<IEnumerable<IContent>> ImportPosts(int userId, XDocument xdoc
{
var result = new List<IContent>();

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);

Expand Down Expand Up @@ -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)
{
Expand Down
13 changes: 10 additions & 3 deletions src/Articulate/PropertyEditors/ArticulateMarkdownPropertyEditor.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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)
{
}
}
Expand Down
28 changes: 23 additions & 5 deletions src/Articulate/Routing/DateFormattedPostContentFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,16 @@ public DateFormattedPostContentFinder(ILogger<ContentFinderByUrl> logger, IUmbra

public override async Task<bool> 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
Expand All @@ -36,7 +41,9 @@ public override async Task<bool> 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
Expand All @@ -49,9 +56,20 @@ public override async Task<bool> 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<bool>("useDateFormatForUrl")) return false;
if (node.Value<DateTime>("publishedDate").Date != postDate.Date) return false;
if (node == null || (node.ContentType.Alias != "ArticulateRichText" && node.ContentType.Alias != "ArticulateMarkdown"))
{
return false;
}

if (!node.Parent.Parent.Value<bool>("useDateFormatForUrl"))
{
return false;
}

if (node.Value<DateTime>("publishedDate").Date != postDate.Date)
{
return false;
}

contentRequest.SetPublishedContent(node);
return true;
Expand Down
6 changes: 4 additions & 2 deletions src/Articulate/Services/ArticulateTagService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -19,7 +19,9 @@ public ArticulateTagService(
ILoggerFactory loggerFactory,
IEventMessagesFactory eventMessagesFactory)
: base(provider, loggerFactory, eventMessagesFactory)
=> _repository = repository;
{
_repository = repository;
}

// TODO: Wrap the repo

Expand Down

0 comments on commit 779266b

Please sign in to comment.