Skip to content

Commit

Permalink
More async calls (#3930)
Browse files Browse the repository at this point in the history
* More async calls

* Little refactoring.

* Minor change

* More async calls.

* Refactoring of home and autoroute to prevent some non async executions.

* Remove testing code.

* Simpler way to check "IsHomepage" before editing.

* Some tweaks

* Minor changes

* Minor change

* GetShapeTableAsync()

* Prevents a non async call of themeManager.GetThemeAsync()

* Update a comment.

* Make some tests async

* More async

* More async calls

* wip on more asunc calls

* Fixes building

* Make CreateUser command async and await all async commands

* More async

* More async

* Make FileContentDefinitionStore thread safe.

* Fixes an use case that ends up with 2 latest versions

* Try to fix travis build

* Definition manager and store as tenant singletons for simpler and better caching. The definitions are read once in place of each time a definition for a given is not built yet. Fixes that, when the type is modified, the definitions were stored twice.

* Tenant level and scoped ContentDefinitionCache. And begin to use some rules around caching and tokens that i will comment and to be continued in another PR.

* Little tweak

* Last tweaks

* my bad

* Revert some changes and some tweaks

* Little updates for some syncing between the caching and async branches.

* Ensures that a deferred signal for a given key is sent once at the end of the scope.

* Re-introduces and uses the DeferredSignalToken extension helper.

* More async calls

* Revert back "ContentDefinitionManager" to its non async version.

* Less async calls.

* Revert "IScriptingEngine" to non async and fix demo module building

* Remove non async Permission providers
  • Loading branch information
jtkech authored Aug 21, 2019
1 parent ccf7f8a commit c65ed09
Show file tree
Hide file tree
Showing 134 changed files with 1,070 additions and 711 deletions.
18 changes: 12 additions & 6 deletions src/OrchardCore.Modules/OrchardCore.Admin/Permissions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using OrchardCore.Security.Permissions;

namespace OrchardCore.Admin
Expand All @@ -7,12 +8,9 @@ public class Permissions : IPermissionProvider
{
public static readonly Permission AccessAdminPanel = new Permission("AccessAdminPanel", "Access admin panel");

public IEnumerable<Permission> GetPermissions()
public Task<IEnumerable<Permission>> GetPermissionsAsync()
{
return new[]
{
AccessAdminPanel
};
return Task.FromResult(GetPermissions());
}

public IEnumerable<PermissionStereotype> GetDefaultStereotypes()
Expand Down Expand Up @@ -42,5 +40,13 @@ public IEnumerable<PermissionStereotype> GetDefaultStereotypes()
}
};
}

private IEnumerable<Permission> GetPermissions()
{
return new[]
{
AccessAdminPanel
};
}
}
}
}
12 changes: 6 additions & 6 deletions src/OrchardCore.Modules/OrchardCore.AdminMenu/Permissions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using OrchardCore.Security.Permissions;

namespace OrchardCore.AdminMenu
Expand All @@ -19,17 +20,16 @@ public Permissions(IAdminMenuService adminMenuService)
_adminMenuService = adminMenuService;
}


public IEnumerable<Permission> GetPermissions()
public async Task<IEnumerable<Permission>> GetPermissionsAsync()
{
var list = new List<Permission> { ManageAdminMenu, ViewAdminMenuAll };

foreach (var adminMenu in _adminMenuService.GetAsync().GetAwaiter().GetResult())
foreach (var adminMenu in await _adminMenuService.GetAsync())
{
list.Add(CreatePermissionForAdminMenu(adminMenu.Name));
}
}

return list;
return list;
}

public IEnumerable<PermissionStereotype> GetDefaultStereotypes()
Expand Down Expand Up @@ -57,4 +57,4 @@ public static Permission CreatePermissionForAdminMenu(string name)
);
}
}
}
}
2 changes: 1 addition & 1 deletion src/OrchardCore.Modules/OrchardCore.Alias/Migrations.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using OrchardCore.ContentManagement.Metadata.Settings;
using OrchardCore.ContentManagement.Metadata.Settings;
using OrchardCore.ContentManagement.Metadata;
using OrchardCore.Data.Migration;
using OrchardCore.Alias.Indexes;
Expand Down
15 changes: 11 additions & 4 deletions src/OrchardCore.Modules/OrchardCore.Apis.GraphQL/Permissions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using OrchardCore.Security.Permissions;

