verbb / cp-nav

Control Panel Nav is a Craft CMS plugin to help manage your Control Panel navigation.
MIT License
130 stars 11 forks source link

Suggestion: Redirect to first available tab on login #3

Closed darylknight closed 9 years ago

darylknight commented 9 years ago

Comment relating to Twitter conversation...

Almost perfect - I can disable the Dashboard tab (and the user can't re-enable it as it's globally hidden), but even if I hide the dashboard globally it's still the first tab that users see when they login (see screenshot). Is there any way to redirect users to the first enabled tab (Entries) on login?

image

I found a config setting that does this (postCpLoginRedirect) maybe there's a way to build this into the plugin so that the user gets redirected to the first available tab if the Dashboard is turned off?

engram-design commented 9 years ago

That's a tricky one, and in fact, I use the same method using postCpLoginRedirect to skip the Dashboard and go straight to entries for my clients.

I think I'll add it to the roadmap as an additional option that you can configure, rather than have it do this automatically. The aim would be to check for any user (accept admin) if the page they're visiting is hidden hidden, to redirect to first visible page. I'd rather have this is an opt-in option though.

Thanks for the great suggestion!

darylknight commented 9 years ago

That'd be great - I'd like to contribute myself but only really just getting started on plugin dev. At least there's a config option for it so it must be possible somehow!

lindseydiloreto commented 9 years ago

I had to do something similar to this on a website previously... Automatically redirect to the user profile page when a member of the "Business" user group logs in.

Here's a portion of the code I used, maybe this will help...

class BusinessLogicPlugin extends BasePlugin
{

    public function init()
    {
        parent::init();

        if (craft()->request->isCpRequest()) {

            $currentUser = craft()->userSession->getUser();
            $isBusiness = ($currentUser && $currentUser->isInGroup(3));

            if ($isBusiness) {
                $target = UrlHelper::getUrl('myaccount').'#profile';
                craft()->templates->includeJs('window.location = "'.$target.'";');
            }

        }

    }

}
engram-design commented 9 years ago

Thanks @lindseydiloreto this'll come in handy!

engram-design commented 9 years ago

This has been added in the latest version (1.6).

darylknight commented 9 years ago

Excellent work - this just became part of my default install!

lindseydiloreto commented 9 years ago

Ditto. Thanks Josh! :)