Closed (fixed)
Project:
Drupal core
Version:
8.0.x-dev
Component:
user system
Priority:
Normal
Category:
Task
Assigned:
Reporter:
Created:
29 Jun 2014 at 09:52 UTC
Updated:
7 Nov 2014 at 11:24 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
znerol commentedComment #3
sunHm. This change seems to imply that
1. while you can access /user as anonymous, you are always redirected to /user/login
2. while you can access /user as authenticated, you are always redirected to /user/{id}
3. /user always redirects and no longer shows page output on its own.
I can't remember why we have the special output behavior on /user. IIRC, there have been attempts to change it in similar ways in the past already but they were shot down. Might be worth to search for old/closed issues with keywords "make /user path always redirect"…
Comment #4
znerol commentedThe login-form is still rendered on
/userbecause some testsPOSTthere. A second reason is that the installer sets the front page to/usersince the node module is not mandatory anymore.Accessing
/uservia aGETrequest results in a redirect - this is already true for HEAD.Let's set the front page to
/user/loginby default.Comment #5
znerol commentedComment #7
znerol commentedComment #8
effulgentsia commentedWhat about for symmetry, moving this redirect into an AccessDeniedSubscriber rather than UserController::userPage(), so that we can set access for /user to be only for authenticated users? That would allow us to remove the stupid hack we currently have in user_translated_menu_link_alter(), and the corollary concept of a MenuLinkInterface::isHidden() being carried over into #2256521: [META] New plan, Phase 2: Implement menu links as plugins, including static admin links and views, and custom links with menu_link_content entity, all managed via menu_ui module and that per #2256521-91: [META] New plan, Phase 2: Implement menu links as plugins, including static admin links and views, and custom links with menu_link_content entity, all managed via menu_ui module will cause us grief in #1805054: Cache localized, access filtered, URL resolved, and rendered menu trees.
Yeah, I'd love to know that. HEAD's behavior of /user duplicating rather than redirecting to /user/login seems stupid to me, so if digging through issue history turns up something useful, it would be good to get that info into the docs of UserController::userPage().
Comment #9
znerol commentedLet's try that.
Comment #10
znerol commentedReroll.
Comment #12
znerol commentedRestore missing use-statement in form builder test.
Comment #13
znerol commentedRemove account-menu-link-hide-hack.
Comment #16
znerol commentedFix the user accounts link test.
Comment #17
znerol commentedComment #18
pwolanin commentedI think I like the solution in #2306991: MyAccountMenuLink should dynamically adjust route parameters, not hidden property better so we can actually link to the user's account and avoid any redirects.
Comment #19
znerol commentedReroll.
Re #18: No matter how the current unfortunate user-redirect is resolved, it will be necessary to fix the tests, such that we can get rid of the duplicate user-login form on
/userand/user/login. Most of the changes in this patch are for that reason.Comment #20
dawehnerThis looks really great!
That todo is in already.
<3
Comment #21
znerol commentedAfter rereading the discussion in #2282161: Split off link/url generation trait I have the impression that
UrlGeneratorTraitshould not be used here. Also the docs of the trait pretty clearly state that it should only be used in controllers.Therefore let's follow @Crell's comment over in #2288911-32: Use route name instead of system path in user maintenance mode subscriber and instead implement a redirect helper method. Note that according to #355157: 302 response code from drupal_redirect_form() violates HTTP/1.1 spec we should use 303 here instead of 302. Also changed array-syntax in the new class.
Comment #23
znerol commentedFix parameters to
redirect()method.Comment #25
dawehnerDidn't we agreed that should just drop the empty check here? If you specify "" as frontpage, well it is what you wanted, maybe.
There is no reason to redirect to user first in order to later redirect to user/{user}.
It is also odd that this lives inside the MaintenanceModeSubscriber in general, all those user/login user/register user.page etc.
directects should happen
Comment #26
znerol commentedYes, in fact we expect
page.frontbeing set also in other places. The config value is always set during installation and also when migrating from previous versions.True, however redirection for authenticated users is being worked on in #2288911: Use route name instead of system path in user maintenance mode subscriber. That one is quite a bit more complex though, see comment #27 for more details.
Comment #29
dawehnerBut can't we simply redirect to user.page directly and be done? This doesn't seem to be a big conflict to be honest.
Comment #30
znerol commentedDone.
Comment #31
wim leersComment #32
dawehnerThis really looks great!
Can't we use the url gen. directly?
Another dump question, are we sure we don't loose test coverage for sites without mod rewrite?
Comment #33
znerol commentedI think this is out of scope, the redirects will be removed in #2288911: Use route name instead of system path in user maintenance mode subscriber.
In Drupal 8 the URL-style for non-clean URLs changed from
index.php?q=/nodetoindex.php/node, see this change record.Comment #34
znerol commentedReroll after #2330363: Enhance the controller resolver to get a route match class.
Comment #36
znerol commentedSince #2323759: Modularize kernel exception handling the maintenance page is also displayed on pages generating exceptions (including 403, 404 etc.). Therefore it is necessary to rise the priority of the
AccessDeniedSubscribersuch that redirection can happen before the coreMaintenanceModeSubscriberkicks in.Comment #38
dawehnerI really like the general idea to not make the default behaviour of the frontpage not special for anonymous users.
Out of scope but maybe worthwhile for the future: I wonder whether we should move this into the UrlGeneratorTrait?
Comment #39
andypostI think that's regression, /user now does 2 redirects and if user has no access to profiles then wtf could happen.
Also "/user" a path that pointed in a lot of manuals and ddos point (no cache) ...
front page is for anonymous user?
Comment #40
andypostRedirect anonymous

