From 9efcb2289a4c26b2e68a6eb76b64f94564091bff Mon Sep 17 00:00:00 2001 From: Hisham Bin Ateya Date: Tue, 6 Jan 2026 11:54:24 +0300 Subject: [PATCH] Bump OCC.ContentPreview to 1.5.0 --- .../Constants.cs | 11 +- .../Controllers/PreviewController.cs | 11 +- .../PagePreviewOrchardCoreExtensions.cs | 38 +++--- .../Manifest.cs | 2 +- .../OrchardCoreContrib.ContentPreview.csproj | 5 +- .../PagePreviewMiddleware.cs | 116 ++++++++---------- .../README.md | 3 +- .../RequestDestination.cs | 18 --- .../ResourceManagementOptionsConfiguration.cs | 47 ++++--- .../Startup.cs | 48 ++++---- .../Views/Preview/Index.cshtml | 11 +- .../_PagePreviewBar.cshtml | 6 +- 12 files changed, 143 insertions(+), 173 deletions(-) delete mode 100644 src/OrchardCoreContrib.ContentPreview/RequestDestination.cs rename src/OrchardCoreContrib.ContentPreview/Views/{Preview => Shared}/_PagePreviewBar.cshtml (88%) diff --git a/src/OrchardCoreContrib.ContentPreview/Constants.cs b/src/OrchardCoreContrib.ContentPreview/Constants.cs index a7391537..40fe6d69 100644 --- a/src/OrchardCoreContrib.ContentPreview/Constants.cs +++ b/src/OrchardCoreContrib.ContentPreview/Constants.cs @@ -1,9 +1,8 @@ -namespace OrchardCoreContrib.ContentPreview +namespace OrchardCoreContrib.ContentPreview; + +public class Constants { - internal class Constants - { - public const string PreviewSlug = "preview"; + public const string PreviewSlug = "preview"; - public const string PagePreviewBarFeatureId = "OrchardCoreContrib.ContentPreview.PagePreviewBar"; - } + public const string PagePreviewBarFeatureId = "OrchardCoreContrib.ContentPreview.PagePreviewBar"; } diff --git a/src/OrchardCoreContrib.ContentPreview/Controllers/PreviewController.cs b/src/OrchardCoreContrib.ContentPreview/Controllers/PreviewController.cs index 5f68a645..5ed6b4bd 100644 --- a/src/OrchardCoreContrib.ContentPreview/Controllers/PreviewController.cs +++ b/src/OrchardCoreContrib.ContentPreview/Controllers/PreviewController.cs @@ -1,11 +1,10 @@ using Microsoft.AspNetCore.Mvc; using OrchardCore.Modules; -namespace OrchardCoreContrib.ContentPreview.Controllers +namespace OrchardCoreContrib.ContentPreview.Controllers; + +[Feature("OrchardCoreContrib.ContentPreview.PagePreviewBar")] +public class PreviewController : Controller { - [Feature("OrchardCoreContrib.ContentPreview.PagePreviewBar")] - public class PreviewController : Controller - { - public IActionResult Index() => View(); - } + public IActionResult Index() => View(); } diff --git a/src/OrchardCoreContrib.ContentPreview/Extensions/PagePreviewOrchardCoreExtensions.cs b/src/OrchardCoreContrib.ContentPreview/Extensions/PagePreviewOrchardCoreExtensions.cs index f4e6c2ee..cf04946d 100644 --- a/src/OrchardCoreContrib.ContentPreview/Extensions/PagePreviewOrchardCoreExtensions.cs +++ b/src/OrchardCoreContrib.ContentPreview/Extensions/PagePreviewOrchardCoreExtensions.cs @@ -4,33 +4,31 @@ using OrchardCore.Environment.Shell; using OrchardCore.Users; using OrchardCoreContrib.ContentPreview; -using System; +using OrchardCoreContrib.Infrastructure; -namespace Microsoft.AspNetCore.Builder +namespace Microsoft.AspNetCore.Builder; + +/// +/// Provides an extension methods for to enable page preview. +/// +public static class PagePreviewOrchardCoreExtensions { /// - /// Provides an extension methods for to enable page preview. + /// Uses the page preview middleware. /// - public static class PagePreviewOrchardCoreExtensions + /// The . + public static IApplicationBuilder UsePagePreview(this IApplicationBuilder app) { - /// - /// Uses the page preview middleware. - /// - /// The . - public static IApplicationBuilder UsePagePreview(this IApplicationBuilder app) - { - if (app is null) - { - throw new ArgumentNullException(nameof(app)); - } + Guard.ArgumentNotNull(app, nameof(app)); - var adminOptions = app.ApplicationServices.GetService>(); - var userOptions = app.ApplicationServices.GetService>(); - var shellFeaturesManager = app.ApplicationServices.CreateScope().ServiceProvider.GetService(); + var adminOptions = app.ApplicationServices.GetService>(); + var userOptions = app.ApplicationServices.GetService>(); + var shellFeaturesManager = app.ApplicationServices.CreateScope() + .ServiceProvider + .GetService(); - app.UseMiddleware(adminOptions, userOptions, shellFeaturesManager); + app.UseMiddleware(adminOptions, userOptions, shellFeaturesManager); - return app; - } + return app; } } diff --git a/src/OrchardCoreContrib.ContentPreview/Manifest.cs b/src/OrchardCoreContrib.ContentPreview/Manifest.cs index 6e912fff..3f88adbf 100644 --- a/src/OrchardCoreContrib.ContentPreview/Manifest.cs +++ b/src/OrchardCoreContrib.ContentPreview/Manifest.cs @@ -6,7 +6,7 @@ Name = "Content Preview", Author = ManifestConstants.Author, Website = ManifestConstants.Website, - Version = "1.3.1", + Version = "1.5.0", Category = "Content Management" )] diff --git a/src/OrchardCoreContrib.ContentPreview/OrchardCoreContrib.ContentPreview.csproj b/src/OrchardCoreContrib.ContentPreview/OrchardCoreContrib.ContentPreview.csproj index b0291f3c..7a019129 100644 --- a/src/OrchardCoreContrib.ContentPreview/OrchardCoreContrib.ContentPreview.csproj +++ b/src/OrchardCoreContrib.ContentPreview/OrchardCoreContrib.ContentPreview.csproj @@ -2,10 +2,11 @@ true - 1.4.0 + 1.5.0 The Orchard Core Contrib Team Provides a list of content preview features such as page preview bar. + README.md BSD-3-Clause https://github.com/OrchardCoreContrib/OrchardCoreContrib.Modules/tree/main/src/OrchardCoreContrib.ContentPreview/README.md https://github.com/OrchardCoreContrib/OrchardCoreContrib.Modules @@ -26,6 +27,7 @@ + @@ -35,6 +37,7 @@ + diff --git a/src/OrchardCoreContrib.ContentPreview/PagePreviewMiddleware.cs b/src/OrchardCoreContrib.ContentPreview/PagePreviewMiddleware.cs index 5d556e69..7894a52e 100644 --- a/src/OrchardCoreContrib.ContentPreview/PagePreviewMiddleware.cs +++ b/src/OrchardCoreContrib.ContentPreview/PagePreviewMiddleware.cs @@ -3,86 +3,78 @@ using OrchardCore.Admin; using OrchardCore.Environment.Shell; using OrchardCore.Users; -using System; -using System.Linq; -using System.Threading.Tasks; -namespace OrchardCoreContrib.ContentPreview +namespace OrchardCoreContrib.ContentPreview; + +/// +/// Represents a middleware for a page preview. +/// +/// +/// Craates a new instance of . +/// +/// The . +/// The . +/// The . +/// The . +public class PagePreviewMiddleware( + RequestDelegate next, + IOptions adminOptions, + IOptions userOptions, + IShellFeaturesManager shellFeaturesManager) { + private readonly AdminOptions _adminOptions = adminOptions.Value; + private readonly UserOptions _userOptions = userOptions.Value; + /// - /// Represents a middleware for a page preview. + /// Invokes the logic of the middleware. /// - public class PagePreviewMiddleware + /// The . + public async Task InvokeAsync(HttpContext context) { - private readonly RequestDelegate _next; - private readonly AdminOptions _adminOptions; - private readonly UserOptions _userOptions; - private readonly IShellFeaturesManager _shellFeaturesManager; + var path = context.Request.Path.Value; - /// - /// Craates a new instance of . - /// - /// The . - /// The . - /// The . - /// The . - public PagePreviewMiddleware( - RequestDelegate next, - IOptions adminOptions, - IOptions userOptions, - IShellFeaturesManager shellFeaturesManager) + // Skip if the user is not authenticated + if (!context.User.Identity.IsAuthenticated) { - _next = next; - _adminOptions = adminOptions.Value; - _userOptions = userOptions.Value; - _shellFeaturesManager = shellFeaturesManager; + await next(context); + + return; } - /// - /// Invokes the logic of the middleware. - /// - /// The . - public Task Invoke(HttpContext context) + // Skip if the current request for a login page + if (path.StartsWith($"/{_userOptions.LoginPath}", StringComparison.OrdinalIgnoreCase)) { - var path = context.Request.Path.Value; + await next(context); - // Skip if the user is not authenticated - if (!context.User.Identity.IsAuthenticated) - { - return _next(context); - } + return; + } - // Skip if the current request for a login page - if (path.StartsWith($"/{_userOptions.LoginPath}", StringComparison.OrdinalIgnoreCase)) - { - return _next(context); - } + // Skip if the current request for an admin page + if (path.StartsWith($"/{_adminOptions.AdminUrlPrefix}", StringComparison.OrdinalIgnoreCase)) + { + await next(context); - // Skip if the current request for an admin page - if (path.StartsWith($"/{_adminOptions.AdminUrlPrefix}", StringComparison.OrdinalIgnoreCase)) - { - return _next(context); - } + return; + } - var featureEnabled = _shellFeaturesManager - .GetEnabledFeaturesAsync().Result - .Any(f => f.Id == Constants.PagePreviewBarFeatureId); + var enabledFeatures = await shellFeaturesManager.GetEnabledFeaturesAsync(); - if (!featureEnabled) - { - return _next(context); - } + if (!enabledFeatures.Any(f => f.Id == Constants.PagePreviewBarFeatureId)) + { + await next(context); - var isPreview = context.Request.Query.ContainsKey(Constants.PreviewSlug); + return; + } - if (!path.Contains(Constants.PreviewSlug) && !isPreview) - { - var url = String.Concat(context.Request.PathBase.Value, $"/{Constants.PreviewSlug}", context.Request.Path.Value); - - context.Response.Redirect(url); - } + var isPreview = context.Request.Query.ContainsKey(Constants.PreviewSlug); - return _next(context); + if (!path.Contains(Constants.PreviewSlug) && !isPreview) + { + var url = string.Concat(context.Request.PathBase.Value, $"/{Constants.PreviewSlug}", context.Request.Path.Value); + + context.Response.Redirect(url); } + + await next(context); } } diff --git a/src/OrchardCoreContrib.ContentPreview/README.md b/src/OrchardCoreContrib.ContentPreview/README.md index b1524aa1..7fd0daf0 100644 --- a/src/OrchardCoreContrib.ContentPreview/README.md +++ b/src/OrchardCoreContrib.ContentPreview/README.md @@ -4,7 +4,7 @@ This module allows you to preview your page in different devices. ## Version -1.3.1 +1.5.0 ## Category @@ -26,6 +26,7 @@ This module has no dependencies. | Name | Version | |---------------------------------------------------------------------------------------------------------------------|-------------| +| [`OrchardCoreContrib.ContentPreview`](https://www.nuget.org/packages/OrchardCoreContrib.ContentPreview/1.5.0) | 1.5.0 | | [`OrchardCoreContrib.ContentPreview`](https://www.nuget.org/packages/OrchardCoreContrib.ContentPreview/1.4.0) | 1.4.0 | | [`OrchardCoreContrib.ContentPreview`](https://www.nuget.org/packages/OrchardCoreContrib.ContentPreview/1.3.1) | 1.3.1 | | [`OrchardCoreContrib.ContentPreview`](https://www.nuget.org/packages/OrchardCoreContrib.ContentPreview/1.3.0) | 1.3.0 | diff --git a/src/OrchardCoreContrib.ContentPreview/RequestDestination.cs b/src/OrchardCoreContrib.ContentPreview/RequestDestination.cs deleted file mode 100644 index 72593980..00000000 --- a/src/OrchardCoreContrib.ContentPreview/RequestDestination.cs +++ /dev/null @@ -1,18 +0,0 @@ -namespace OrchardCoreContrib.ContentPreview -{ - /// - /// Represents an enum like for request destination. - /// - public class RequestDestination - { - /// - /// Request comes from document aka page. - /// - public readonly static string Document = "document"; - - /// - /// Request comes from IFrame. - /// - public readonly static string Iframe = "iframe"; - } -} diff --git a/src/OrchardCoreContrib.ContentPreview/ResourceManagementOptionsConfiguration.cs b/src/OrchardCoreContrib.ContentPreview/ResourceManagementOptionsConfiguration.cs index 8ab99f30..437003bf 100644 --- a/src/OrchardCoreContrib.ContentPreview/ResourceManagementOptionsConfiguration.cs +++ b/src/OrchardCoreContrib.ContentPreview/ResourceManagementOptionsConfiguration.cs @@ -1,34 +1,33 @@ using Microsoft.Extensions.Options; using OrchardCore.ResourceManagement; -namespace OrchardCoreContrib.ContentPreview +namespace OrchardCoreContrib.ContentPreview; + +/// +/// Configure the resources that will be used in the module. +/// +public class ResourceManagementOptionsConfiguration : IConfigureOptions { - /// - /// Configure the resources that will be used in the module. - /// - public class ResourceManagementOptionsConfiguration : IConfigureOptions - { - private static readonly ResourceManifest _manifest; + private static readonly ResourceManifest _manifest; - static ResourceManagementOptionsConfiguration() - { - _manifest = new ResourceManifest(); + static ResourceManagementOptionsConfiguration() + { + _manifest = new ResourceManifest(); - _manifest - .DefineScript("page-preview-bar") - .SetUrl("~/OrchardCoreContrib.ContentPreview/Scripts/PagePreviewBar.js") - .SetVersion("1.0.0"); + _manifest + .DefineScript("page-preview-bar") + .SetUrl("~/OrchardCoreContrib.ContentPreview/Scripts/PagePreviewBar.js") + .SetVersion("1.0.0"); - _manifest - .DefineStyle("page-preview-bar") - .SetUrl("~/OrchardCoreContrib.ContentPreview/Styles/PagePreviewBar.css") - .SetVersion("1.0.0"); - } + _manifest + .DefineStyle("page-preview-bar") + .SetUrl("~/OrchardCoreContrib.ContentPreview/Styles/PagePreviewBar.css") + .SetVersion("1.0.0"); + } - /// - public void Configure(ResourceManagementOptions options) - { - options.ResourceManifests.Add(_manifest); - } + /// + public void Configure(ResourceManagementOptions options) + { + options.ResourceManifests.Add(_manifest); } } diff --git a/src/OrchardCoreContrib.ContentPreview/Startup.cs b/src/OrchardCoreContrib.ContentPreview/Startup.cs index 4f1c831a..ad7f2ea3 100644 --- a/src/OrchardCoreContrib.ContentPreview/Startup.cs +++ b/src/OrchardCoreContrib.ContentPreview/Startup.cs @@ -6,33 +6,35 @@ using OrchardCore.Mvc.Core.Utilities; using OrchardCore.ResourceManagement; using OrchardCoreContrib.ContentPreview.Controllers; -using System; -namespace OrchardCoreContrib.ContentPreview +namespace OrchardCoreContrib.ContentPreview; + +/// +/// Represents an entry point to register the page preview bar required services. +/// +[Feature("OrchardCoreContrib.ContentPreview.PagePreviewBar")] +public class Startup : StartupBase { - /// - /// Represents an entry point to register the page preview bar required services. - /// - [Feature("OrchardCoreContrib.ContentPreview.PagePreviewBar")] - public class Startup : StartupBase + /// + public override void ConfigureServices(IServiceCollection services) { - /// - public override void ConfigureServices(IServiceCollection services) - { - services.AddTransient, ResourceManagementOptionsConfiguration>(); - } + services.AddTransient, ResourceManagementOptionsConfiguration>(); + } - /// - public override void Configure(IApplicationBuilder app, IEndpointRouteBuilder routes, IServiceProvider serviceProvider) - { - routes.MapAreaControllerRoute( - name: "PreviewContent", - areaName: "OrchardCoreContrib.ContentPreview", - pattern: "/Preview/{*page}", - defaults: new { controller = typeof(PreviewController).ControllerName(), action = nameof(PreviewController.Index) } - ); + /// + public override void Configure(IApplicationBuilder app, IEndpointRouteBuilder routes, IServiceProvider serviceProvider) + { + routes.MapAreaControllerRoute( + name: "PreviewContent", + areaName: "OrchardCoreContrib.ContentPreview", + pattern: "/Preview/{*page}", + defaults: new + { + controller = typeof(PreviewController).ControllerName(), + action = nameof(PreviewController.Index) + } + ); - app.UsePagePreview(); - } + app.UsePagePreview(); } } diff --git a/src/OrchardCoreContrib.ContentPreview/Views/Preview/Index.cshtml b/src/OrchardCoreContrib.ContentPreview/Views/Preview/Index.cshtml index c5134c94..3df80b86 100644 --- a/src/OrchardCoreContrib.ContentPreview/Views/Preview/Index.cshtml +++ b/src/OrchardCoreContrib.ContentPreview/Views/Preview/Index.cshtml @@ -19,13 +19,12 @@ - + - - - - - + + + +