namespace OrchardCore.Apis.GraphQL
Expand All @@ -7,11 +8,9 @@ public class Permissions : IPermissionProvider
{
public static readonly Permission ExecuteGraphQL = new Permission("ExecuteGraphQL", "Execute GraphQL.");

public IEnumerable<Permission> GetPermissions()
public Task<IEnumerable<Permission>> GetPermissionsAsync()
{
return new[] {
ExecuteGraphQL
};
return Task.FromResult(GetPermissions());
}

public IEnumerable<PermissionStereotype> GetDefaultStereotypes()
Expand All @@ -23,5 +22,13 @@ public IEnumerable<PermissionStereotype> GetDefaultStereotypes()
}
};
}

private IEnumerable<Permission> GetPermissions()
{
return new[]
{
ExecuteGraphQL
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Localization;
using Microsoft.Extensions.Options;
using OrchardCore.Autoroute.Model;
using OrchardCore.Autoroute.Models;
using OrchardCore.Autoroute.ViewModels;
using OrchardCore.ContentManagement.Display.ContentDisplay;
using OrchardCore.ContentManagement.Metadata;
using OrchardCore.ContentManagement.Records;
using OrchardCore.ContentManagement.Routing;
using OrchardCore.DisplayManagement.ModelBinding;
using OrchardCore.DisplayManagement.Views;
using OrchardCore.Mvc.ModelBinding;
Expand All @@ -23,6 +25,7 @@ public class AutoroutePartDisplay : ContentPartDisplayDriver<AutoroutePart>
public static char[] InvalidCharactersForPath = ":?#[]@!$&'()*+,.;=<>\\|%".ToCharArray();
public const int MaxPathLength = 1024;

private readonly AutorouteOptions _options;
private readonly IContentDefinitionManager _contentDefinitionManager;
private readonly ISiteService _siteService;
private readonly IAuthorizationService _authorizationService;
Expand All @@ -31,6 +34,7 @@ public class AutoroutePartDisplay : ContentPartDisplayDriver<AutoroutePart>
private readonly IStringLocalizer<AutoroutePartDisplay> T;

public AutoroutePartDisplay(
IOptions<AutorouteOptions> options,
IContentDefinitionManager contentDefinitionManager,
ISiteService siteService,
IAuthorizationService authorizationService,
Expand All @@ -39,6 +43,7 @@ public AutoroutePartDisplay(
IStringLocalizer<AutoroutePartDisplay> localizer
)
{
_options = options.Value;
_contentDefinitionManager = contentDefinitionManager;
_siteService = siteService;
_authorizationService = authorizationService;
Expand All @@ -51,17 +56,14 @@ public override IDisplayResult Edit(AutoroutePart autoroutePart)
{
return Initialize<AutoroutePartViewModel>("AutoroutePart_Edit", async model =>
{

model.Path = autoroutePart.Path;
model.AutoroutePart = autoroutePart;
model.SetHomepage = false;

var siteSettings = await _siteService.GetSiteSettingsAsync();
var homeRoute = siteSettings.HomeRoute;
if (homeRoute["area"]?.ToString() == "OrchardCore.Contents" &&
homeRoute["controller"]?.ToString() == "Item" &&
homeRoute["action"]?.ToString() == "Display" &&
autoroutePart.ContentItem.ContentItemId == homeRoute["contentItemId"]?.ToString())

if (autoroutePart.ContentItem.ContentItemId == homeRoute?[_options.ContentItemIdKey]?.ToString())
{
model.IsHomepage = true;
}
Expand Down Expand Up @@ -110,6 +112,11 @@ public override async Task<IDisplayResult> UpdateAsync(AutoroutePart model, IUpd

private async Task ValidateAsync(AutoroutePart autoroute, IUpdateModel updater)
{
if (autoroute.Path == "/")
{
updater.ModelState.AddModelError(Prefix, nameof(autoroute.Path), T["Your permalink can't be set to the homepage, please use the homepage option instead."]);
}

if (autoroute.Path?.IndexOfAny(InvalidCharactersForPath) > -1 || autoroute.Path?.IndexOf(' ') > -1)
{
var invalidCharactersForMessage = string.Join(", ", InvalidCharactersForPath.Select(c => $"\"{c}\""));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using System.Linq;
using System.Threading.Tasks;
using Fluid;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.Options;
using OrchardCore.Autoroute.Model;
using OrchardCore.Autoroute.Models;
using OrchardCore.ContentManagement;
Expand All @@ -19,23 +21,26 @@ namespace OrchardCore.Autoroute.Handlers
public class AutoroutePartHandler : ContentPartHandler<AutoroutePart>
{
private readonly IAutorouteEntries _entries;
private readonly AutorouteOptions _options;
private readonly ILiquidTemplateManager _liquidTemplateManager;
private readonly IContentDefinitionManager _contentDefinitionManager;
private readonly ISiteService _siteService;
private readonly ITagCache _tagCache;
private readonly YesSql.ISession _session;
private readonly ISession _session;

public AutoroutePartHandler(
IAutorouteEntries entries,
IOptions<AutorouteOptions> options,
ILiquidTemplateManager liquidTemplateManager,
IContentDefinitionManager contentDefinitionManager,
ISiteService siteService,
ITagCache tagCache,
YesSql.ISession session)
ISession session)
{
_contentDefinitionManager = contentDefinitionManager;
_entries = entries;
_options = options.Value;
_liquidTemplateManager = liquidTemplateManager;
_contentDefinitionManager = contentDefinitionManager;
_siteService = siteService;
_tagCache = tagCache;
_session = session;
Expand All @@ -51,12 +56,20 @@ public override async Task PublishedAsync(PublishContentContext context, Autorou
if (part.SetHomepage)
{
var site = await _siteService.GetSiteSettingsAsync();

if (site.HomeRoute == null)
{
site.HomeRoute = new RouteValueDictionary();
}

var homeRoute = site.HomeRoute;

homeRoute["area"] = "OrchardCore.Contents";
homeRoute["controller"] = "Item";
homeRoute["action"] = "Display";
homeRoute["contentItemId"] = context.ContentItem.ContentItemId;
foreach (var entry in _options.GlobalRouteValues)
{
homeRoute[entry.Key] = entry.Value;
}

homeRoute[_options.ContentItemIdKey] = context.ContentItem.ContentItemId;

// Once we too the flag into account we can dismiss it.
part.SetHomepage = false;
Expand Down
4 changes: 2 additions & 2 deletions src/OrchardCore.Modules/OrchardCore.Autoroute/Migrations.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using OrchardCore.Autoroute.Drivers;
using OrchardCore.ContentManagement.Metadata.Settings;
using OrchardCore.Autoroute.Drivers;
using OrchardCore.ContentManagement.Metadata;
using OrchardCore.ContentManagement.Metadata.Settings;
using OrchardCore.ContentManagement.Records;
using OrchardCore.Data.Migration;

Expand Down
17 changes: 12 additions & 5 deletions src/OrchardCore.Modules/OrchardCore.Autoroute/Permissions.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.Threading.Tasks;
using OrchardCore.Security.Permissions;

namespace OrchardCore.Autoroute
{
public class Permissions : IPermissionProvider
{
public static readonly Permission SetHomepage = new Permission("SetHomepage", "Set homepage.");
public IEnumerable<Permission> GetPermissions()
public Task<IEnumerable<Permission>> GetPermissionsAsync()
{
return new[] {
SetHomepage
};
return Task.FromResult(GetPermissions());
}

public IEnumerable<PermissionStereotype> GetDefaultStereotypes()
Expand All @@ -22,5 +21,13 @@ public IEnumerable<PermissionStereotype> GetDefaultStereotypes()
}
};
}

private IEnumerable<Permission> GetPermissions()
{
return new[]
{
SetHomepage
};
}
}
}
Loading

0 comments on commit c65ed09

Please sign in to comment.