filamentphp / filament

A collection of beautiful full-stack components for Laravel. The perfect starting point for your next app. Using Livewire, Alpine.js and Tailwind CSS.
https://filamentphp.com
MIT License
17.48k stars 2.73k forks source link

Excessive Gate Checks against Tenants in Tenant Menu #13290

Open tonypartridge opened 2 months ago

tonypartridge commented 2 months ago

Package

filament/filament

Package Version

v3.2.91

Laravel Version

10.48.12

Livewire Version

3.5.0

PHP Version

8.3.8

Problem description

When enabling tenancy and the tenancy menu, the gate checks multiply by the amount of tenants + 1 additional tenant. In that the loaded tenants are being tested for what resources that tenant can access. To replicate, just add a policy against any resource and that policy is checked against every tenant in the tenant menu. In my instance, I've gone from 66 gate checks to 3306 gate checks by enabling the tenancy.

Expected behavior

The tenant gate checks should only be happening against the current active tenant, we have returned the results of tenants already which are limited to the current user and as such the resource checks should not be done of the tenants in the tenant menu.

Steps to reproduce

Add tenancy, add a Policy to a model, this will show X checks, add a tenant and you'll see the checks multiply, add another tenant and they increase again.

Reproduction repository (issue will be closed if this is not valid)

https://github.com/tonypartridge/filament-demo/tree/main

Relevant log output

No response

Donate 💰 to fund this issue

Fund with Polar

tonypartridge commented 2 months ago

Issue is down to the tenant-menu.blade.php calling getUrl(). We need a new tenancy method 'getHomeUrl' or 'getTenantUrl' which returns the standard path generated for urls of the current tenant to avoid the excessive checks and the routing can be done on accessing the panel.