dniccum / nova-documentation

A Laravel Nova tool that allows you to add markdown-based documentation to your administrator's dashboard.
MIT License
37 stars 15 forks source link

`canSee` implementation #17

Open blackfyre opened 2 years ago

blackfyre commented 2 years ago

Our use case would require access control on select pages, any ideas on the feasibility? A canSee callback, like how it is on nova resource fields, added to the tool instantiation seems like a good starting point.

dniccum commented 2 years ago

Obviously this functionality doesn't exist at the moment. I hadn't planned on implementing this type of feature, but you are more than welcome to take this on and submit a PR.

bluec commented 2 years ago

Hi, canSee is already implemented as this type of Authorization is a standard feature that all tools inherit from Laravel\Nova\Tool

You can use it like this, for example:

use Dniccum\NovaDocumentation\NovaDocumentation;

...

/**
 * Get the tools that should be listed in the Nova sidebar.
 *
 * @return array
 */
public function tools()
{
    return [
        // other tools
        (new NovaDocumentation)->canSee(function ($request) {
            return $request->user()->can('view documentation');
        }),
    ];
}
blackfyre commented 2 years ago

@bluec That's true, however the ultimate scope is for individual pages instead of the complete tool.

bluec commented 2 years ago

Ah my apologies I hadn't noticed that you wanted to restrict access to individual pages.

That is not possible and I don't know how easily it could be added. I've been looking at tweaking a few things in this tool but the lack of any in-depth developer documentation on Nova Tools makes it hard work.