Users: fix UserMenu.cshtml for anonymous visitors and without the Avatar feature - #340
Open
DavidHolmlabs wants to merge 1 commit into
Conversation
…ar feature - Anonymous visitors get the stock OrchardCore.Users menu (login link) instead of the avatar dropdown. Before, the view built an avatar from a null User.Identity.Name, which throws ArgumentNullException (Parameter 'DisplayName') and returns 500 for every page rendering the user menu (e.g. TheTheme's navbar). - Resolve IAvatarService optionally. Orchard Core binds a module's shape templates to every enabled feature of the module (ShapeTemplateBindingStrategy), so the view is active whenever any OrchardCoreContrib.Users feature is - e.g. only Impersonation - and the [Feature] attribute doesn't prevent that. Without an avatar provider every page threw "No service for type IAvatarService". It now falls back to a user icon, also when the service returns an empty avatar (NullAvatarService). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Member
|
Thanks @DavidHolmlabs I will check your changes and hope to merge ASAP One more thing: please provide the steps to reproduce for the first case, coz I presume it should show the menu after you're logged in |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
OrchardCoreContrib.Users'UserMenu.cshtmloverride breaks every page that renders the user menu (e.g. TheTheme's navbar, including the login page) in two cases. Both reproduce on 1.7.0 and on currentmain.1. Anonymous visitors (Avatar enabled)
The view has no
User.Identity.IsAuthenticatedcheck. For a logged-out visitor it builds an avatar from a nullUser.Identity.Name:Fix: for anonymous visitors, render the same markup as the stock
OrchardCore.UsersUserMenu.cshtml(its anonymous dropdown, or a login link).2. Any Users feature enabled without Avatar (e.g. only Impersonation)
Orchard Core binds a module's shape templates to every enabled feature of that module (
ShapeTemplateBindingStrategy), so this view is active whenever anyOrchardCoreContrib.Usersfeature is. The@attribute [Feature("OrchardCoreContrib.Users.Avatar")]doesn't prevent that. Without the Avatar feature, and with a host that doesn't callAddOrchardCoreContrib(), nothing registersIAvatarService:Fix: resolve
IAvatarServiceoptionally. If there is none, or it returns an empty avatar (NullAvatarService), show a user icon in place of the<img>. Otherwise the dropdown is unchanged.Verification
I booted
OrchardCoreContrib.Modules.Webfrom theSaaSrecipe (TheTheme) withWebApplicationFactoryand requested/. I removed the host-levelNullAvatarServiceregistration inProgram.cs, so the host behaves like a consumer app that doesn't callAddOrchardCoreContrib().ArgumentNullExceptionNo service for type 'IAvatarService'The Profile / Change password links resolve the same before and after.
Downstream we currently work around both bugs with a view override in our own module, which we'd like to delete once this is released.
🤖 Generated with Claude Code