nova-telescope icon indicating copy to clipboard operation
nova-telescope copied to clipboard

Sidebar link does not respect the viewTelescope Gate

Open atmediauk opened this issue 4 years ago • 5 comments

Thank you for the package, it works really well.

As mentioned in the title, the sidebar link does not respect the viewTelescope Gate and is shown permanently.

For example:

// App\Providers\TelescopeServiceProvider

        Gate::define('viewTelescope', function ($user) {
            // return in_array($user->email, [
                '[email protected]'
            // ]);
        });

When a user logs in on the production environment with a non-whitelisted email they still see the "Telescope" link in the sidebar. When clicking the link it 403's as expected though.

Would it be possible to show/ hide this link based on the gate result?

----EDIT----

Or maybe the navigation.blade.php view can be made publishable so users can modify themselves. This would also allow users to change the text/ styling etc.

atmediauk avatar May 22 '20 18:05 atmediauk

Hi @atmediauk, thanks for writing in! This looks like a compelling feature. I haven't run into the problem, because I have been handling permissions differently: namely by conditionally adding the tool in Nova, depending on user role.

What you suggest makes a lot of sense. If you can get a PR in, I will be happy to look at it. I can't promise how fast I can get to adding this myself. :)

mikebronner avatar May 22 '20 18:05 mikebronner

Thanks for the speedy reply. Sure, I'll have a go now 🙌

atmediauk avatar May 22 '20 18:05 atmediauk

Pull request here 😊 https://github.com/GeneaLabs/nova-telescope/pull/10

atmediauk avatar May 22 '20 19:05 atmediauk

You can also register the tool like this, and it will respect the viewTelescope ability.

/**
     * Get the tools that should be listed in the Nova sidebar.
     *
     * @return array
     */
    public function tools()
    {
        return [
            (new NovaTelescope)->canSeeWhen('viewTelescope'),
        ];
    }

madsem avatar Aug 25 '20 12:08 madsem

@madsem Thanks for supplying that alternative solution. I like that. I'll update the documentation.

mikebronner avatar Aug 25 '20 14:08 mikebronner