From 32e7d862f9cc8fb885acba05bc06e39b45a1311c Mon Sep 17 00:00:00 2001 From: aaronamm Date: Thu, 14 Nov 2024 23:36:34 +0700 Subject: [PATCH] Add AutorouteSettings.AllowSetAsHomePage to control whether user can set a content to display on a home page (#8424) * Add AutorouteSettings.AllowSetAsHomePage to control whether user can set a content to display on a home page * Extending the description of the AllowSetAsHomePage setting * Updating setting label --------- Co-authored-by: Benedek Farkas --- .../Orchard.Autoroute/Settings/AutorouteSettings.cs | 3 +++ .../Views/DefinitionTemplates/AutorouteSettings.cshtml | 10 +++++++++- .../Views/EditorTemplates/Parts.Autoroute.Edit.cshtml | 2 +- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/Orchard.Web/Modules/Orchard.Autoroute/Settings/AutorouteSettings.cs b/src/Orchard.Web/Modules/Orchard.Autoroute/Settings/AutorouteSettings.cs index 75bc1a033de..4c8291b0adb 100644 --- a/src/Orchard.Web/Modules/Orchard.Autoroute/Settings/AutorouteSettings.cs +++ b/src/Orchard.Web/Modules/Orchard.Autoroute/Settings/AutorouteSettings.cs @@ -18,6 +18,7 @@ public class AutorouteSettings { public AutorouteSettings() { PerItemConfiguration = false; AllowCustomPattern = true; + AllowSetAsHomePage = true; UseCulturePattern = false; AutomaticAdjustmentOnEdit = false; PatternDefinitions = "[]"; @@ -27,6 +28,7 @@ public AutorouteSettings() { public bool PerItemConfiguration { get; set; } public bool AllowCustomPattern { get; set; } + public bool AllowSetAsHomePage { get; set; } public bool UseCulturePattern { get; set; } public bool AutomaticAdjustmentOnEdit { get; set; } public bool? IsDefault { get; set; } @@ -100,6 +102,7 @@ public List DefaultPatterns { public void Build(ContentTypePartDefinitionBuilder builder) { builder.WithSetting("AutorouteSettings.PerItemConfiguration", PerItemConfiguration.ToString(CultureInfo.InvariantCulture)); builder.WithSetting("AutorouteSettings.AllowCustomPattern", AllowCustomPattern.ToString(CultureInfo.InvariantCulture)); + builder.WithSetting("AutorouteSettings.AllowSetAsHomePage", AllowSetAsHomePage.ToString(CultureInfo.InvariantCulture)); builder.WithSetting("AutorouteSettings.UseCulturePattern", UseCulturePattern.ToString(CultureInfo.InvariantCulture)); builder.WithSetting("AutorouteSettings.AutomaticAdjustmentOnEdit", AutomaticAdjustmentOnEdit.ToString(CultureInfo.InvariantCulture)); builder.WithSetting("AutorouteSettings.PatternDefinitions", PatternDefinitions); diff --git a/src/Orchard.Web/Modules/Orchard.Autoroute/Views/DefinitionTemplates/AutorouteSettings.cshtml b/src/Orchard.Web/Modules/Orchard.Autoroute/Views/DefinitionTemplates/AutorouteSettings.cshtml index ebc34592064..5f400d3886e 100644 --- a/src/Orchard.Web/Modules/Orchard.Autoroute/Views/DefinitionTemplates/AutorouteSettings.cshtml +++ b/src/Orchard.Web/Modules/Orchard.Autoroute/Views/DefinitionTemplates/AutorouteSettings.cshtml @@ -15,7 +15,15 @@
@Html.CheckBoxFor(m => m.AllowCustomPattern) - @T("Allow the user to change the pattern on each item") + @T("Allow the user to change the pattern on each item.") +
+ +
+
+ @Html.CheckBoxFor(m => m.AllowSetAsHomePage) + + @T("Allow the user to set a content item of this type as the home page.") + @T("NOTE: Certain combinations of content type definitions and permission settings can create circumstances for non-Admin users with Dashboard access to remove the home page without the ability to set another one. Use this option with caution.")
diff --git a/src/Orchard.Web/Modules/Orchard.Autoroute/Views/EditorTemplates/Parts.Autoroute.Edit.cshtml b/src/Orchard.Web/Modules/Orchard.Autoroute/Views/EditorTemplates/Parts.Autoroute.Edit.cshtml index db6d9be356d..8e5d5f5ed16 100644 --- a/src/Orchard.Web/Modules/Orchard.Autoroute/Views/EditorTemplates/Parts.Autoroute.Edit.cshtml +++ b/src/Orchard.Web/Modules/Orchard.Autoroute/Views/EditorTemplates/Parts.Autoroute.Edit.cshtml @@ -51,7 +51,7 @@
@if (!Model.IsHomePage) { - if (AuthorizedFor(Permissions.SetHomePage)) { + if (AuthorizedFor(Permissions.SetHomePage) && Model.Settings.AllowSetAsHomePage) {
@Html.CheckBoxFor(m => m.PromoteToHomePage)