orchidsoftware / crud

Simplify the process of building CRUD (Create, Read, Update, Delete) functionality in Laravel using the features of Orchid.
https://orchid.software
MIT License
137 stars 34 forks source link

Title resources is showing even though no permissions #71

Open TowlieeNetworks opened 2 years ago

TowlieeNetworks commented 2 years ago

title resources is showing even though the user does not have any of the appropriate permissions set for the resource menu items. This can be fixed with a simple if statement in the "vendor\orchid\crud\src\Arbitrator.php" @ "registerMenu"

`private function registerMenu(Resource $resource, int $key): Arbitrator { if (! $resource::displayInNavigation()) { return $this; }

    View::composer('platform::dashboard', function () use ($resource, $key) {

        if (user()->hasAnyAccess('manage-crud-resource-*')) {
            $title = Menu::make()
                ->canSee($key === 0)
                ->title(__('Resources'))
                ->sort($resource::sort());
            Dashboard::registerMenuElement(\Orchid\Platform\Dashboard::MENU_MAIN, $title);
        }

        $menu = Menu::make($resource::label())
            ->icon($resource::icon())
            ->route('platform.resource.list', [$resource::uriKey()])
            ->active($this->activeMenu($resource))
            ->permission($resource::permission())
            ->sort($resource::sort());
        Dashboard::registerMenuElement(\Orchid\Platform\Dashboard::MENU_MAIN, $menu);
    });

    return $this;
}`
szonov commented 2 years ago

Looks like proposed 'manage-crud-resource-*' is your application specific permissions, as well as user() function, and should not be part of library. Just implement valid displayInNavigation() function in every resource (which can depends on your application logic/permissions) and title 'Resources' will disappear :)