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.

Home Page:https://filamentphp.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Excessive Gate Checks against Tenants in Tenant Menu

tonypartridge opened this issue · comments

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

  • You can donate funding to this issue. We receive the money once the issue is completed & confirmed by you.
  • 100% of the funding will be distributed between the Filament core team to run all aspects of the project.
  • Thank you in advance for helping us make maintenance sustainable!
Fund with Polar

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.