diff --git a/.editorconfig b/.editorconfig
index e591a9cd54c..2cf117a4d88 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -1,7 +1,6 @@
root = true
[*]
-end_of_line = crlf
charset = utf-8
indent_style = space
indent_size = 4
@@ -32,7 +31,10 @@ dotnet_sort_system_directives_first = true
# Code-block preferences
csharp_prefer_braces = true
csharp_prefer_simple_using_statement = true
-csharp_style_namespace_declarations = file_scoped:suggestion
+csharp_style_namespace_declarations = file_scoped:warning
+# Note that currently both IDE* rules and csharp_style_* rules are necessary, because only IDE rules will be enforced
+# during build, see: https://github.com/dotnet/roslyn/issues/44201.
+dotnet_diagnostic.IDE0161.severity = warning
# Range operator
csharp_style_prefer_range_operator = false:warning
diff --git a/.gitattributes b/.gitattributes
index b175f24ba07..afbe3b25f10 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -1,7 +1,3 @@
* text=auto
**/wwwroot/Scripts/* linguist-vendored
-
-# Keep LF line endings in webroot assets files. Otherwise, building them under Windows would change the line endings to CLRF and cause changes without actually editing the source files.
-**/wwwroot/**/*.js text eol=lf
-**/wwwroot/**/*.css text eol=lf
diff --git a/Directory.Packages.props b/Directory.Packages.props
index a3effff50d5..674edaf3f9c 100644
--- a/Directory.Packages.props
+++ b/Directory.Packages.props
@@ -56,6 +56,7 @@
+
diff --git a/OrchardCore.sln b/OrchardCore.sln
index 95a51c8d18b..e2b57d6f876 100644
--- a/OrchardCore.sln
+++ b/OrchardCore.sln
@@ -523,7 +523,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OrchardCore.Email.Smtp", "s
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OrchardCore.Rules.Core", "src\OrchardCore\OrchardCore.Rules.Core\OrchardCore.Rules.Core.csproj", "{4BAA08A2-878C-4B96-86BF-5B3DB2B6C2C7}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OrchardCore.Queries.Core", "src\OrchardCore\OrchardCore.Queries.Core\OrchardCore.Queries.Core.csproj", "{61B358F2-702C-40AA-9DF7-7121248FE6DE}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OrchardCore.Queries.Core", "src\OrchardCore\OrchardCore.Queries.Core\OrchardCore.Queries.Core.csproj", "{61B358F2-702C-40AA-9DF7-7121248FE6DE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
diff --git a/src/OrchardCore.Build/OrchardCore.Commons.props b/src/OrchardCore.Build/OrchardCore.Commons.props
index 1b3d5fcbd2c..8679acba8de 100644
--- a/src/OrchardCore.Build/OrchardCore.Commons.props
+++ b/src/OrchardCore.Build/OrchardCore.Commons.props
@@ -13,7 +13,6 @@
false
false
false
-
Orchard Core Framework is an application framework for building modular, multi-tenant applications on ASP.NET Core.
Orchard Core CMS is a Web Content Management System (CMS) built on top of the Orchard Core Framework.
@@ -48,6 +47,10 @@
+
+ all
+ runtime; build; native; contentfiles; analyzers
+
diff --git a/src/OrchardCore.Modules/OrchardCore.Admin/AdminAreaControllerRouteMapper.cs b/src/OrchardCore.Modules/OrchardCore.Admin/AdminAreaControllerRouteMapper.cs
index fb6677e135d..5b58e37e7ba 100644
--- a/src/OrchardCore.Modules/OrchardCore.Admin/AdminAreaControllerRouteMapper.cs
+++ b/src/OrchardCore.Modules/OrchardCore.Admin/AdminAreaControllerRouteMapper.cs
@@ -5,53 +5,52 @@
using Microsoft.Extensions.Options;
using OrchardCore.Mvc.Routing;
-namespace OrchardCore.Admin
+namespace OrchardCore.Admin;
+
+public class AdminAreaControllerRouteMapper : IAreaControllerRouteMapper
{
- public class AdminAreaControllerRouteMapper : IAreaControllerRouteMapper
+ private const string _defaultAreaPattern = "{area}/{controller}/{action}/{id?}";
+ private readonly string _adminUrlPrefix;
+
+ public int Order => -1000;
+
+ public AdminAreaControllerRouteMapper(IOptions adminOptions)
{
- private const string _defaultAreaPattern = "{area}/{controller}/{action}/{id?}";
- private readonly string _adminUrlPrefix;
+ _adminUrlPrefix = adminOptions.Value.AdminUrlPrefix;
+ }
- public int Order => -1000;
+ public bool TryMapAreaControllerRoute(IEndpointRouteBuilder routes, ControllerActionDescriptor descriptor)
+ {
+ var controllerAttribute = descriptor.ControllerTypeInfo.GetCustomAttribute();
+ var actionAttribute = descriptor.MethodInfo.GetCustomAttribute();
- public AdminAreaControllerRouteMapper(IOptions adminOptions)
+ if (descriptor.ControllerName != "Admin" && controllerAttribute == null && actionAttribute == null)
{
- _adminUrlPrefix = adminOptions.Value.AdminUrlPrefix;
+ return false;
}
- public bool TryMapAreaControllerRoute(IEndpointRouteBuilder routes, ControllerActionDescriptor descriptor)
+ string name = null;
+ var pattern = _defaultAreaPattern;
+
+ if (!string.IsNullOrWhiteSpace(actionAttribute?.Template))
{
- var controllerAttribute = descriptor.ControllerTypeInfo.GetCustomAttribute();
- var actionAttribute = descriptor.MethodInfo.GetCustomAttribute();
-
- if (descriptor.ControllerName != "Admin" && controllerAttribute == null && actionAttribute == null)
- {
- return false;
- }
-
- string name = null;
- var pattern = _defaultAreaPattern;
-
- if (!string.IsNullOrWhiteSpace(actionAttribute?.Template))
- {
- name = actionAttribute.RouteName;
- pattern = actionAttribute.Template;
- }
- else if (!string.IsNullOrWhiteSpace(controllerAttribute?.Template))
- {
- name = controllerAttribute.RouteName;
- pattern = controllerAttribute.Template;
- }
-
- var (area, controller, action) = RoutingHelper.GetMvcRouteValues(descriptor);
-
- routes.MapControllerRoute(
- name: RoutingHelper.ReplaceMvcPlaceholders(name, area, controller, action) ?? descriptor.DisplayName,
- pattern: $"{_adminUrlPrefix}/{RoutingHelper.ReplaceMvcPlaceholders(pattern.TrimStart('/'), area, controller, action)}",
- defaults: new { area, controller, action }
- );
-
- return true;
+ name = actionAttribute.RouteName;
+ pattern = actionAttribute.Template;
}
+ else if (!string.IsNullOrWhiteSpace(controllerAttribute?.Template))
+ {
+ name = controllerAttribute.RouteName;
+ pattern = controllerAttribute.Template;
+ }
+
+ var (area, controller, action) = RoutingHelper.GetMvcRouteValues(descriptor);
+
+ routes.MapControllerRoute(
+ name: RoutingHelper.ReplaceMvcPlaceholders(name, area, controller, action) ?? descriptor.DisplayName,
+ pattern: $"{_adminUrlPrefix}/{RoutingHelper.ReplaceMvcPlaceholders(pattern.TrimStart('/'), area, controller, action)}",
+ defaults: new { area, controller, action }
+ );
+
+ return true;
}
}
diff --git a/src/OrchardCore.Modules/OrchardCore.Admin/AdminFilter.cs b/src/OrchardCore.Modules/OrchardCore.Admin/AdminFilter.cs
index 9c9197e0822..b48f79ddbcf 100644
--- a/src/OrchardCore.Modules/OrchardCore.Admin/AdminFilter.cs
+++ b/src/OrchardCore.Modules/OrchardCore.Admin/AdminFilter.cs
@@ -4,63 +4,62 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
-namespace OrchardCore.Admin
+namespace OrchardCore.Admin;
+
+///
+/// Intercepts any request to check whether it applies to the admin site.
+/// If so it marks the request as such and ensures the user as the right to access it.
+///
+public sealed class AdminFilter : ActionFilterAttribute, IAsyncPageFilter
{
- ///
- /// Intercepts any request to check whether it applies to the admin site.
- /// If so it marks the request as such and ensures the user as the right to access it.
- ///
- public sealed class AdminFilter : ActionFilterAttribute, IAsyncPageFilter
+ private readonly IAuthorizationService _authorizationService;
+
+ public AdminFilter(IAuthorizationService authorizationService)
{
- private readonly IAuthorizationService _authorizationService;
+ _authorizationService = authorizationService;
+ }
- public AdminFilter(IAuthorizationService authorizationService)
- {
- _authorizationService = authorizationService;
- }
+ public override async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
+ {
+ ArgumentNullException.ThrowIfNull(context);
- public override async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
+ if (!await AuthorizeAsync(context.HttpContext))
{
- ArgumentNullException.ThrowIfNull(context);
+ context.Result = context.HttpContext.User?.Identity?.IsAuthenticated ?? false
+ ? new ForbidResult()
+ : new ChallengeResult();
+ return;
+ }
- if (!await AuthorizeAsync(context.HttpContext))
- {
- context.Result = context.HttpContext.User?.Identity?.IsAuthenticated ?? false
- ? new ForbidResult()
- : new ChallengeResult();
- return;
- }
+ await base.OnActionExecutionAsync(context, next);
+ }
- await base.OnActionExecutionAsync(context, next);
- }
+ public async Task OnPageHandlerExecutionAsync(PageHandlerExecutingContext context, PageHandlerExecutionDelegate next)
+ {
+ ArgumentNullException.ThrowIfNull(context);
- public async Task OnPageHandlerExecutionAsync(PageHandlerExecutingContext context, PageHandlerExecutionDelegate next)
+ if (!await AuthorizeAsync(context.HttpContext))
{
- ArgumentNullException.ThrowIfNull(context);
+ context.Result = new ChallengeResult();
+ return;
+ }
- if (!await AuthorizeAsync(context.HttpContext))
- {
- context.Result = new ChallengeResult();
- return;
- }
+ // Do post work.
+ await next.Invoke();
+ }
- // Do post work.
- await next.Invoke();
- }
+ public Task OnPageHandlerSelectionAsync(PageHandlerSelectedContext context)
+ {
+ return Task.CompletedTask;
+ }
- public Task OnPageHandlerSelectionAsync(PageHandlerSelectedContext context)
+ private Task AuthorizeAsync(Microsoft.AspNetCore.Http.HttpContext context)
+ {
+ if (AdminAttribute.IsApplied(context))
{
- return Task.CompletedTask;
+ return _authorizationService.AuthorizeAsync(context.User, AdminPermissions.AccessAdminPanel);
}
- private Task AuthorizeAsync(Microsoft.AspNetCore.Http.HttpContext context)
- {
- if (AdminAttribute.IsApplied(context))
- {
- return _authorizationService.AuthorizeAsync(context.User, AdminPermissions.AccessAdminPanel);
- }
-
- return Task.FromResult(true);
- }
+ return Task.FromResult(true);
}
}
diff --git a/src/OrchardCore.Modules/OrchardCore.Admin/AdminMenu.cs b/src/OrchardCore.Modules/OrchardCore.Admin/AdminMenu.cs
index 5a38b1e0527..ebd71358a49 100644
--- a/src/OrchardCore.Modules/OrchardCore.Admin/AdminMenu.cs
+++ b/src/OrchardCore.Modules/OrchardCore.Admin/AdminMenu.cs
@@ -4,43 +4,42 @@
using OrchardCore.Admin.Drivers;
using OrchardCore.Navigation;
-namespace OrchardCore.Admin
+namespace OrchardCore.Admin;
+
+public sealed class AdminMenu : INavigationProvider
{
- public sealed class AdminMenu : INavigationProvider
+ private static readonly RouteValueDictionary _routeValues = new()
{
- private static readonly RouteValueDictionary _routeValues = new()
- {
- { "area", "OrchardCore.Settings" },
- { "groupId", AdminSiteSettingsDisplayDriver.GroupId },
- };
+ { "area", "OrchardCore.Settings" },
+ { "groupId", AdminSiteSettingsDisplayDriver.GroupId },
+ };
- internal readonly IStringLocalizer S;
+ internal readonly IStringLocalizer S;
- public AdminMenu(IStringLocalizer localizer)
- {
- S = localizer;
- }
+ public AdminMenu(IStringLocalizer localizer)
+ {
+ S = localizer;
+ }
- public Task BuildNavigationAsync(string name, NavigationBuilder builder)
+ public Task BuildNavigationAsync(string name, NavigationBuilder builder)
+ {
+ if (!NavigationHelper.IsAdminMenu(name))
{
- if (!NavigationHelper.IsAdminMenu(name))
- {
- return Task.CompletedTask;
- }
+ return Task.CompletedTask;
+ }
- builder
- .Add(S["Configuration"], configuration => configuration
- .Add(S["Settings"], settings => settings
- .Add(S["Admin"], S["Admin"].PrefixPosition(), admin => admin
- .AddClass("admin").Id("admin")
- .Action("Index", "Admin", _routeValues)
- .Permission(PermissionsAdminSettings.ManageAdminSettings)
- .LocalNav()
- )
+ builder
+ .Add(S["Configuration"], configuration => configuration
+ .Add(S["Settings"], settings => settings
+ .Add(S["Admin"], S["Admin"].PrefixPosition(), admin => admin
+ .AddClass("admin").Id("admin")
+ .Action("Index", "Admin", _routeValues)
+ .Permission(PermissionsAdminSettings.ManageAdminSettings)
+ .LocalNav()
)
- );
+ )
+ );
- return Task.CompletedTask;
- }
+ return Task.CompletedTask;
}
}
diff --git a/src/OrchardCore.Modules/OrchardCore.Admin/AdminMenuFilter.cs b/src/OrchardCore.Modules/OrchardCore.Admin/AdminMenuFilter.cs
index 00d313ea21f..6f8d1bd28a0 100644
--- a/src/OrchardCore.Modules/OrchardCore.Admin/AdminMenuFilter.cs
+++ b/src/OrchardCore.Modules/OrchardCore.Admin/AdminMenuFilter.cs
@@ -5,73 +5,72 @@
using OrchardCore.DisplayManagement.Shapes;
using OrchardCore.Navigation;
-namespace OrchardCore.Admin
+namespace OrchardCore.Admin;
+
+///
+/// This filter inject a Navigation shape in the Navigation zone of the Layout
+/// for any ViewResult returned from an Admin controller.
+///
+public sealed class AdminMenuFilter : IAsyncResultFilter
{
- ///
- /// This filter inject a Navigation shape in the Navigation zone of the Layout
- /// for any ViewResult returned from an Admin controller.
- ///
- public sealed class AdminMenuFilter : IAsyncResultFilter
+ private readonly ILayoutAccessor _layoutAccessor;
+ private readonly IShapeFactory _shapeFactory;
+
+ public AdminMenuFilter(ILayoutAccessor layoutAccessor,
+ IShapeFactory shapeFactory)
{
- private readonly ILayoutAccessor _layoutAccessor;
- private readonly IShapeFactory _shapeFactory;
+ _layoutAccessor = layoutAccessor;
+ _shapeFactory = shapeFactory;
+ }
- public AdminMenuFilter(ILayoutAccessor layoutAccessor,
- IShapeFactory shapeFactory)
+ public async Task OnResultExecutionAsync(ResultExecutingContext filterContext, ResultExecutionDelegate next)
+ {
+ // Should only run on a full view rendering result
+ if (!filterContext.IsViewOrPageResult())
{
- _layoutAccessor = layoutAccessor;
- _shapeFactory = shapeFactory;
+ await next();
+ return;
}
- public async Task OnResultExecutionAsync(ResultExecutingContext filterContext, ResultExecutionDelegate next)
+ // Should only run on the Admin
+ if (!AdminAttribute.IsApplied(filterContext.HttpContext))
{
- // Should only run on a full view rendering result
- if (!filterContext.IsViewOrPageResult())
- {
- await next();
- return;
- }
+ await next();
+ return;
+ }
- // Should only run on the Admin
- if (!AdminAttribute.IsApplied(filterContext.HttpContext))
- {
- await next();
- return;
- }
+ // Should only run for authenticated users
+ if (!(filterContext.HttpContext.User?.Identity?.IsAuthenticated ?? false))
+ {
+ await next();
+ return;
+ }
- // Should only run for authenticated users
- if (!(filterContext.HttpContext.User?.Identity?.IsAuthenticated ?? false))
- {
- await next();
- return;
- }
+ // Don't create the menu if the status code is 3xx
+ var statusCode = filterContext.HttpContext.Response.StatusCode;
+ if (statusCode >= 300 && statusCode < 400)
+ {
+ await next();
+ return;
+ }
- // Don't create the menu if the status code is 3xx
- var statusCode = filterContext.HttpContext.Response.StatusCode;
- if (statusCode >= 300 && statusCode < 400)
+ // Populate main nav
+ var menuShape = await _shapeFactory.CreateAsync("Navigation",
+ Arguments.From(new
{
- await next();
- return;
- }
-
- // Populate main nav
- var menuShape = await _shapeFactory.CreateAsync("Navigation",
- Arguments.From(new
- {
- MenuName = NavigationConstants.AdminId,
- filterContext.RouteData,
- }));
+ MenuName = NavigationConstants.AdminId,
+ filterContext.RouteData,
+ }));
- var layout = await _layoutAccessor.GetLayoutAsync();
+ var layout = await _layoutAccessor.GetLayoutAsync();
- var navigation = layout.Zones["Navigation"];
+ var navigation = layout.Zones["Navigation"];
- if (navigation is Shape shape)
- {
- await shape.AddAsync(menuShape);
- }
-
- await next();
+ if (navigation is Shape shape)
+ {
+ await shape.AddAsync(menuShape);
}
+
+ await next();
}
}
diff --git a/src/OrchardCore.Modules/OrchardCore.Admin/AdminPageRouteModelConvention.cs b/src/OrchardCore.Modules/OrchardCore.Admin/AdminPageRouteModelConvention.cs
index 3ff8e6a0b50..852397c5cc1 100644
--- a/src/OrchardCore.Modules/OrchardCore.Admin/AdminPageRouteModelConvention.cs
+++ b/src/OrchardCore.Modules/OrchardCore.Admin/AdminPageRouteModelConvention.cs
@@ -1,35 +1,34 @@
using System.Linq;
using Microsoft.AspNetCore.Mvc.ApplicationModels;
-namespace OrchardCore.Admin
+namespace OrchardCore.Admin;
+
+public class AdminPageRouteModelConvention : IPageRouteModelConvention
{
- public class AdminPageRouteModelConvention : IPageRouteModelConvention
+ private readonly string _adminUrlPrefixTemplate;
+
+ public AdminPageRouteModelConvention(string adminUrlPrefix)
+ {
+ _adminUrlPrefixTemplate = adminUrlPrefix;
+ }
+
+ public void Apply(PageRouteModel model)
{
- private readonly string _adminUrlPrefixTemplate;
+ var route = model.Selectors.FirstOrDefault()?.AttributeRouteModel;
- public AdminPageRouteModelConvention(string adminUrlPrefix)
+ if (route == null)
{
- _adminUrlPrefixTemplate = adminUrlPrefix;
+ return;
}
- public void Apply(PageRouteModel model)
+ if (!route.Template.StartsWith(model.AreaName))
{
- var route = model.Selectors.FirstOrDefault()?.AttributeRouteModel;
-
- if (route == null)
- {
- return;
- }
-
- if (!route.Template.StartsWith(model.AreaName))
- {
- return;
- }
+ return;
+ }
- if (route.Template.Contains("/Admin/") || model.Properties.ContainsKey("Admin"))
- {
- route.Template = AttributeRouteModel.CombineTemplates(_adminUrlPrefixTemplate, route.Template);
- }
+ if (route.Template.Contains("/Admin/") || model.Properties.ContainsKey("Admin"))
+ {
+ route.Template = AttributeRouteModel.CombineTemplates(_adminUrlPrefixTemplate, route.Template);
}
}
}
diff --git a/src/OrchardCore.Modules/OrchardCore.Admin/AdminPageRouteModelProvider.cs b/src/OrchardCore.Modules/OrchardCore.Admin/AdminPageRouteModelProvider.cs
index 4ac4f126eb7..f76a60dfd63 100644
--- a/src/OrchardCore.Modules/OrchardCore.Admin/AdminPageRouteModelProvider.cs
+++ b/src/OrchardCore.Modules/OrchardCore.Admin/AdminPageRouteModelProvider.cs
@@ -10,98 +10,97 @@
using Microsoft.Extensions.Hosting;
using OrchardCore.Mvc;
-namespace OrchardCore.Admin
+namespace OrchardCore.Admin;
+
+internal sealed class AdminPageRouteModelProvider : IPageRouteModelProvider
{
- internal sealed class AdminPageRouteModelProvider : IPageRouteModelProvider
- {
- private readonly IHostEnvironment _hostingEnvironment;
- private readonly ApplicationPartManager _applicationManager;
+ private readonly IHostEnvironment _hostingEnvironment;
+ private readonly ApplicationPartManager _applicationManager;
- public AdminPageRouteModelProvider(IHostEnvironment hostingEnvironment, ApplicationPartManager applicationManager)
- {
- _hostingEnvironment = hostingEnvironment;
- _applicationManager = applicationManager;
- }
+ public AdminPageRouteModelProvider(IHostEnvironment hostingEnvironment, ApplicationPartManager applicationManager)
+ {
+ _hostingEnvironment = hostingEnvironment;
+ _applicationManager = applicationManager;
+ }
- public int Order => 1000;
+ public int Order => 1000;
- public void OnProvidersExecuting(PageRouteModelProviderContext context)
- {
- ArgumentNullException.ThrowIfNull(context);
+ public void OnProvidersExecuting(PageRouteModelProviderContext context)
+ {
+ ArgumentNullException.ThrowIfNull(context);
- IEnumerable descriptors;
+ IEnumerable descriptors;
- var refsFolderExists = Directory.Exists(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "refs"));
+ var refsFolderExists = Directory.Exists(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "refs"));
- if (_hostingEnvironment.IsDevelopment() && refsFolderExists)
- {
- descriptors = GetPageDescriptors(_applicationManager);
- }
- else
- {
- descriptors = GetPageDescriptors(_applicationManager);
- }
+ if (_hostingEnvironment.IsDevelopment() && refsFolderExists)
+ {
+ descriptors = GetPageDescriptors(_applicationManager);
+ }
+ else
+ {
+ descriptors = GetPageDescriptors(_applicationManager);
+ }
- var adminPaths = new HashSet(StringComparer.OrdinalIgnoreCase);
+ var adminPaths = new HashSet(StringComparer.OrdinalIgnoreCase);
- foreach (var descriptor in descriptors)
+ foreach (var descriptor in descriptors)
+ {
+ foreach (var type in descriptor.Type.GetNestedTypes())
{
- foreach (var type in descriptor.Type.GetNestedTypes())
- {
- var attribute = type.GetCustomAttribute();
-
- if (attribute != null)
- {
- adminPaths.Add(descriptor.RelativePath);
- break;
- }
- }
- }
+ var attribute = type.GetCustomAttribute();
- foreach (var model in context.RouteModels.ToArray())
- {
- if (adminPaths.Contains(model.RelativePath))
+ if (attribute != null)
{
- model.Properties["Admin"] = null;
+ adminPaths.Add(descriptor.RelativePath);
+ break;
}
}
}
- public void OnProvidersExecuted(PageRouteModelProviderContext context)
+ foreach (var model in context.RouteModels.ToArray())
{
+ if (adminPaths.Contains(model.RelativePath))
+ {
+ model.Properties["Admin"] = null;
+ }
}
+ }
- private static IEnumerable GetPageDescriptors(ApplicationPartManager applicationManager)
- where T : ViewsFeature, new()
- {
- ArgumentNullException.ThrowIfNull(applicationManager);
+ public void OnProvidersExecuted(PageRouteModelProviderContext context)
+ {
+ }
- var viewsFeature = GetViewFeature(applicationManager);
+ private static IEnumerable GetPageDescriptors(ApplicationPartManager applicationManager)
+ where T : ViewsFeature, new()
+ {
+ ArgumentNullException.ThrowIfNull(applicationManager);
- var visited = new HashSet(StringComparer.OrdinalIgnoreCase);
+ var viewsFeature = GetViewFeature(applicationManager);
- foreach (var viewDescriptor in viewsFeature.ViewDescriptors)
+ var visited = new HashSet(StringComparer.OrdinalIgnoreCase);
+
+ foreach (var viewDescriptor in viewsFeature.ViewDescriptors)
+ {
+ if (!visited.Add(viewDescriptor.RelativePath))
{
- if (!visited.Add(viewDescriptor.RelativePath))
- {
- continue;
- }
+ continue;
+ }
- if (IsRazorPage(viewDescriptor))
- {
- yield return viewDescriptor;
- }
+ if (IsRazorPage(viewDescriptor))
+ {
+ yield return viewDescriptor;
}
}
+ }
- private static bool IsRazorPage(CompiledViewDescriptor viewDescriptor) =>
- viewDescriptor.Item?.Kind == RazorPageDocumentClassifierPass.RazorPageDocumentKind;
+ private static bool IsRazorPage(CompiledViewDescriptor viewDescriptor) =>
+ viewDescriptor.Item?.Kind == RazorPageDocumentClassifierPass.RazorPageDocumentKind;
- private static T GetViewFeature(ApplicationPartManager applicationManager) where T : ViewsFeature, new()
- {
- var viewsFeature = new T();
- applicationManager.PopulateFeature(viewsFeature);
- return viewsFeature;
- }
+ private static T GetViewFeature(ApplicationPartManager applicationManager) where T : ViewsFeature, new()
+ {
+ var viewsFeature = new T();
+ applicationManager.PopulateFeature(viewsFeature);
+ return viewsFeature;
}
}
diff --git a/src/OrchardCore.Modules/OrchardCore.Admin/AdminThemeSelector.cs b/src/OrchardCore.Modules/OrchardCore.Admin/AdminThemeSelector.cs
index a5c3659139b..ade57f59e8b 100644
--- a/src/OrchardCore.Modules/OrchardCore.Admin/AdminThemeSelector.cs
+++ b/src/OrchardCore.Modules/OrchardCore.Admin/AdminThemeSelector.cs
@@ -2,45 +2,44 @@
using Microsoft.AspNetCore.Http;
using OrchardCore.DisplayManagement.Theming;
-namespace OrchardCore.Admin
+namespace OrchardCore.Admin;
+
+///
+/// Provides the theme defined in the site configuration for the current scope (request).
+/// The same is returned if called multiple times
+/// during the same scope.
+///
+public class AdminThemeSelector : IThemeSelector
{
- ///
- /// Provides the theme defined in the site configuration for the current scope (request).
- /// The same is returned if called multiple times
- /// during the same scope.
- ///
- public class AdminThemeSelector : IThemeSelector
- {
- private readonly IAdminThemeService _adminThemeService;
- private readonly IHttpContextAccessor _httpContextAccessor;
+ private readonly IAdminThemeService _adminThemeService;
+ private readonly IHttpContextAccessor _httpContextAccessor;
- public AdminThemeSelector(
- IAdminThemeService adminThemeService,
- IHttpContextAccessor httpContextAccessor
- )
- {
- _adminThemeService = adminThemeService;
- _httpContextAccessor = httpContextAccessor;
- }
+ public AdminThemeSelector(
+ IAdminThemeService adminThemeService,
+ IHttpContextAccessor httpContextAccessor
+ )
+ {
+ _adminThemeService = adminThemeService;
+ _httpContextAccessor = httpContextAccessor;
+ }
- public async Task GetThemeAsync()
+ public async Task GetThemeAsync()
+ {
+ if (AdminAttribute.IsApplied(_httpContextAccessor.HttpContext))
{
- if (AdminAttribute.IsApplied(_httpContextAccessor.HttpContext))
+ var adminThemeName = await _adminThemeService.GetAdminThemeNameAsync();
+ if (string.IsNullOrEmpty(adminThemeName))
{
- var adminThemeName = await _adminThemeService.GetAdminThemeNameAsync();
- if (string.IsNullOrEmpty(adminThemeName))
- {
- return null;
- }
-
- return new ThemeSelectorResult
- {
- Priority = 100,
- ThemeName = adminThemeName
- };
+ return null;
}
- return null;
+ return new ThemeSelectorResult
+ {
+ Priority = 100,
+ ThemeName = adminThemeName
+ };
}
+
+ return null;
}
}
diff --git a/src/OrchardCore.Modules/OrchardCore.Admin/AdminThemeService.cs b/src/OrchardCore.Modules/OrchardCore.Admin/AdminThemeService.cs
index 08a0f538e8e..8d3e75d1fd8 100644
--- a/src/OrchardCore.Modules/OrchardCore.Admin/AdminThemeService.cs
+++ b/src/OrchardCore.Modules/OrchardCore.Admin/AdminThemeService.cs
@@ -2,43 +2,42 @@
using OrchardCore.Environment.Extensions;
using OrchardCore.Settings;
-namespace OrchardCore.Admin
+namespace OrchardCore.Admin;
+
+public class AdminThemeService : IAdminThemeService
{
- public class AdminThemeService : IAdminThemeService
+ private readonly ISiteService _siteService;
+ private readonly IExtensionManager _extensionManager;
+
+ public AdminThemeService(
+ ISiteService siteService,
+ IExtensionManager extensionManager)
{
- private readonly ISiteService _siteService;
- private readonly IExtensionManager _extensionManager;
+ _siteService = siteService;
+ _extensionManager = extensionManager;
+ }
- public AdminThemeService(
- ISiteService siteService,
- IExtensionManager extensionManager)
+ public async Task GetAdminThemeAsync()
+ {
+ var currentThemeName = await GetAdminThemeNameAsync();
+ if (string.IsNullOrEmpty(currentThemeName))
{
- _siteService = siteService;
- _extensionManager = extensionManager;
+ return null;
}
- public async Task GetAdminThemeAsync()
- {
- var currentThemeName = await GetAdminThemeNameAsync();
- if (string.IsNullOrEmpty(currentThemeName))
- {
- return null;
- }
-
- return _extensionManager.GetExtension(currentThemeName);
- }
+ return _extensionManager.GetExtension(currentThemeName);
+ }
- public async Task SetAdminThemeAsync(string themeName)
- {
- var site = await _siteService.LoadSiteSettingsAsync();
- site.Properties["CurrentAdminThemeName"] = themeName;
- await _siteService.UpdateSiteSettingsAsync(site);
- }
+ public async Task SetAdminThemeAsync(string themeName)
+ {
+ var site = await _siteService.LoadSiteSettingsAsync();
+ site.Properties["CurrentAdminThemeName"] = themeName;
+ await _siteService.UpdateSiteSettingsAsync(site);
+ }
- public async Task GetAdminThemeNameAsync()
- {
- var site = await _siteService.GetSiteSettingsAsync();
- return (string)site.Properties["CurrentAdminThemeName"];
- }
+ public async Task GetAdminThemeNameAsync()
+ {
+ var site = await _siteService.GetSiteSettingsAsync();
+ return (string)site.Properties["CurrentAdminThemeName"];
}
}
diff --git a/src/OrchardCore.Modules/OrchardCore.Admin/AdminZoneFilter.cs b/src/OrchardCore.Modules/OrchardCore.Admin/AdminZoneFilter.cs
index 63abff0170b..d40a4575467 100644
--- a/src/OrchardCore.Modules/OrchardCore.Admin/AdminZoneFilter.cs
+++ b/src/OrchardCore.Modules/OrchardCore.Admin/AdminZoneFilter.cs
@@ -3,32 +3,31 @@
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.AspNetCore.Mvc.RazorPages;
-namespace OrchardCore.Admin
+namespace OrchardCore.Admin;
+
+///
+/// This filter makes an controller that starts with Admin and Razor Pages in /Pages/Admin folder behave as
+/// it had the .
+///
+public sealed class AdminZoneFilter : IAsyncResourceFilter
{
- ///
- /// This filter makes an controller that starts with Admin and Razor Pages in /Pages/Admin folder behave as
- /// it had the .
- ///
- public sealed class AdminZoneFilter : IAsyncResourceFilter
+ public Task OnResourceExecutionAsync(ResourceExecutingContext context, ResourceExecutionDelegate next)
{
- public Task OnResourceExecutionAsync(ResourceExecutingContext context, ResourceExecutionDelegate next)
+ if (context.ActionDescriptor is ControllerActionDescriptor action)
{
- if (context.ActionDescriptor is ControllerActionDescriptor action)
+ if (action.ControllerName == "Admin")
{
- if (action.ControllerName == "Admin")
- {
- AdminAttribute.Apply(context.HttpContext);
- }
+ AdminAttribute.Apply(context.HttpContext);
}
- else if (context.ActionDescriptor is PageActionDescriptor page)
+ }
+ else if (context.ActionDescriptor is PageActionDescriptor page)
+ {
+ if (page.ViewEnginePath.Contains("/Admin/"))
{
- if (page.ViewEnginePath.Contains("/Admin/"))
- {
- AdminAttribute.Apply(context.HttpContext);
- }
+ AdminAttribute.Apply(context.HttpContext);
}
-
- return next();
}
+
+ return next();
}
}
diff --git a/src/OrchardCore.Modules/OrchardCore.Admin/Controllers/AdminController.cs b/src/OrchardCore.Modules/OrchardCore.Admin/Controllers/AdminController.cs
index 0d020a8dc5b..95687dd2bdd 100644
--- a/src/OrchardCore.Modules/OrchardCore.Admin/Controllers/AdminController.cs
+++ b/src/OrchardCore.Modules/OrchardCore.Admin/Controllers/AdminController.cs
@@ -1,14 +1,13 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
-namespace OrchardCore.Admin.Controllers
+namespace OrchardCore.Admin.Controllers;
+
+[Authorize]
+public class AdminController : Controller
{
- [Authorize]
- public class AdminController : Controller
+ public IActionResult Index()
{
- public IActionResult Index()
- {
- return View();
- }
+ return View();
}
}
diff --git a/src/OrchardCore.Modules/OrchardCore.Admin/Drivers/AdminSiteSettingsDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Admin/Drivers/AdminSiteSettingsDisplayDriver.cs
index 73b9ff6e8e1..ef8fb39f354 100644
--- a/src/OrchardCore.Modules/OrchardCore.Admin/Drivers/AdminSiteSettingsDisplayDriver.cs
+++ b/src/OrchardCore.Modules/OrchardCore.Admin/Drivers/AdminSiteSettingsDisplayDriver.cs
@@ -9,64 +9,63 @@
using OrchardCore.DisplayManagement.Views;
using OrchardCore.Settings;
-namespace OrchardCore.Admin.Drivers
+namespace OrchardCore.Admin.Drivers;
+
+public sealed class AdminSiteSettingsDisplayDriver : SiteDisplayDriver
{
- public sealed class AdminSiteSettingsDisplayDriver : SiteDisplayDriver
+ public const string GroupId = "admin";
+
+ private readonly IHttpContextAccessor _httpContextAccessor;
+ private readonly IAuthorizationService _authorizationService;
+
+ public AdminSiteSettingsDisplayDriver(
+ IHttpContextAccessor httpContextAccessor,
+ IAuthorizationService authorizationService)
{
- public const string GroupId = "admin";
+ _httpContextAccessor = httpContextAccessor;
+ _authorizationService = authorizationService;
+ }
- private readonly IHttpContextAccessor _httpContextAccessor;
- private readonly IAuthorizationService _authorizationService;
+ protected override string SettingsGroupId
+ => GroupId;
- public AdminSiteSettingsDisplayDriver(
- IHttpContextAccessor httpContextAccessor,
- IAuthorizationService authorizationService)
+ public override async Task EditAsync(ISite site, AdminSettings settings, BuildEditorContext context)
+ {
+ var user = _httpContextAccessor.HttpContext?.User;
+
+ if (!await _authorizationService.AuthorizeAsync(user, PermissionsAdminSettings.ManageAdminSettings))
{
- _httpContextAccessor = httpContextAccessor;
- _authorizationService = authorizationService;
+ return null;
}
- protected override string SettingsGroupId
- => GroupId;
-
- public override async Task EditAsync(ISite site, AdminSettings settings, BuildEditorContext context)
+ return Initialize("AdminSettings_Edit", model =>
{
- var user = _httpContextAccessor.HttpContext?.User;
-
- if (!await _authorizationService.AuthorizeAsync(user, PermissionsAdminSettings.ManageAdminSettings))
- {
- return null;
- }
+ model.DisplayThemeToggler = settings.DisplayThemeToggler;
+ model.DisplayMenuFilter = settings.DisplayMenuFilter;
+ model.DisplayNewMenu = settings.DisplayNewMenu;
+ model.DisplayTitlesInTopbar = settings.DisplayTitlesInTopbar;
+ }).Location("Content:3")
+ .OnGroup(SettingsGroupId);
+ }
- return Initialize("AdminSettings_Edit", model =>
- {
- model.DisplayThemeToggler = settings.DisplayThemeToggler;
- model.DisplayMenuFilter = settings.DisplayMenuFilter;
- model.DisplayNewMenu = settings.DisplayNewMenu;
- model.DisplayTitlesInTopbar = settings.DisplayTitlesInTopbar;
- }).Location("Content:3")
- .OnGroup(SettingsGroupId);
- }
+ public override async Task UpdateAsync(ISite site, AdminSettings settings, UpdateEditorContext context)
+ {
+ var user = _httpContextAccessor.HttpContext?.User;
- public override async Task UpdateAsync(ISite site, AdminSettings settings, UpdateEditorContext context)
+ if (!await _authorizationService.AuthorizeAsync(user, PermissionsAdminSettings.ManageAdminSettings))
{
- var user = _httpContextAccessor.HttpContext?.User;
-
- if (!await _authorizationService.AuthorizeAsync(user, PermissionsAdminSettings.ManageAdminSettings))
- {
- return null;
- }
+ return null;
+ }
- var model = new AdminSettingsViewModel();
+ var model = new AdminSettingsViewModel();
- await context.Updater.TryUpdateModelAsync(model, Prefix);
+ await context.Updater.TryUpdateModelAsync(model, Prefix);
- settings.DisplayThemeToggler = model.DisplayThemeToggler;
- settings.DisplayMenuFilter = model.DisplayMenuFilter;
- settings.DisplayNewMenu = model.DisplayNewMenu;
- settings.DisplayTitlesInTopbar = model.DisplayTitlesInTopbar;
+ settings.DisplayThemeToggler = model.DisplayThemeToggler;
+ settings.DisplayMenuFilter = model.DisplayMenuFilter;
+ settings.DisplayNewMenu = model.DisplayNewMenu;
+ settings.DisplayTitlesInTopbar = model.DisplayTitlesInTopbar;
- return await EditAsync(site, settings, context);
- }
+ return await EditAsync(site, settings, context);
}
}
diff --git a/src/OrchardCore.Modules/OrchardCore.Admin/Startup.cs b/src/OrchardCore.Modules/OrchardCore.Admin/Startup.cs
index d52f4a06e78..821441a2107 100644
--- a/src/OrchardCore.Modules/OrchardCore.Admin/Startup.cs
+++ b/src/OrchardCore.Modules/OrchardCore.Admin/Startup.cs
@@ -26,102 +26,101 @@
using OrchardCore.Settings;
using OrchardCore.Settings.Deployment;
-namespace OrchardCore.Admin
+namespace OrchardCore.Admin;
+
+public sealed class Startup : StartupBase
{
- public sealed class Startup : StartupBase
+ private readonly AdminOptions _adminOptions;
+ private readonly IShellConfiguration _configuration;
+
+ public Startup(IOptions adminOptions, IShellConfiguration configuration)
{
- private readonly AdminOptions _adminOptions;
- private readonly IShellConfiguration _configuration;
+ _adminOptions = adminOptions.Value;
+ _configuration = configuration;
+ }
- public Startup(IOptions adminOptions, IShellConfiguration configuration)
- {
- _adminOptions = adminOptions.Value;
- _configuration = configuration;
- }
+ public override void ConfigureServices(IServiceCollection services)
+ {
+ services.AddNavigation();
- public override void ConfigureServices(IServiceCollection services)
+ services.Configure((options) =>
{
- services.AddNavigation();
+ options.Filters.Add();
+ options.Filters.Add();
- services.Configure((options) =>
- {
- options.Filters.Add();
- options.Filters.Add();
-
- // Ordered to be called before any global filter.
- options.Filters.Add(-1000);
- });
-
- services.AddTransient();
- services.AddScoped();
- services.AddScoped();
- services.AddScoped();
- services.AddScoped, AdminSiteSettingsDisplayDriver>();
- services.AddScoped();
- services.AddScoped();
- services.AddSingleton();
- services.AddScoped, VisitSiteNavbarDisplayDriver>();
-
- services.Configure(_configuration.GetSection("OrchardCore_Admin"));
- }
-
- public override void Configure(IApplicationBuilder builder, IEndpointRouteBuilder routes, IServiceProvider serviceProvider)
- {
- routes.MapAreaControllerRoute(
- name: "Admin",
- areaName: "OrchardCore.Admin",
- pattern: _adminOptions.AdminUrlPrefix,
- defaults: new { controller = typeof(AdminController).ControllerName(), action = nameof(AdminController.Index) }
- );
- }
+ // Ordered to be called before any global filter.
+ options.Filters.Add(-1000);
+ });
+
+ services.AddTransient();
+ services.AddScoped();
+ services.AddScoped();
+ services.AddScoped();
+ services.AddScoped, AdminSiteSettingsDisplayDriver>();
+ services.AddScoped();
+ services.AddScoped();
+ services.AddSingleton();
+ services.AddScoped, VisitSiteNavbarDisplayDriver>();
+
+ services.Configure(_configuration.GetSection("OrchardCore_Admin"));
}
- public sealed class AdminPagesStartup : StartupBase
+ public override void Configure(IApplicationBuilder builder, IEndpointRouteBuilder routes, IServiceProvider serviceProvider)
{
- public override int Order
- => OrchardCoreConstants.ConfigureOrder.AdminPages;
+ routes.MapAreaControllerRoute(
+ name: "Admin",
+ areaName: "OrchardCore.Admin",
+ pattern: _adminOptions.AdminUrlPrefix,
+ defaults: new { controller = typeof(AdminController).ControllerName(), action = nameof(AdminController.Index) }
+ );
+ }
+}
+
+public sealed class AdminPagesStartup : StartupBase
+{
+ public override int Order
+ => OrchardCoreConstants.ConfigureOrder.AdminPages;
- public override void ConfigureServices(IServiceCollection services)
+ public override void ConfigureServices(IServiceCollection services)
+ {
+ services.Configure((options) =>
{
- services.Configure((options) =>
- {
- var adminOptions = ShellScope.Services.GetRequiredService>().Value;
- options.Conventions.Add(new AdminPageRouteModelConvention(adminOptions.AdminUrlPrefix));
- });
- }
+ var adminOptions = ShellScope.Services.GetRequiredService>().Value;
+ options.Conventions.Add(new AdminPageRouteModelConvention(adminOptions.AdminUrlPrefix));
+ });
}
+}
- [RequireFeatures("OrchardCore.Deployment")]
- public sealed class DeploymentStartup : StartupBase
+[RequireFeatures("OrchardCore.Deployment")]
+public sealed class DeploymentStartup : StartupBase
+{
+ public override void ConfigureServices(IServiceCollection services)
{
- public override void ConfigureServices(IServiceCollection services)
- {
- services.AddSiteSettingsPropertyDeploymentStep(S => S["Admin settings"], S => S["Exports the admin settings."]);
- }
+ services.AddSiteSettingsPropertyDeploymentStep(S => S["Admin settings"], S => S["Exports the admin settings."]);
}
+}
- [RequireFeatures("OrchardCore.Liquid")]
- public sealed class LiquidStartup : StartupBase
+[RequireFeatures("OrchardCore.Liquid")]
+public sealed class LiquidStartup : StartupBase
+{
+ public override void ConfigureServices(IServiceCollection services)
{
- public override void ConfigureServices(IServiceCollection services)
+ services.Configure(o =>
{
- services.Configure(o =>
+ o.Scope.SetValue(nameof(Navbar), new FunctionValue(async (args, ctx) =>
{
- o.Scope.SetValue(nameof(Navbar), new FunctionValue(async (args, ctx) =>
+ if (ctx is LiquidTemplateContext context)
{
- if (ctx is LiquidTemplateContext context)
- {
- var displayManager = context.Services.GetRequiredService>();
- var updateModelAccessor = context.Services.GetRequiredService();
+ var displayManager = context.Services.GetRequiredService>();
+ var updateModelAccessor = context.Services.GetRequiredService();
- var shape = await displayManager.BuildDisplayAsync(updateModelAccessor.ModelUpdater);
+ var shape = await displayManager.BuildDisplayAsync(updateModelAccessor.ModelUpdater);
- return FluidValue.Create(shape, ctx.Options);
- }
+ return FluidValue.Create(shape, ctx.Options);
+ }
- return NilValue.Instance;
- }));
- });
- }
+ return NilValue.Instance;
+ }));
+ });
}
}
diff --git a/src/OrchardCore.Modules/OrchardCore.Admin/ViewModels/AdminSettingsViewModel.cs b/src/OrchardCore.Modules/OrchardCore.Admin/ViewModels/AdminSettingsViewModel.cs
index f0149d2b2f5..d94df30eaaf 100644
--- a/src/OrchardCore.Modules/OrchardCore.Admin/ViewModels/AdminSettingsViewModel.cs
+++ b/src/OrchardCore.Modules/OrchardCore.Admin/ViewModels/AdminSettingsViewModel.cs
@@ -1,13 +1,12 @@
-namespace OrchardCore.Admin.ViewModels
+namespace OrchardCore.Admin.ViewModels;
+
+public class AdminSettingsViewModel
{
- public class AdminSettingsViewModel
- {
- public bool DisplayThemeToggler { get; set; }
+ public bool DisplayThemeToggler { get; set; }
- public bool DisplayMenuFilter { get; set; }
+ public bool DisplayMenuFilter { get; set; }
- public bool DisplayNewMenu { get; set; }
+ public bool DisplayNewMenu { get; set; }
- public bool DisplayTitlesInTopbar { get; set; }
- }
+ public bool DisplayTitlesInTopbar { get; set; }
}
diff --git a/src/OrchardCore.Modules/OrchardCore.AdminDashboard/Controllers/DashboardController.cs b/src/OrchardCore.Modules/OrchardCore.AdminDashboard/Controllers/DashboardController.cs
index 6fc1b3d8ee1..31d0ea22f2f 100644
--- a/src/OrchardCore.Modules/OrchardCore.AdminDashboard/Controllers/DashboardController.cs
+++ b/src/OrchardCore.Modules/OrchardCore.AdminDashboard/Controllers/DashboardController.cs
@@ -16,196 +16,195 @@
using OrchardCore.Contents;
using OrchardCore.DisplayManagement.ModelBinding;
-namespace OrchardCore.AdminDashboard.Controllers
+namespace OrchardCore.AdminDashboard.Controllers;
+
+[Admin]
+public class DashboardController : Controller
{
- [Admin]
- public class DashboardController : Controller
+ private readonly IAuthorizationService _authorizationService;
+ private readonly IAdminDashboardService _adminDashboardService;
+ private readonly IContentManager _contentManager;
+ private readonly IContentItemDisplayManager _contentItemDisplayManager;
+ private readonly IContentDefinitionManager _contentDefinitionManager;
+ private readonly IUpdateModelAccessor _updateModelAccessor;
+ private readonly YesSql.ISession _session;
+
+ public DashboardController(
+ IAuthorizationService authorizationService,
+ IAdminDashboardService adminDashboardService,
+ IContentManager contentManager,
+ IContentItemDisplayManager contentItemDisplayManager,
+ IContentDefinitionManager contentDefinitionManager,
+ IUpdateModelAccessor updateModelAccessor,
+ YesSql.ISession session)
{
- private readonly IAuthorizationService _authorizationService;
- private readonly IAdminDashboardService _adminDashboardService;
- private readonly IContentManager _contentManager;
- private readonly IContentItemDisplayManager _contentItemDisplayManager;
- private readonly IContentDefinitionManager _contentDefinitionManager;
- private readonly IUpdateModelAccessor _updateModelAccessor;
- private readonly YesSql.ISession _session;
-
- public DashboardController(
- IAuthorizationService authorizationService,
- IAdminDashboardService adminDashboardService,
- IContentManager contentManager,
- IContentItemDisplayManager contentItemDisplayManager,
- IContentDefinitionManager contentDefinitionManager,
- IUpdateModelAccessor updateModelAccessor,
- YesSql.ISession session)
+ _authorizationService = authorizationService;
+ _adminDashboardService = adminDashboardService;
+ _contentManager = contentManager;
+ _contentItemDisplayManager = contentItemDisplayManager;
+ _contentDefinitionManager = contentDefinitionManager;
+ _updateModelAccessor = updateModelAccessor;
+ _session = session;
+ }
+
+ public async Task Index()
+ {
+ var model = new AdminDashboardViewModel()
{
- _authorizationService = authorizationService;
- _adminDashboardService = adminDashboardService;
- _contentManager = contentManager;
- _contentItemDisplayManager = contentItemDisplayManager;
- _contentDefinitionManager = contentDefinitionManager;
- _updateModelAccessor = updateModelAccessor;
- _session = session;
- }
+ CanManageDashboard = await _authorizationService.AuthorizeAsync(User, Permissions.ManageAdminDashboard),
+ };
- public async Task Index()
+ if (model.CanManageDashboard || await _authorizationService.AuthorizeAsync(User, Permissions.AccessAdminDashboard))
{
- var model = new AdminDashboardViewModel()
- {
- CanManageDashboard = await _authorizationService.AuthorizeAsync(User, Permissions.ManageAdminDashboard),
- };
+ var wrappers = new List();
+ var widgetContentTypes = await GetDashboardWidgetsAsync();
- if (model.CanManageDashboard || await _authorizationService.AuthorizeAsync(User, Permissions.AccessAdminDashboard))
+ var widgets = await _adminDashboardService.GetWidgetsAsync(x => x.Published);
+ foreach (var widget in widgets)
{
- var wrappers = new List();
- var widgetContentTypes = await GetDashboardWidgetsAsync();
+ if (!widgetContentTypes.ContainsKey(widget.ContentType))
+ {
+ continue;
+ }
- var widgets = await _adminDashboardService.GetWidgetsAsync(x => x.Published);
- foreach (var widget in widgets)
+ if (!model.CanManageDashboard && !await _authorizationService.AuthorizeAsync(User, CommonPermissions.ViewContent, widget))
{
- if (!widgetContentTypes.ContainsKey(widget.ContentType))
- {
- continue;
- }
-
- if (!model.CanManageDashboard && !await _authorizationService.AuthorizeAsync(User, CommonPermissions.ViewContent, widget))
- {
- continue;
- }
-
- wrappers.Add(new DashboardWrapper
- {
- Dashboard = widget,
- Content = await _contentItemDisplayManager.BuildDisplayAsync(widget, _updateModelAccessor.ModelUpdater, "DetailAdmin")
- });
+ continue;
}
- model.Dashboards = wrappers.ToArray();
+ wrappers.Add(new DashboardWrapper
+ {
+ Dashboard = widget,
+ Content = await _contentItemDisplayManager.BuildDisplayAsync(widget, _updateModelAccessor.ModelUpdater, "DetailAdmin")
+ });
}
- return View(model);
+ model.Dashboards = wrappers.ToArray();
}
- [Admin("dashboard/manage", "AdminDashboard")]
- public async Task Manage()
+ return View(model);
+ }
+
+ [Admin("dashboard/manage", "AdminDashboard")]
+ public async Task Manage()
+ {
+ if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageAdminDashboard))
{
- if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageAdminDashboard))
- {
- return Forbid();
- }
+ return Forbid();
+ }
- // Set Manage Dashboard Feature.
- Request.HttpContext.Features.Set(new DashboardFeature()
- {
- IsManageRequest = true
- });
+ // Set Manage Dashboard Feature.
+ Request.HttpContext.Features.Set(new DashboardFeature()
+ {
+ IsManageRequest = true
+ });
- var dashboardCreatable = new List();
- var widgetContentTypes = await GetDashboardWidgetsAsync();
+ var dashboardCreatable = new List();
+ var widgetContentTypes = await GetDashboardWidgetsAsync();
- var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
+ var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
- foreach (var ctd in widgetContentTypes.Values.OrderBy(x => x.DisplayName))
+ foreach (var ctd in widgetContentTypes.Values.OrderBy(x => x.DisplayName))
+ {
+ if (!await _authorizationService.AuthorizeContentTypeAsync(User, CommonPermissions.EditContent, ctd.Name, userId))
{
- if (!await _authorizationService.AuthorizeContentTypeAsync(User, CommonPermissions.EditContent, ctd.Name, userId))
- {
- continue;
- }
-
- dashboardCreatable.Add(new SelectListItem(ctd.DisplayName, ctd.Name));
+ continue;
}
- var widgets = await _adminDashboardService.GetWidgetsAsync(x => x.Latest);
- var wrappers = new List();
- foreach (var widget in widgets)
- {
- if (!widgetContentTypes.ContainsKey(widget.ContentType)
- || !await _authorizationService.AuthorizeContentTypeAsync(User, CommonPermissions.EditContent, widget.ContentType, userId))
- {
- continue;
- }
-
- var wrapper = new DashboardWrapper
- {
- Dashboard = widget,
- Content = await _contentItemDisplayManager.BuildDisplayAsync(widget, _updateModelAccessor.ModelUpdater, "DetailAdmin")
- };
+ dashboardCreatable.Add(new SelectListItem(ctd.DisplayName, ctd.Name));
+ }
- wrappers.Add(wrapper);
+ var widgets = await _adminDashboardService.GetWidgetsAsync(x => x.Latest);
+ var wrappers = new List();
+ foreach (var widget in widgets)
+ {
+ if (!widgetContentTypes.ContainsKey(widget.ContentType)
+ || !await _authorizationService.AuthorizeContentTypeAsync(User, CommonPermissions.EditContent, widget.ContentType, userId))
+ {
+ continue;
}
- var model = new AdminDashboardViewModel
+ var wrapper = new DashboardWrapper
{
- Dashboards = wrappers.ToArray(),
- Creatable = dashboardCreatable
+ Dashboard = widget,
+ Content = await _contentItemDisplayManager.BuildDisplayAsync(widget, _updateModelAccessor.ModelUpdater, "DetailAdmin")
};
- return View(model);
+ wrappers.Add(wrapper);
}
- [HttpPost]
- public async Task Update([FromForm] DashboardPartViewModel[] parts)
+ var model = new AdminDashboardViewModel
{
- if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageAdminDashboard))
- {
- return Unauthorized();
- }
+ Dashboards = wrappers.ToArray(),
+ Creatable = dashboardCreatable
+ };
- var contentItemIds = parts.Select(i => i.ContentItemId).ToArray();
+ return View(model);
+ }
- // Load the latest version first if any.
- var latestItems = await _contentManager.GetAsync(contentItemIds, VersionOptions.Latest);
+ [HttpPost]
+ public async Task Update([FromForm] DashboardPartViewModel[] parts)
+ {
+ if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageAdminDashboard))
+ {
+ return Unauthorized();
+ }
- if (latestItems == null)
- {
- return NotFound();
- }
+ var contentItemIds = parts.Select(i => i.ContentItemId).ToArray();
+
+ // Load the latest version first if any.
+ var latestItems = await _contentManager.GetAsync(contentItemIds, VersionOptions.Latest);
+
+ if (latestItems == null)
+ {
+ return NotFound();
+ }
- var publishedItems = await _contentManager.GetAsync(contentItemIds, VersionOptions.Published);
+ var publishedItems = await _contentManager.GetAsync(contentItemIds, VersionOptions.Published);
- foreach (var contentItem in latestItems)
+ foreach (var contentItem in latestItems)
+ {
+ var dashboardPart = contentItem.As();
+ if (dashboardPart == null)
{
- var dashboardPart = contentItem.As();
- if (dashboardPart == null)
- {
- return Forbid();
- }
+ return Forbid();
+ }
- var partViewModel = parts.FirstOrDefault(m => m.ContentItemId == contentItem.ContentItemId);
+ var partViewModel = parts.FirstOrDefault(m => m.ContentItemId == contentItem.ContentItemId);
- dashboardPart.Position = partViewModel?.Position ?? 0;
- dashboardPart.Width = partViewModel?.Width ?? 1;
- dashboardPart.Height = partViewModel?.Height ?? 1;
+ dashboardPart.Position = partViewModel?.Position ?? 0;
+ dashboardPart.Width = partViewModel?.Width ?? 1;
+ dashboardPart.Height = partViewModel?.Height ?? 1;
- contentItem.Apply(dashboardPart);
+ contentItem.Apply(dashboardPart);
- await _session.SaveAsync(contentItem);
+ await _session.SaveAsync(contentItem);
- if (contentItem.IsPublished() == false)
+ if (contentItem.IsPublished() == false)
+ {
+ var publishedVersion = publishedItems.FirstOrDefault(p => p.ContentItemId == contentItem.ContentItemId);
+ var publishedMetaData = publishedVersion?.As();
+ if (publishedMetaData != null)
{
- var publishedVersion = publishedItems.FirstOrDefault(p => p.ContentItemId == contentItem.ContentItemId);
- var publishedMetaData = publishedVersion?.As();
- if (publishedMetaData != null)
- {
- publishedMetaData.Position = partViewModel.Position;
- publishedMetaData.Width = partViewModel.Width;
- publishedMetaData.Height = partViewModel.Height;
- publishedVersion.Apply(publishedMetaData);
- await _session.SaveAsync(publishedVersion);
- }
+ publishedMetaData.Position = partViewModel.Position;
+ publishedMetaData.Width = partViewModel.Width;
+ publishedMetaData.Height = partViewModel.Height;
+ publishedVersion.Apply(publishedMetaData);
+ await _session.SaveAsync(publishedVersion);
}
}
+ }
- if (Request.Headers != null && Request.Headers.XRequestedWith == "XMLHttpRequest")
- {
- return Ok();
- }
-
- return RedirectToAction(nameof(Manage));
+ if (Request.Headers != null && Request.Headers.XRequestedWith == "XMLHttpRequest")
+ {
+ return Ok();
}
- private async Task> GetDashboardWidgetsAsync()
- => (await _contentDefinitionManager.ListTypeDefinitionsAsync())
- .Where(t => t.StereotypeEquals("DashboardWidget"))
- .ToDictionary(ctd => ctd.Name, ctd => ctd);
+ return RedirectToAction(nameof(Manage));
}
+
+ private async Task> GetDashboardWidgetsAsync()
+ => (await _contentDefinitionManager.ListTypeDefinitionsAsync())
+ .Where(t => t.StereotypeEquals("DashboardWidget"))
+ .ToDictionary(ctd => ctd.Name, ctd => ctd);
}
diff --git a/src/OrchardCore.Modules/OrchardCore.AdminDashboard/DashboardFeature.cs b/src/OrchardCore.Modules/OrchardCore.AdminDashboard/DashboardFeature.cs
index 7a2c03bec42..02dc15fc564 100644
--- a/src/OrchardCore.Modules/OrchardCore.AdminDashboard/DashboardFeature.cs
+++ b/src/OrchardCore.Modules/OrchardCore.AdminDashboard/DashboardFeature.cs
@@ -1,7 +1,6 @@
-namespace OrchardCore.AdminDashboard
+namespace OrchardCore.AdminDashboard;
+
+public class DashboardFeature
{
- public class DashboardFeature
- {
- public bool IsManageRequest { get; set; }
- }
+ public bool IsManageRequest { get; set; }
}
diff --git a/src/OrchardCore.Modules/OrchardCore.AdminDashboard/Drivers/DashboardContentDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.AdminDashboard/Drivers/DashboardContentDisplayDriver.cs
index 214069b6a7e..fc4b36422d6 100644
--- a/src/OrchardCore.Modules/OrchardCore.AdminDashboard/Drivers/DashboardContentDisplayDriver.cs
+++ b/src/OrchardCore.Modules/OrchardCore.AdminDashboard/Drivers/DashboardContentDisplayDriver.cs
@@ -10,99 +10,98 @@
using OrchardCore.DisplayManagement.Views;
-namespace OrchardCore.AdminDashboard.Drivers
+namespace OrchardCore.AdminDashboard.Drivers;
+
+public sealed class DashboardContentDisplayDriver : ContentDisplayDriver
{
- public sealed class DashboardContentDisplayDriver : ContentDisplayDriver
+ private readonly IHttpContextAccessor _httpContextAccessor;
+ private readonly IAuthorizationService _authorizationService;
+ private readonly IContentManager _contentManager;
+
+ public DashboardContentDisplayDriver(IHttpContextAccessor httpContextAccessor,
+ IAuthorizationService authorizationService,
+ IContentManager contentManager)
{
- private readonly IHttpContextAccessor _httpContextAccessor;
- private readonly IAuthorizationService _authorizationService;
- private readonly IContentManager _contentManager;
+ _httpContextAccessor = httpContextAccessor;
+ _authorizationService = authorizationService;
+ _contentManager = contentManager;
+ }
- public DashboardContentDisplayDriver(IHttpContextAccessor httpContextAccessor,
- IAuthorizationService authorizationService,
- IContentManager contentManager)
- {
- _httpContextAccessor = httpContextAccessor;
- _authorizationService = authorizationService;
- _contentManager = contentManager;
- }
+ public override async Task DisplayAsync(ContentItem model, BuildDisplayContext context)
+ {
+ var httpContext = _httpContextAccessor.HttpContext;
+ var dashboardFeature = httpContext.Features.Get();
- public override async Task DisplayAsync(ContentItem model, BuildDisplayContext context)
+ // Return if it's not Manage dashboard request
+ if (dashboardFeature == null || !dashboardFeature.IsManageRequest)
{
- var httpContext = _httpContextAccessor.HttpContext;
- var dashboardFeature = httpContext.Features.Get();
+ return null;
+ }
- // Return if it's not Manage dashboard request
- if (dashboardFeature == null || !dashboardFeature.IsManageRequest)
- {
- return null;
- }
+ var results = new List();
+ var hasPublished = await _contentManager.HasPublishedVersionAsync(model);
+ var hasDraft = model.HasDraft();
+ var hasEditPermission = await _authorizationService.AuthorizeAsync(httpContext.User, CommonPermissions.EditContent, model);
+ var hasDeletePermission = await _authorizationService.AuthorizeAsync(httpContext.User, CommonPermissions.DeleteContent, model);
+ var hasPublishPermission = await _authorizationService.AuthorizeAsync(httpContext.User, CommonPermissions.PublishContent, model);
- var results = new List();
- var hasPublished = await _contentManager.HasPublishedVersionAsync(model);
- var hasDraft = model.HasDraft();
- var hasEditPermission = await _authorizationService.AuthorizeAsync(httpContext.User, CommonPermissions.EditContent, model);
- var hasDeletePermission = await _authorizationService.AuthorizeAsync(httpContext.User, CommonPermissions.DeleteContent, model);
- var hasPublishPermission = await _authorizationService.AuthorizeAsync(httpContext.User, CommonPermissions.PublishContent, model);
+ var dragHandle = Initialize("Dashboard_DragHandle", m =>
+ {
+ m.ContentItem = model;
+ }).Location("Leading:before");
+ results.Add(dragHandle);
- var dragHandle = Initialize("Dashboard_DragHandle", m =>
+ if (hasEditPermission)
+ {
+ var editButton = Initialize("Dashboard_EditButton", m =>
{
m.ContentItem = model;
- }).Location("Leading:before");
- results.Add(dragHandle);
-
- if (hasEditPermission)
- {
- var editButton = Initialize("Dashboard_EditButton", m =>
- {
- m.ContentItem = model;
- }).Location("ActionsMenu:after");
- results.Add(editButton);
- }
-
- if (hasDeletePermission)
- {
- var deleteButton = Initialize("Dashboard_DeleteButton", m =>
- {
- m.ContentItem = model;
- }).Location("ActionsMenu:after");
- results.Add(deleteButton);
- }
+ }).Location("ActionsMenu:after");
+ results.Add(editButton);
+ }
- if (hasPublished && hasPublishPermission)
+ if (hasDeletePermission)
+ {
+ var deleteButton = Initialize("Dashboard_DeleteButton", m =>
{
- var unpublishButton = Initialize("Dashboard_UnpublishButton", m =>
- {
- m.ContentItem = model;
- }).Location("ActionsMenu:after");
- results.Add(unpublishButton);
- }
+ m.ContentItem = model;
+ }).Location("ActionsMenu:after");
+ results.Add(deleteButton);
+ }
- if (hasDraft && hasPublishPermission)
+ if (hasPublished && hasPublishPermission)
+ {
+ var unpublishButton = Initialize("Dashboard_UnpublishButton", m =>
{
- var publishButton = Initialize("Dashboard_PublishButton", m =>
- {
- m.ContentItem = model;
- }).Location("ActionsMenu:after");
- results.Add(publishButton);
- }
+ m.ContentItem = model;
+ }).Location("ActionsMenu:after");
+ results.Add(unpublishButton);
+ }
- if (hasDraft && hasEditPermission)
+ if (hasDraft && hasPublishPermission)
+ {
+ var publishButton = Initialize("Dashboard_PublishButton", m =>
{
- var discardDraftButton = Initialize("Dashboard_DiscardDraftButton", m =>
- {
- m.ContentItem = model;
- }).Location("ActionsMenu:after");
- results.Add(discardDraftButton);
- }
+ m.ContentItem = model;
+ }).Location("ActionsMenu:after");
+ results.Add(publishButton);
+ }
- var shapeTag = Initialize("DashboardWidget_DetailAdmin__ContentsTags", m =>
+ if (hasDraft && hasEditPermission)
+ {
+ var discardDraftButton = Initialize("Dashboard_DiscardDraftButton", m =>
{
m.ContentItem = model;
- }).Location("DetailAdmin", "Tags:10");
- results.Add(shapeTag);
-
- return Combine(results.ToArray());
+ }).Location("ActionsMenu:after");
+ results.Add(discardDraftButton);
}
+
+ var shapeTag = Initialize("DashboardWidget_DetailAdmin__ContentsTags", m =>
+ {
+ m.ContentItem = model;
+ }).Location("DetailAdmin", "Tags:10");
+ results.Add(shapeTag);
+
+ return Combine(results.ToArray());
}
}
diff --git a/src/OrchardCore.Modules/OrchardCore.AdminDashboard/Drivers/DashboardPartDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.AdminDashboard/Drivers/DashboardPartDisplayDriver.cs
index 2d502ed7903..f105cb79fbd 100644
--- a/src/OrchardCore.Modules/OrchardCore.AdminDashboard/Drivers/DashboardPartDisplayDriver.cs
+++ b/src/OrchardCore.Modules/OrchardCore.AdminDashboard/Drivers/DashboardPartDisplayDriver.cs
@@ -6,37 +6,36 @@
using OrchardCore.DisplayManagement.ModelBinding;
using OrchardCore.DisplayManagement.Views;
-namespace OrchardCore.AdminDashboard.Drivers
+namespace OrchardCore.AdminDashboard.Drivers;
+
+public sealed class DashboardPartDisplayDriver : ContentPartDisplayDriver
{
- public sealed class DashboardPartDisplayDriver : ContentPartDisplayDriver
+ public override Task DisplayAsync(DashboardPart part, BuildPartDisplayContext context)
{
- public override Task DisplayAsync(DashboardPart part, BuildPartDisplayContext context)
- {
- return Task.FromResult(null);
- }
+ return Task.FromResult(null);
+ }
- public override IDisplayResult Edit(DashboardPart dashboardPart, BuildPartEditorContext context)
- {
- return Initialize(GetEditorShapeType(context), m => BuildViewModel(m, dashboardPart));
- }
+ public override IDisplayResult Edit(DashboardPart dashboardPart, BuildPartEditorContext context)
+ {
+ return Initialize(GetEditorShapeType(context), m => BuildViewModel(m, dashboardPart));
+ }
- public override async Task UpdateAsync(DashboardPart model, UpdatePartEditorContext context)
- {
- await context.Updater.TryUpdateModelAsync(model, Prefix,
- t => t.Position,
- t => t.Width,
- t => t.Height);
+ public override async Task UpdateAsync(DashboardPart model, UpdatePartEditorContext context)
+ {
+ await context.Updater.TryUpdateModelAsync(model, Prefix,
+ t => t.Position,
+ t => t.Width,
+ t => t.Height);
- return Edit(model, context);
- }
+ return Edit(model, context);
+ }
- private static void BuildViewModel(DashboardPartViewModel model, DashboardPart part)
- {
- model.Position = part.Position;
- model.Width = part.Width;
- model.Height = part.Height;
- model.DashboardPart = part;
- model.ContentItem = part.ContentItem;
- }
+ private static void BuildViewModel(DashboardPartViewModel model, DashboardPart part)
+ {
+ model.Position = part.Position;
+ model.Width = part.Width;
+ model.Height = part.Height;
+ model.DashboardPart = part;
+ model.ContentItem = part.ContentItem;
}
}
diff --git a/src/OrchardCore.Modules/OrchardCore.AdminDashboard/Indexes/DashboardPartIndex.cs b/src/OrchardCore.Modules/OrchardCore.AdminDashboard/Indexes/DashboardPartIndex.cs
index 4e70965687d..40927b0bc46 100644
--- a/src/OrchardCore.Modules/OrchardCore.AdminDashboard/Indexes/DashboardPartIndex.cs
+++ b/src/OrchardCore.Modules/OrchardCore.AdminDashboard/Indexes/DashboardPartIndex.cs
@@ -2,38 +2,37 @@
using OrchardCore.ContentManagement;
using YesSql.Indexes;
-namespace OrchardCore.AdminDashboard.Indexes
+namespace OrchardCore.AdminDashboard.Indexes;
+
+public class DashboardPartIndex : MapIndex
{
- public class DashboardPartIndex : MapIndex
- {
- public double Position { get; set; }
- }
+ public double Position { get; set; }
+}
- public class DashboardPartIndexProvider : IndexProvider
+public class DashboardPartIndexProvider : IndexProvider
+{
+ public override void Describe(DescribeContext context)
{
- public override void Describe(DescribeContext context)
- {
- context.For()
- .Map(contentItem =>
- {
- var dashboardPart = contentItem.As();
+ context.For()
+ .Map(contentItem =>
+ {
+ var dashboardPart = contentItem.As();
- // Store only published and latest versions
- if (!contentItem.Published && !contentItem.Latest)
- {
- return null;
- }
+ // Store only published and latest versions
+ if (!contentItem.Published && !contentItem.Latest)
+ {
+ return null;
+ }
- if (dashboardPart != null)
+ if (dashboardPart != null)
+ {
+ return new DashboardPartIndex
{
- return new DashboardPartIndex
- {
- Position = dashboardPart.Position,
- };
- }
+ Position = dashboardPart.Position,
+ };
+ }
- return null;
- });
- }
+ return null;
+ });
}
}
diff --git a/src/OrchardCore.Modules/OrchardCore.AdminDashboard/Migrations.cs b/src/OrchardCore.Modules/OrchardCore.AdminDashboard/Migrations.cs
index e31897c300a..a7664223ea8 100644
--- a/src/OrchardCore.Modules/OrchardCore.AdminDashboard/Migrations.cs
+++ b/src/OrchardCore.Modules/OrchardCore.AdminDashboard/Migrations.cs
@@ -7,61 +7,60 @@
using OrchardCore.Recipes.Services;
using YesSql.Sql;
-namespace OrchardCore.AdminDashboard
+namespace OrchardCore.AdminDashboard;
+
+public sealed class Migrations : DataMigration
{
- public sealed class Migrations : DataMigration
+ private readonly IContentDefinitionManager _contentDefinitionManager;
+ private readonly IRecipeMigrator _recipeMigrator;
+
+ public Migrations(
+ IContentDefinitionManager contentDefinitionManager,
+ IRecipeMigrator recipeMigrator)
{
- private readonly IContentDefinitionManager _contentDefinitionManager;
- private readonly IRecipeMigrator _recipeMigrator;
+ _contentDefinitionManager = contentDefinitionManager;
+ _recipeMigrator = recipeMigrator;
+ }
- public Migrations(
- IContentDefinitionManager contentDefinitionManager,
- IRecipeMigrator recipeMigrator)
- {
- _contentDefinitionManager = contentDefinitionManager;
- _recipeMigrator = recipeMigrator;
- }
+ public async Task CreateAsync()
+ {
+ await SchemaBuilder.CreateMapIndexTableAsync(table => table
+ .Column("Position")
+ );
- public async Task CreateAsync()
- {
- await SchemaBuilder.CreateMapIndexTableAsync(table => table
- .Column("Position")
- );
+ await SchemaBuilder.AlterIndexTableAsync(table => table
+ .CreateIndex("IDX_DashboardPart_DocumentId",
+ "DocumentId",
+ "Position")
+ );
- await SchemaBuilder.AlterIndexTableAsync(table => table
- .CreateIndex("IDX_DashboardPart_DocumentId",
- "DocumentId",
- "Position")
+ await _contentDefinitionManager.AlterPartDefinitionAsync("DashboardPart", builder => builder
+ .Attachable()
+ .WithDescription("Provides a way to add widgets to a dashboard.")
);
- await _contentDefinitionManager.AlterPartDefinitionAsync("DashboardPart", builder => builder
- .Attachable()
- .WithDescription("Provides a way to add widgets to a dashboard.")
- );
-
- await _recipeMigrator.ExecuteAsync($"dashboard-widgets{RecipesConstants.RecipeExtension}", this);
+ await _recipeMigrator.ExecuteAsync($"dashboard-widgets{RecipesConstants.RecipeExtension}", this);
- // Shortcut other migration steps on new content definition schemas.
- return 3;
- }
+ // Shortcut other migration steps on new content definition schemas.
+ return 3;
+ }
- public async Task UpdateFrom1Async()
- {
- await _recipeMigrator.ExecuteAsync($"dashboard-widgets{RecipesConstants.RecipeExtension}", this);
+ public async Task UpdateFrom1Async()
+ {
+ await _recipeMigrator.ExecuteAsync($"dashboard-widgets{RecipesConstants.RecipeExtension}", this);
- return 2;
- }
+ return 2;
+ }
- // This code can be removed in a later version.
- public async Task UpdateFrom2Async()
- {
- await SchemaBuilder.AlterIndexTableAsync(table => table
- .CreateIndex("IDX_DashboardPart_DocumentId",
- "DocumentId",
- "Position")
- );
+ // This code can be removed in a later version.
+ public async Task UpdateFrom2Async()
+ {
+ await SchemaBuilder.AlterIndexTableAsync(table => table
+ .CreateIndex("IDX_DashboardPart_DocumentId",
+ "DocumentId",
+ "Position")
+ );
- return 3;
- }
+ return 3;
}
}
diff --git a/src/OrchardCore.Modules/OrchardCore.AdminDashboard/Models/DashboardPart.cs b/src/OrchardCore.Modules/OrchardCore.AdminDashboard/Models/DashboardPart.cs
index 8403922180d..721a5115692 100644
--- a/src/OrchardCore.Modules/OrchardCore.AdminDashboard/Models/DashboardPart.cs
+++ b/src/OrchardCore.Modules/OrchardCore.AdminDashboard/Models/DashboardPart.cs
@@ -1,11 +1,10 @@
using OrchardCore.ContentManagement;
-namespace OrchardCore.AdminDashboard.Models
+namespace OrchardCore.AdminDashboard.Models;
+
+public class DashboardPart : ContentPart
{
- public class DashboardPart : ContentPart
- {
- public double Position { get; set; }
- public double Width { get; set; } = 1.0;
- public double Height { get; set; } = 1.0;
- }
+ public double Position { get; set; }
+ public double Width { get; set; } = 1.0;
+ public double Height { get; set; } = 1.0;
}
diff --git a/src/OrchardCore.Modules/OrchardCore.AdminDashboard/Services/AdminDashboardService.cs b/src/OrchardCore.Modules/OrchardCore.AdminDashboard/Services/AdminDashboardService.cs
index f9d03c02c90..188c55d608a 100644
--- a/src/OrchardCore.Modules/OrchardCore.AdminDashboard/Services/AdminDashboardService.cs
+++ b/src/OrchardCore.Modules/OrchardCore.AdminDashboard/Services/AdminDashboardService.cs
@@ -7,26 +7,25 @@
using OrchardCore.ContentManagement.Records;
using YesSql;
-namespace OrchardCore.AdminDashboard.Services
+namespace OrchardCore.AdminDashboard.Services;
+
+public class AdminDashboardService : IAdminDashboardService
{
- public class AdminDashboardService : IAdminDashboardService
- {
- private readonly ISession _session;
+ private readonly ISession _session;
- public AdminDashboardService(ISession session)
- {
- _session = session;
- }
+ public AdminDashboardService(ISession session)
+ {
+ _session = session;
+ }
- public async Task> GetWidgetsAsync(Expression> predicate)
- {
- var widgets = await _session
- .Query()
- .OrderBy(w => w.Position)
- .With(predicate)
- .ListAsync();
+ public async Task> GetWidgetsAsync(Expression> predicate)
+ {
+ var widgets = await _session
+ .Query()
+ .OrderBy(w => w.Position)
+ .With(predicate)
+ .ListAsync();
- return widgets;
- }
+ return widgets;
}
}
diff --git a/src/OrchardCore.Modules/OrchardCore.AdminDashboard/Services/IAdminDashboardService.cs b/src/OrchardCore.Modules/OrchardCore.AdminDashboard/Services/IAdminDashboardService.cs
index bfac84c58e6..35ec639a5d9 100644
--- a/src/OrchardCore.Modules/OrchardCore.AdminDashboard/Services/IAdminDashboardService.cs
+++ b/src/OrchardCore.Modules/OrchardCore.AdminDashboard/Services/IAdminDashboardService.cs
@@ -5,13 +5,12 @@
using OrchardCore.ContentManagement;
using OrchardCore.ContentManagement.Records;
-namespace OrchardCore.AdminDashboard.Services
+namespace OrchardCore.AdminDashboard.Services;
+
+///
+/// Provides services to manage the Admin Dashboards.
+///
+public interface IAdminDashboardService
{
- ///
- /// Provides services to manage the Admin Dashboards.
- ///
- public interface IAdminDashboardService
- {
- Task> GetWidgetsAsync(Expression> predicate);
- }
+ Task> GetWidgetsAsync(Expression> predicate);
}
diff --git a/src/OrchardCore.Modules/OrchardCore.AdminDashboard/Startup.cs b/src/OrchardCore.Modules/OrchardCore.AdminDashboard/Startup.cs
index 1881c834fb2..8073e6c7844 100644
--- a/src/OrchardCore.Modules/OrchardCore.AdminDashboard/Startup.cs
+++ b/src/OrchardCore.Modules/OrchardCore.AdminDashboard/Startup.cs
@@ -17,45 +17,44 @@
using OrchardCore.Mvc.Core.Utilities;
using OrchardCore.Security.Permissions;
-namespace OrchardCore.AdminDashboard
-{
- public sealed class Startup : StartupBase
- {
- public override int ConfigureOrder => -10;
+namespace OrchardCore.AdminDashboard;
- private readonly AdminOptions _adminOptions;
+public sealed class Startup : StartupBase
+{
+ public override int ConfigureOrder => -10;
- public Startup(IOptions adminOptions)
- {
- _adminOptions = adminOptions.Value;
- }
+ private readonly AdminOptions _adminOptions;
- public override void ConfigureServices(IServiceCollection services)
- {
- services.AddScoped();
+ public Startup(IOptions adminOptions)
+ {
+ _adminOptions = adminOptions.Value;
+ }
- services.AddScoped();
- services.AddIndexProvider();
+ public override void ConfigureServices(IServiceCollection services)
+ {
+ services.AddScoped();
- services.AddContentPart()
- .UseDisplayDriver();
+ services.AddScoped();
+ services.AddIndexProvider();
- services.AddScoped();
+ services.AddContentPart()
+ .UseDisplayDriver();
- services.AddDataMigration();
- }
+ services.AddScoped();
- public override void Configure(IApplicationBuilder builder, IEndpointRouteBuilder routes, IServiceProvider serviceProvider)
- {
- // Dashboard
- var dashboardControllerName = typeof(DashboardController).ControllerName();
+ services.AddDataMigration();
+ }
- routes.MapAreaControllerRoute(
- name: "AdminDashboard",
- areaName: "OrchardCore.AdminDashboard",
- pattern: _adminOptions.AdminUrlPrefix,
- defaults: new { controller = dashboardControllerName, action = nameof(DashboardController.Index) }
- );
- }
+ public override void Configure(IApplicationBuilder builder, IEndpointRouteBuilder routes, IServiceProvider serviceProvider)
+ {
+ // Dashboard
+ var dashboardControllerName = typeof(DashboardController).ControllerName();
+
+ routes.MapAreaControllerRoute(
+ name: "AdminDashboard",
+ areaName: "OrchardCore.AdminDashboard",
+ pattern: _adminOptions.AdminUrlPrefix,
+ defaults: new { controller = dashboardControllerName, action = nameof(DashboardController.Index) }
+ );
}
}
diff --git a/src/OrchardCore.Modules/OrchardCore.AdminDashboard/ViewModels/AdminDashboardViewModel.cs b/src/OrchardCore.Modules/OrchardCore.AdminDashboard/ViewModels/AdminDashboardViewModel.cs
index 7805a8ec978..9be1b519701 100644
--- a/src/OrchardCore.Modules/OrchardCore.AdminDashboard/ViewModels/AdminDashboardViewModel.cs
+++ b/src/OrchardCore.Modules/OrchardCore.AdminDashboard/ViewModels/AdminDashboardViewModel.cs
@@ -2,17 +2,16 @@
using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.AspNetCore.Mvc.Rendering;
-namespace OrchardCore.AdminDashboard.ViewModels
+namespace OrchardCore.AdminDashboard.ViewModels;
+
+public class AdminDashboardViewModel
{
- public class AdminDashboardViewModel
- {
- [BindNever]
- public bool CanManageDashboard { get; set; }
+ [BindNever]
+ public bool CanManageDashboard { get; set; }
- [BindNever]
- public DashboardWrapper[] Dashboards { get; set; }
+ [BindNever]
+ public DashboardWrapper[] Dashboards { get; set; }
- [BindNever]
- public List Creatable { get; set; }
- }
+ [BindNever]
+ public List Creatable { get; set; }
}
diff --git a/src/OrchardCore.Modules/OrchardCore.AdminDashboard/ViewModels/DashboardPartViewModel.cs b/src/OrchardCore.Modules/OrchardCore.AdminDashboard/ViewModels/DashboardPartViewModel.cs
index 6a11b04c0ff..095394cb00d 100644
--- a/src/OrchardCore.Modules/OrchardCore.AdminDashboard/ViewModels/DashboardPartViewModel.cs
+++ b/src/OrchardCore.Modules/OrchardCore.AdminDashboard/ViewModels/DashboardPartViewModel.cs
@@ -2,19 +2,18 @@
using OrchardCore.AdminDashboard.Models;
using OrchardCore.ContentManagement;
-namespace OrchardCore.AdminDashboard.ViewModels
+namespace OrchardCore.AdminDashboard.ViewModels;
+
+public class DashboardPartViewModel
{
- public class DashboardPartViewModel
- {
- public string ContentItemId { get; set; }
- public double Position { get; set; }
- public double Width { get; set; }
- public double Height { get; set; }
+ public string ContentItemId { get; set; }
+ public double Position { get; set; }
+ public double Width { get; set; }
+ public double Height { get; set; }
- [BindNever]
- public ContentItem ContentItem { get; set; }
+ [BindNever]
+ public ContentItem ContentItem { get; set; }
- [BindNever]
- public DashboardPart DashboardPart { get; set; }
- }
+ [BindNever]
+ public DashboardPart DashboardPart { get; set; }
}
diff --git a/src/OrchardCore.Modules/OrchardCore.AdminDashboard/ViewModels/DashboardWrapper.cs b/src/OrchardCore.Modules/OrchardCore.AdminDashboard/ViewModels/DashboardWrapper.cs
index cf293deeb7b..f08533c0c64 100644
--- a/src/OrchardCore.Modules/OrchardCore.AdminDashboard/ViewModels/DashboardWrapper.cs
+++ b/src/OrchardCore.Modules/OrchardCore.AdminDashboard/ViewModels/DashboardWrapper.cs
@@ -2,16 +2,14 @@
using OrchardCore.DisplayManagement;
using OrchardCore.DisplayManagement.Views;
-namespace OrchardCore.AdminDashboard.ViewModels
+namespace OrchardCore.AdminDashboard.ViewModels;
+
+public class DashboardWrapper : ShapeViewModel
{
- public class DashboardWrapper : ShapeViewModel
+ public DashboardWrapper() : base("Dashboard_Wrapper")
{
- public DashboardWrapper() : base("Dashboard_Wrapper")
- {
- }
-
- public ContentItem Dashboard { get; set; }
- public IShape Content { get; set; }
}
+ public ContentItem Dashboard { get; set; }
+ public IShape Content { get; set; }
}
diff --git a/src/OrchardCore.Modules/OrchardCore.AdminMenu/AdminMenu.cs b/src/OrchardCore.Modules/OrchardCore.AdminMenu/AdminMenu.cs
index 01196918b0d..76ad7d16913 100644
--- a/src/OrchardCore.Modules/OrchardCore.AdminMenu/AdminMenu.cs
+++ b/src/OrchardCore.Modules/OrchardCore.AdminMenu/AdminMenu.cs
@@ -3,40 +3,39 @@
using OrchardCore.AdminMenu.Services;
using OrchardCore.Navigation;
-namespace OrchardCore.AdminMenu
+namespace OrchardCore.AdminMenu;
+
+public sealed class AdminMenu : INavigationProvider
{
- public sealed class AdminMenu : INavigationProvider
- {
- private readonly AdminMenuNavigationProvidersCoordinator _adminMenuNavigationProvider;
+ private readonly AdminMenuNavigationProvidersCoordinator _adminMenuNavigationProvider;
- internal readonly IStringLocalizer S;
+ internal readonly IStringLocalizer S;
- public AdminMenu(AdminMenuNavigationProvidersCoordinator adminMenuNavigationProvider,
- IStringLocalizer localizer)
- {
- _adminMenuNavigationProvider = adminMenuNavigationProvider;
- S = localizer;
- }
+ public AdminMenu(AdminMenuNavigationProvidersCoordinator adminMenuNavigationProvider,
+ IStringLocalizer localizer)
+ {
+ _adminMenuNavigationProvider = adminMenuNavigationProvider;
+ S = localizer;
+ }
- public async Task BuildNavigationAsync(string name, NavigationBuilder builder)
+ public async Task BuildNavigationAsync(string name, NavigationBuilder builder)
+ {
+ if (!NavigationHelper.IsAdminMenu(name))
{
- if (!NavigationHelper.IsAdminMenu(name))
- {
- return;
- }
+ return;
+ }
- // Configuration and settings menus for the AdminMenu module
- builder
- .Add(S["Configuration"], configuration => configuration
- .Add(S["Admin Menus"], S["Admin Menus"].PrefixPosition(), adminMenu => adminMenu
- .Permission(Permissions.ManageAdminMenu)
- .Action("List", "Menu", "OrchardCore.AdminMenu")
- .LocalNav()
- )
- );
+ // Configuration and settings menus for the AdminMenu module
+ builder
+ .Add(S["Configuration"], configuration => configuration
+ .Add(S["Admin Menus"], S["Admin Menus"].PrefixPosition(), adminMenu => adminMenu
+ .Permission(Permissions.ManageAdminMenu)
+ .Action("List", "Menu", "OrchardCore.AdminMenu")
+ .LocalNav()
+ )
+ );
- // This is the entry point for the adminMenu: dynamically generated custom admin menus
- await _adminMenuNavigationProvider.BuildNavigationAsync(NavigationConstants.AdminMenuId, builder);
- }
+ // This is the entry point for the adminMenu: dynamically generated custom admin menus
+ await _adminMenuNavigationProvider.BuildNavigationAsync(NavigationConstants.AdminMenuId, builder);
}
}
diff --git a/src/OrchardCore.Modules/OrchardCore.AdminMenu/AdminNodes/LinkAdminNode.cs b/src/OrchardCore.Modules/OrchardCore.AdminMenu/AdminNodes/LinkAdminNode.cs
index 6c522d97827..be4788e73bd 100644
--- a/src/OrchardCore.Modules/OrchardCore.AdminMenu/AdminNodes/LinkAdminNode.cs
+++ b/src/OrchardCore.Modules/OrchardCore.AdminMenu/AdminNodes/LinkAdminNode.cs
@@ -1,21 +1,20 @@
using System.ComponentModel.DataAnnotations;
using OrchardCore.AdminMenu.Models;
-namespace OrchardCore.AdminMenu.AdminNodes
+namespace OrchardCore.AdminMenu.AdminNodes;
+
+public class LinkAdminNode : AdminNode
{
- public class LinkAdminNode : AdminNode
- {
- [Required]
- public string LinkText { get; set; }
+ [Required]
+ public string LinkText { get; set; }
- [Required]
- public string LinkUrl { get; set; }
+ [Required]
+ public string LinkUrl { get; set; }
- public string IconClass { get; set; }
+ public string IconClass { get; set; }
- ///
- /// The names of the permissions required to view this admin menu node.
- ///
- public string[] PermissionNames { get; set; } = [];
- }
+ ///
+ /// The names of the permissions required to view this admin menu node.
+ ///
+ public string[] PermissionNames { get; set; } = [];
}
diff --git a/src/OrchardCore.Modules/OrchardCore.AdminMenu/AdminNodes/LinkAdminNodeDriver.cs b/src/OrchardCore.Modules/OrchardCore.AdminMenu/AdminNodes/LinkAdminNodeDriver.cs
index b0068519ac1..5690f12d5b6 100644
--- a/src/OrchardCore.Modules/OrchardCore.AdminMenu/AdminNodes/LinkAdminNodeDriver.cs
+++ b/src/OrchardCore.Modules/OrchardCore.AdminMenu/AdminNodes/LinkAdminNodeDriver.cs
@@ -6,78 +6,77 @@
using OrchardCore.DisplayManagement.Views;
using OrchardCore.Navigation;
-namespace OrchardCore.AdminMenu.AdminNodes
+namespace OrchardCore.AdminMenu.AdminNodes;
+
+public sealed class LinkAdminNodeDriver : DisplayDriver