Problem/Motivation

I find it somewhat confusing for authenticated users to be redirected without a message. It would be nice to have a configurable message shown to authenticated users as well as anonymous users.

Steps to reproduce

1. Be authenticated as a user that is not an admin
2. Visit /admin
3. Be redirected without message, and wonder why.

Proposed resolution

Allow admins to show a message similar to what anonymous users see.

Remaining tasks

User interface changes

3 new settings:
* Display access denied message on authenticated landing page
* Authenticated user 'access denied' message
* Authenticated user 'access denied' message type

API changes

None.

Data model changes

Just the new configuration.

Issue fork r4032login-3201471

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

greggles created an issue. See original summary.

greggles’s picture

Status: Active » Needs review

OK, this needs review.

lkacenja’s picture

Status: Needs review » Reviewed & tested by the community

We reviewed the code and tested the patch on the Foundation's staging server. Works as advertised. Thanks!

greggles’s picture

Title: Show a message when redirecting authenicated users » Show a message when redirecting authenticated users

Just fixing a typo on the title.

nixou’s picture

Version: 8.x-1.x-dev » 2.x-dev
Status: Reviewed & tested by the community » Needs work

Thanks you for the new feature.

This will be merged to the 2.x branch which has to remain compatible with both D8 and D9.

The patch is not passing tests due to the usage of drupal_set_message() which do not exists anymore on D9.
We should also considere to have HTML in the authenticated message as we have for the anonymous one.

Moreover it would be good to have a functional test for this new functionality.

So remaining tasks should be :

  1. Use $this->messenger->addMessage instead of drupal_set_message
  2. Use Markup::create() to allow HTML in message
  3. Add a functional test to cover this case (set the message, login, go to /admin and assert the message is visible)
lkacenja’s picture

I updated the work in #5 to be D9 ready. I also added the requested test.

I hit one unanticipated snag. Since the feature branch was originally created, something with the destination handling changed. When I setup a redirect for authenticated users, I got an infinite set of redirections due to the destination param being set. For instance if authenticated users are were set to be redirected to '/', when I visited '/admin/config' then I'd be redirected to '/?destination=/admin/config'. When the destination is processed, the whole thing starts over again. I attempted to fix this by unsetting the destination for logged in users for redirection happening on the site. Here is that change. Happy to remove this if it could be dealt with in a better way. Thanks!

lkacenja’s picture

Status: Needs work » Needs review
greggles’s picture

Status: Needs review » Reviewed & tested by the community

Any feedback from a maintainer on this? I worked on the initial version, but it's been working well on a D9 site for a while. Would be great if a maintainer could review the current work and test it out.

  • Nixou committed 8d98311 on 2.x authored by greggles
    Issue #3201471 by greggles, lkacenja, Nixou: Show a message when...
nixou’s picture

Status: Reviewed & tested by the community » Fixed

Thank you very much.

I just added some additionnal test and I reorganized the settings form for a better lisibility.

Committed to 2.x-dev, will be released in 2.1.1.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.