redirect authorized

Comment #41
znerol commentedRe #38: Commented in #2344491: Move ControllerBase::redirect() to UrlGeneratorTrait.
Re #39:
The redirect from
usertouser/loginwill only happen for anonymous users, no problem there.The behavior when accessing
user/loginas an authenticated user did not change, except that there is one redirection less. Before the browser was first redirected touserand then further touser/Xfrom within theuserPagecontroller action.It would be very easy to add cache-control headers for that redirect. It can be cached for anonymous users and I agree it should be.
I admit that this looks silly. But please keep in mind that the front-page is set to
nodeas soon as the node module is enabled. So we have this situation mainly during tests. Perhaps the system module could provide a front-page which only exists as long as the front-page settings is not yet customized, that would be cleaner.Re #40: Regarding the http status code see #355157: 302 response code from drupal_redirect_form() violates HTTP/1.1 spec. The 302 is generated by
ControllerBase::redirect().Comment #42
catchThis still needs an issue summary update.
It's not clear to me at all from the discussion why the extra redirect for anonymous users is necessary. We could override the route used for the page if we have to no?
In Drupal 7 we do not have any of these redirects (I think they mainly got added because the new routing system doesn't have an equivalent of to_arg).
Comment #43
znerol commentedFiled #2346671: Two templates necessary in order to customize the login page. I think HEAD is broken in this regard and this patch fixes that.
Comment #44
znerol commentedReroll.
Comment #46
znerol commentedReuploading #44, this should pass after #2347111: StackKernelIntegrationTest is not testing a successful request got committed.
Comment #47
dawehnerGiven #2346671: Two templates necessary in order to customize the login page I would consider that this solves a bug.
Comment #48
alexpottre #41
I don't think this is true - in the standard profile the frontpage is node but just installing the node module in minimal does not change the frontpage. I think that this is the correct behaviour as I don't think installing a module should change the front page of your website.
This patch makes complete sense to me - having two login pages at /user and /user/login as we do in HEAD is silly.
The outstanding question is what happens if the user has no access to user profiles - I think that this question is moot because a user can always view their own profile and this patch does nothing to change that.
Comment #50
alexpottAssigning to @catch because of his concerns about redirects. I can't see a way of avoiding them.
Comment #51
catchThis doesn't redirect to either the user page or the login form, it's only redirecting to user.canonical.
That does make me wonder why we need to have the exception listener, as opposed to handling the redirect for anonymous users here. Having one redirect in the controller, and one in the exception listener, which checks whether we're on this route anyway seems very indirect.
Also the end result of this, regardless of the above, is that /user only ever redirects. What's the use case for the route now? Wondering if we could maybe get rid of it altogether in a follow-up.
Comment #52
znerol commentedWhen an anonymous user tries to access
/user(the my-account-page), a 403 exception is thrown. Therefore the redirect for anonymous users needs to happen in the exception listener.The route is necessary for the my-account link. That link points to a different profile for each user.
Comment #53
catchThat's due to the access on the route though. If we're going to redirect from the route for both cases, we can change the access. The the title callback can switch between "My Account" and "Login".
Yeah I'm wondering if we can change that so it actually points to the specific URL for each user - would need some special handling but would likely be less complex than a route that only does a redirect and an exception handler.
Comment #54
znerol commentedThis does not work in maintenance mode.
Introducing the exception handler is the whole point of this issue. It removes the duplicated redirect logic in the user-controller and maintenance mode subscriber by restricting the
/userroute to exactly one purpose.#18 also asked for a more intelligent route on
/userbut as pointed out in #19 we would still need to fix the tests.Comment #55
catchWhy exactly doesn't it work?
Returning the redirect response is only a single line of code, I don't think DRY applies here.
Comment #56
znerol commentedMaintenance mode happens in a request subscriber, i.e. it is before the controller is executed. If we want to redirect anonymous users to the login page, we need to do that in a high priority request event subscriber - or use an exception subscriber. #2288911: Use route name instead of system path in user maintenance mode subscriber wants to move the maintenance mode subscriber of the user module to a low priority request subscriber.
The exception subscriber approach allows us to actually assign proper access permissions and restrict the routes to their purpose. This in turn lets us remove the dubious
MyAccountMenuLinkclass and also fixes #2346671: Two templates necessary in order to customize the login page.I see the
AccessDeniedSubscriberas a UX pattern which can be reused in similar situations. Instead of showing a 403 we want to redirect anonymous users to a meaningful target page (we do the same for authenticated users in #2346671). This is also whatHEADdoes - but it (mis-)uses the maintenance mode subscriber for that purpose.Comment #57
effulgentsia commentedSo long as we have a "My account" link that points to the
/userroute, and we want that link visible for authenticated and not visible for anonymous, then I think the best way to model that is via route access, as this patch is doing, which lets us remove the MyAccountMenuLink::isEnabled() hack as this patch does.That might be good, but there's no working patch for that. If someone writes a patch for that, then great, but until that happens, I agree with #56's reasoning that #52 is an improvement over HEAD, and doesn't preclude removing the route entirely in a followup if someone wants to pursue that.
Comment #58
effulgentsia commentedComment #59
effulgentsia commentedI updated the summary and opened #2360971: The user.page route only redirects, so remove it as a follow-up. I think all of catch's other concerns have been answered, but @catch: please correct me if I'm wrong on that.
I was about to RTBC this patch, except:
From what I can tell, that's not true. There's the same amount of redirection because MaintenanceModeSubscriber has this code that runs regardless of maintenance status that is unchanged by this patch:
However, due to the above, this code:
creates one additional redirection for authenticated users: instead of HEAD's (<front> = user) -> user/N, the patch does (<front> = user/login) -> user -> user/N. But I think this can be fixed by changing the MaintenanceModeSubscriber code to redirect to entity.user.canonical directly, so setting to "needs work" for that.
Comment #60
znerol commented@effulgentsia thanks for the issue summary update and also for the review.
#2288911: Use route name instead of system path in user maintenance mode subscriber is supposed to address the authenticated users case, but I'm okay with fixing that line here.
Meanwhile the
UrlGeneratorTraithas been introduced intoMaintenanceModeSubscriberand also got aredirect()method. For the sake of removing duplicated code let's also use it in theAccessDeniedSubscriber.Comment #61
effulgentsia commentedThanks!
Comment #62
effulgentsia commentedSorry for unRTBCing, but I wanted to fix some docs. Please re-RTBC if these docs are ok.
Comment #63
catchOK with #2360971: The user.page route only redirects, so remove it open and the extra redirect removed I'm happy with this otherwise, thanks for all the clarifications.
Comment #64
alexpottNew docs look good to me. Thanks @effulgentsia
Comment #65
wim leersYAY!
Comment #66
catchCommitted/pushed to 8.0.x, thanks!