Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix implicit HomeRoute dependency in Autoroute #17321

Merged
merged 5 commits into from
Jan 9, 2025

Conversation

jbytes1027
Copy link
Contributor

Fix #17244

Changes:

  • Add HomeRoute dependency to Autoroute
  • Update admin message wording

The Autoroute was written such that it assumes the home route feature is enabled. This PR makes that assumption an explicit dependency.

@jbytes1027 jbytes1027 changed the title Fix17244 Fix #17244 Jan 9, 2025
Copy link
Member

@Piedone Piedone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where in the code is the hidden dependency/assumption?

@jbytes1027
Copy link
Contributor Author

Where in the code is the hidden dependency/assumption?

It's not technically the homepage module that it references but the homepage property that is useless without the homepage module. A quick search yields the following:

Handlers/AutoroutePartHandler.cs
71:                await CheckContainedHomeRouteAsync(part.ContentItem.ContentItemId, containedAspect, (JsonObject)context.PublishingItem.Content);
78:        if (!string.IsNullOrWhiteSpace(part.Path) && !part.Disabled && part.SetHomepage)
80:            await SetHomeRouteAsync(part, homeRoute =>
82:                homeRoute[_options.ContentItemIdKey] = context.ContentItem.ContentItemId;
83:                homeRoute.Remove(_options.JsonPathKey);
145:        clonedPart.SetHomepage = false;
167:    private async Task SetHomeRouteAsync(AutoroutePart part, Action<RouteValueDictionary> action)
171:        site.HomeRoute ??= [];
173:        var homeRoute = site.HomeRoute;
177:            homeRoute[entry.Key] = entry.Value;
180:        action.Invoke(homeRoute);
183:        part.SetHomepage = false;
194:    private async Task CheckContainedHomeRouteAsync(string containerContentItemId, ContainedContentItemsAspect containedAspect, JsonObject content)
207:                    // Only an autoroute part, not a default handler aspect can set itself as the homepage.
209:                    if (autoroutePart != null && autoroutePart.SetHomepage)
211:                        await SetHomeRouteAsync(autoroutePart, homeRoute =>
213:                            homeRoute[_options.ContentItemIdKey] = containerContentItemId;
214:                            homeRoute[_options.JsonPathKey] = jItem.GetNormalizedPath();

Permissions.cs
7:    public static readonly Permission SetHomepage = new("SetHomepage", "Set homepage.");
11:        SetHomepage,

Views/AutoroutePart.Edit.cshtml
56:        var authorized = await AuthorizationService.AuthorizeAsync(User, Permissions.SetHomepage);
57:        var showHomepageOption = Model.Settings.ShowHomepageOption && authorized;
59:        if (Model.IsHomepage)
61:            <div class="alert alert-info">@T["This content item is the current homepage"]</div>
65:            if (showHomepageOption)
70:                            <input type="checkbox" class="form-check-input" asp-for="SetHomepage" checked="@Model.SetHomepage" />
71:                            <label class="form-check-label" asp-for="SetHomepage">@T["Set as homepage"]</label>
72:                            <span class="hint dashed">@T["Check to set this content item as the homepage once published."]</span>

ViewModels/AutoroutePartSettingsViewModel.cs
9:    public bool ShowHomepageOption { get; set; }

Drivers/AutoroutePartDisplayDriver.cs
53:            model.SetHomepage = false;
56:            var homeRoute = siteSettings.HomeRoute;
58:            if (homeRoute != null && homeRoute.TryGetValue(_options.ContainedContentItemIdKey, out var containedContentItemId))
62:                    model.IsHomepage = true;
65:            else if (string.Equals(autoroutePart.ContentItem.ContentItemId, homeRoute?[_options.ContentItemIdKey]?.ToString(), StringComparison.OrdinalIgnoreCase))
67:                model.IsHomepage = true;
111:            if (httpContext != null && await _authorizationService.AuthorizeAsync(httpContext.User, Permissions.SetHomepage))
113:                await context.Updater.TryUpdateModelAsync(model, Prefix, t => t.SetHomepage);

Views/AutoroutePartSettings.Edit.cshtml
39:        <input type="checkbox" class="form-check-input" asp-for="ShowHomepageOption" checked="@Model.ShowHomepageOption">
40:        <label class="form-check-label" asp-for="ShowHomepageOption">@T["Show homepage options"]</label>
41:        <span class="hint dashed">@T["Check to allow the content items of this content type to be set as the homepage. It will only be visible to users with the appropriate permission."]</span>

ViewModels/AutoroutePartViewModel.cs
10:    public bool SetHomepage { get; set; }
12:    public bool IsHomepage { get; set; }

Settings/AutoroutePartSettingsDisplayDriver.cs
35:            model.ShowHomepageOption = settings.ShowHomepageOption;
52:            m => m.ShowHomepageOption,
69:                ShowHomepageOption = model.ShowHomepageOption,

Models/AutoroutePartSettings.cs
19:    /// Whether to display an option to set the content item as the homepage.
21:    public bool ShowHomepageOption { get; set; }

Models/AutoroutePartExtensions.cs
12:            yield return new ValidationResult(S["Your permalink can't be set to the homepage, please use the homepage option instead."], new[] { nameof(autoroute.Path) });

Copy link
Member

@Piedone Piedone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@Piedone Piedone changed the title Fix #17244 Fix implicit HomeRoute dependency in Autoroute Jan 9, 2025
Co-authored-by: Mike Alhayek <[email protected]>
@MikeAlhayek MikeAlhayek enabled auto-merge (squash) January 9, 2025 21:27
@MikeAlhayek MikeAlhayek merged commit 2d71ad4 into OrchardCMS:main Jan 9, 2025
6 checks passed
@jbytes1027 jbytes1027 deleted the Fix17244 branch January 9, 2025 21:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Homepage settings are visible when feature is disabled
3 participants