From 809897085dbc2ecde100e3fa23febfb208c6245d Mon Sep 17 00:00:00 2001 From: Eliezer Margareten <46111162+emargareten@users.noreply.github.com> Date: Wed, 6 Nov 2024 14:03:52 +0200 Subject: [PATCH 1/2] Add backed enum for $abilities type --- packages/actions/src/Concerns/CanBeHidden.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/actions/src/Concerns/CanBeHidden.php b/packages/actions/src/Concerns/CanBeHidden.php index f11fc9661b..f93f7dc489 100644 --- a/packages/actions/src/Concerns/CanBeHidden.php +++ b/packages/actions/src/Concerns/CanBeHidden.php @@ -2,6 +2,7 @@ namespace Filament\Actions\Concerns; +use BackedEnum; use Closure; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Arr; @@ -20,6 +21,10 @@ trait CanBeHidden */ public function authorize(mixed $abilities, Model | string | array | null $arguments = null): static { + if ($abilities instanceof BackedEnum) { + $abilities = $abilities->value; + } + if (is_string($abilities) || is_array($abilities)) { $this->authorization = [ 'type' => 'all', @@ -34,11 +39,15 @@ public function authorize(mixed $abilities, Model | string | array | null $argum } /** - * @param string | array $abilities + * @param string | array | BackedEnum $abilities * @param Model | array | null $arguments */ - public function authorizeAny(string | array $abilities, Model | array | null $arguments = null): static + public function authorizeAny(string | array | BackedEnum $abilities, Model | array | null $arguments = null): static { + if ($abilities instanceof BackedEnum) { + $abilities = $abilities->value; + } + $this->authorization = [ 'type' => 'any', 'abilities' => Arr::wrap($abilities), From 87a489e9be73e7449730ad8274b4cd9331b248f9 Mon Sep 17 00:00:00 2001 From: Dan Harrin Date: Thu, 7 Nov 2024 08:14:02 +0000 Subject: [PATCH 2/2] Update CanBeHidden.php --- packages/actions/src/Concerns/CanBeHidden.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/actions/src/Concerns/CanBeHidden.php b/packages/actions/src/Concerns/CanBeHidden.php index f93f7dc489..5b8e9bab86 100644 --- a/packages/actions/src/Concerns/CanBeHidden.php +++ b/packages/actions/src/Concerns/CanBeHidden.php @@ -39,10 +39,10 @@ public function authorize(mixed $abilities, Model | string | array | null $argum } /** - * @param string | array | BackedEnum $abilities + * @param string | BackedEnum | array $abilities * @param Model | array | null $arguments */ - public function authorizeAny(string | array | BackedEnum $abilities, Model | array | null $arguments = null): static + public function authorizeAny(string | BackedEnum | array $abilities, Model | array | null $arguments = null): static { if ($abilities instanceof BackedEnum) { $abilities = $abilities->value;