Policy being ignored with custom button on ListPage
In Filament 3 I have a ReceiptPolicy that restricts a Staff user from adding a receipt record. The policy works apart from the fact that the Staff account stills has the ability to add receipts as the button is still available.
On the ListReceipt page there is an action that is used to change the title of the Add Receipt button slightly and this seems to be the offending item. When this is removed and the default button state of Add Receipt is back the Policy activates and removes the button from the Staff account. When the function is reintroduced to the page the Policy is ignored.
Is there a reason why this would happen as it seems bizarre that a simple label function can ignore a policy that is in place.
ReceiptPolicy
<?php
namespace App\Policies;
use App\Models\Receipt;
use App\Models\User;
class ReceiptPolicy
{
/**
* Determine whether the user can view any models.
*/
public function viewAny(User $user): bool
{
return $user->hasRole(['Administrator', 'Manager', 'Staff']);
}
/**
* Determine whether the user can view the model.
*/
public function view(User $user, Receipt $receipt): bool
{
return $user->hasRole(['Administrator', 'Manager', 'Staff']);
}
/**
* Determine whether the user can create models.
*/
public function create(User $user): bool
{
return $user->hasRole(['Administrator', 'Manager']);
}
/**
* Determine whether the user can update the model.
*/
public function update(User $user, Receipt $receipt): bool
{
return $user->hasRole('Administrator');
}
ListReceipts.php
protected function getHeaderActions(): array
{
return [
Actions\CreateAction::make()
->label('Create New Receipt'),
];
}
Please or to participate in this conversation.