filament-breezy icon indicating copy to clipboard operation
filament-breezy copied to clipboard

allow modification of sanctum permissions in tenantMiddleware()

Open eelco2k opened this issue 11 months ago • 0 comments

At this moment you can only set the sanctum permissions on plugin initialization (by my knowledge).

In my case i have some middlewares for each tenant and there the abilities change of the users.

Is there any other way of setting the abilities later on? now i've done it like this in my tenantMiddleware() of a panel:


function array_values_recursive(array $array): array
{
    $flat = array();

    foreach ($array as $value) {
        if (is_array($value)) {
            $flat = array_merge($flat, array_values_recursive($value));
        } else {
            $flat[] = $value;
        }
    }
    return $flat;
}

$apiplugin = Filament::getCurrentPanel()->getPlugin('api-service');   // https://filamentphp.com/plugins/rupadana-api-service
$abilities = $apiplugin->getAbilities(Filament::getCurrentPanel()); // gets all resources with their abilities

$abilities = array_values_recursive($abilities);

$breezyplugin = Filament::getCurrentPanel()->getPlugin('filament-breezy');
$breezyplugin->enableSanctumTokens(true, $abilities);      

so getting the plugin and then enableSanctumTokens() function...

eelco2k avatar Mar 13 '24 14:03 eelco2k