collapsible-resource-manager
collapsible-resource-manager copied to clipboard
Hide TopLevelResource label and icon when all resources in the group hidden
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?
same issue here
A posible workarround is to use ->cansee method for TopLevel element.
Can confirm the existence of this bug.
In our case it only shows itself the TopLevelResource
has an empty Group
inside of it.
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')),
I solve the empty space in groups, using a CSS class.
.leading-tight:empty { display: none; }
This issue is no longer present on the latest version v2.0.0