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

Automatically regenerate admin menus when needed #268

Open
Toutouwai opened this issue Feb 15, 2019 · 9 comments

Comments

Projects
None yet
4 participants
@Toutouwai
Copy link

commented Feb 15, 2019

Short description of the enhancement

The first level of dropdown menu items in the admin (and the main menu?) are cached. This request is that the cache be cleared and the menu markup regenerated whenever an action is performed in admin that will result in menu items being added or removed.

For example, in the "Pages" menu dropdown the "Add New", "Find" and "Recent" items are included or not included in the menu for users with a role depending on the permissions given to that role.

2019-02-15_134817

When developing a site and setting up permissions for a role I keep an incognito window open with a test user of that role logged in, so I can check the effects of the permission changes as I make them. I'd like to be able to grant or remove permissions and see the related menu changes applied immediately without needing to log out and back in again, or do any other manual cache clearing if possible.

@jmartsch

This comment has been minimized.

Copy link

commented Feb 15, 2019

You can clear the navigation cache via Tracy console with
wire('session')->removeFor(wire(), 'prnav');
or when you click "refresh" in the modules section the cache is also cleared.

@Toutouwai

This comment has been minimized.

Copy link
Author

commented Feb 15, 2019

@jmartsch, yeah but the nav is cached in the user session, and for a non-superuser there is no option to refresh modules or use the Tracy console.

@jmartsch

This comment has been minimized.

Copy link

commented Feb 15, 2019

you can enable Tracy for non-superusers. Add a permission tracy-debugger to the non-superuser role. I think then you will be able to open up the console.

@jmartsch

This comment has been minimized.

Copy link

commented Feb 15, 2019

And you could also write a module for this task which simply calls the hookClearCaches method. The module could add a button/link/nav item to which users have access to.

@Toutouwai

This comment has been minimized.

Copy link
Author

commented Feb 15, 2019

I think then you will be able to open up the console.

Nope, the console is specifically blocked for non-superusers in the current latest version of Tracy Debugger.
https://processwire.com/talk/topic/12208-tracy-debugger/?do=findComment&comment=180379

I think you're right about a module being one solution. But this request is so that such problems might be avoided by possible changes to the PW core.

@jmartsch

This comment has been minimized.

Copy link

commented Feb 15, 2019

I think there should be a nav item for superusers which clears the navigation cache for all users. And this should be in the core. Seems more and more people are building custom admins, and therefore we would need such functionality.

@adrianbj

This comment has been minimized.

Copy link

commented Feb 15, 2019

@Toutouwai - I haven't forgotten about the Console and non-superusers - just been too busy, but it will be coming soon.

Speaking of Tracy and Modules > Refresh - I always use the "Modules Refresh" from the PW Info panel because it reloads the page you are on, so no need to go to the modules page, refresh and then navigate back to where you were - it's one click from anywhere and it's also available to non-superusers with Tracy permission (even guest on localhost), so it should work for your needs.

@Toutouwai

This comment has been minimized.

Copy link
Author

commented Feb 15, 2019

@adrianbj, I didn't mean to imply you should hurry up with the feature request. No urgency from my end. Thanks for the tip about the Info panel.

Regarding the caching of the menus, I'm wondering if this actually gives any significant performance advantage, or enough to counterbalance the inconvenience of not having menus reflect permission changes as they are made.

For non-superusers the number of items in the top two levels of menu is normally very small. And even for superusers if I clear the cache on every page load using the hook below I don't notice any difference in the page load speed.

$wire->addHookBefore('ProcessController::execute', function(HookEvent $event) {
    $event->wire('session')->removeFor('AdminThemeUikit', 'prnav');
});

I think I'll add this hook to the custom mods I use on each site because the cached menu situation bugs me regularly.

@BernhardBaumrock

This comment has been minimized.

Copy link

commented Apr 22, 2019

Related issue: The menu does also not update when changing language: https://processwire.com/talk/topic/21346-admin-menu-not-changing-language
Thx Robin for creating this issue! Actually I think this is more a bug than a feature request...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.