collapsible-resource-manager icon indicating copy to clipboard operation
collapsible-resource-manager copied to clipboard

Hide TopLevelResource label and icon when all resources in the group hidden

Open ITango opened this issue 4 years ago • 5 comments

I'm using permissions to show/hide resources to users. Sometimes, it happens that a given user is not allowed to see all the resources in the group(s) under one of the TopLevel menus.

I am able to hide all the resources, however, the label and icon of the TopLevelResource as still visible, as on the attached screenshot.

Is it possible to hide the TopLevelResource menu in those cases? Screen Shot 2020-03-26 at 2 26 14 pm

ITango avatar Mar 26 '20 05:03 ITango

same issue here

cord avatar Jun 18 '20 06:06 cord

A posible workarround is to use ->cansee method for TopLevel element.

omarmatijas avatar Mar 24 '21 16:03 omarmatijas

Can confirm the existence of this bug. In our case it only shows itself the TopLevelResource has an empty Group inside of it.

blackfyre avatar Jul 12 '21 08:07 blackfyre

Same issue here. As comment @omarmatijas a posible workaround is using canSee method. Please see and quick and dirty example bellow. Hope that can help.

Note that I'm using Spatie Permissions and my permissions scheme has a structure like {module}.{submodule}.{[*,view,viewAny,create,update,delete]} so I can match using regex.

Please feel free to optimize it and give me your feedback. The only way I found to get it working is returning closure but might be possible to achieve the same in a more elegant way.

Moreover It's probably interesting to add some cache mechanism to improve performance.

Add this method to your Provider

    public static function canSeeHandler($name) {
        $user = auth()->user();

        if ($user->hasRole('super-admin')) {
            return function($request) { return true; };
        }

        $permissions = $user->getAllPermissions()->pluck('name');
        $filtered = $permissions->filter(function ($value, $key) use ($name) {
            return preg_match('/^'.$name.'/', $value);
        });

        $count = $filtered->count();
        return function($request) use ($count) { return $count; };
    }

And use it with colapsible resource manager as this

Group::make([
   ...
])
->canSee(self::canSeeHandler('servicedesk.ticket')),

scramatte avatar Oct 31 '21 23:10 scramatte

I solve the empty space in groups, using a CSS class.

.leading-tight:empty { display: none; }

cerobox avatar Dec 29 '21 11:12 cerobox

This issue is no longer present on the latest version v2.0.0

milewski avatar Oct 07 '23 06:10 milewski