serenysoft / nova-permissions

Laravel Nova 4 Roles & Permissions
72 stars 25 forks source link

disablePermissions() doesn't do anything #44

Closed salmanhijazi closed 5 months ago

salmanhijazi commented 5 months ago

Hello,

I want to hide the permissions resource, but it is not working. I have tried with and without disableMenu().

public function tools()
    {
        return [
            (\Sereny\NovaPermissions\NovaPermissions::make()
                ->hideFieldsFromRole([
                    'id',
                    'guard_name'
                ])
                ->disableMenu()
                ->disablePermissions()
                ->resolveGuardsUsing(function($request) {
                    return [ 'web' ];
                })
            )->canSee(function ($request) {
                return $request->user()->isSuperAdmin();
            }),
        ];
    }

Updating the disablePermissions function works if I update it to this:

public function disablePermissions()
    {
        $this->permissionResource::$displayInNavigation = false;
        return $this;
    }

Although, the naming of this function is misleading, probably worth renaming it to "hidePermissionsFromSidebar"

Thank you!

leandrogehlen commented 5 months ago

Please take a moment https://github.com/serenysoft/nova-permissions/issues/38#issuecomment-1964653109

salmanhijazi commented 5 months ago

That issue is marked as closed, does that mean it is already merged? Because, I have the latest version and it doesn't work.

Here's my code to make it work:

public function disablePermissions()
    {
        $this->displayPermissions = false;
        $this->permissionResource::$displayInNavigation = false;
        return $this;
    }

    public function disableMenu()
    {
        $this->menuDisabled = true;
        $this->roleResource::$displayInNavigation = $this->menuDisabled;
        $this->permissionResource::$displayInNavigation = !$this->displayPermissions ? $this->displayPermissions : $this->menuDisabled;
        return $this;
    }

    public function menu(Request $request)
    {
        if ($this->menuDisabled) {
            return [];
        }

        return MenuSection::make(__('Roles'. ($this->displayPermissions ? ' & Permissions' : '')), [
            $this->createMenuItem($this->roleResource),
            $this->displayPermissions ? $this->createMenuItem($this->permissionResource) : ''
        ])->icon('shield-check')->collapsable();
    }
leandrogehlen commented 5 months ago

Please make a PR

leandrogehlen commented 5 months ago

ref 4a30855e57ada9e058602451d8c191cfd711df31