Skip to content

Commit a753296

Browse files
simonhampclaude
andcommitted
Fix "selected user is invalid" when granting bundle to user with null name
Filament's Select uses getOptionLabelUsing to validate the chosen value; returning a blank label causes the "in" rule to reject it. The bundle grant action returned `User->name`, which is null for some users. Use `getFilamentName()` so the label falls back through display_name, name, then email, ensuring a non-blank result for any existing user. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent d00591c commit a753296

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

app/Filament/Resources/PluginBundleResource.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,10 @@ public static function table(Table $table): Table
189189
->orWhere('email', 'like', "%{$search}%")
190190
->limit(50)
191191
->get()
192-
->mapWithKeys(fn (User $user) => [$user->id => "{$user->name} ({$user->email})"])
192+
->mapWithKeys(fn (User $user) => [$user->id => "{$user->getFilamentName()} ({$user->email})"])
193193
->toArray();
194194
})
195-
->getOptionLabelUsing(fn ($value): ?string => User::find($value)?->name)
195+
->getOptionLabelUsing(fn ($value): ?string => User::find($value)?->getFilamentName())
196196
->required(),
197197
])
198198
->action(function (PluginBundle $record, array $data): void {

tests/Feature/Filament/GrantBundleToUserActionTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,25 @@ public function test_grant_to_user_action_can_be_called_with_user_id(): void
5151
]);
5252
}
5353
}
54+
55+
public function test_grant_to_user_action_works_for_user_with_null_name(): void
56+
{
57+
$recipient = User::factory()->create(['name' => null]);
58+
$plugins = Plugin::factory()->count(1)->approved()->create();
59+
$this->bundle->plugins()->attach($plugins->pluck('id'));
60+
61+
Livewire::actingAs($this->admin)
62+
->test(ListPluginBundles::class)
63+
->callAction(
64+
TestAction::make('grantToUser')->table($this->bundle),
65+
data: ['user_id' => $recipient->id],
66+
)
67+
->assertHasNoFormErrors();
68+
69+
$this->assertDatabaseHas('plugin_licenses', [
70+
'user_id' => $recipient->id,
71+
'plugin_id' => $plugins->first()->id,
72+
'plugin_bundle_id' => $this->bundle->id,
73+
]);
74+
}
5475
}

0 commit comments

Comments
 (0)