Skip to content

Commit 61a1bc2

Browse files
simonhampclaude
andcommitted
Remove admin plugin links and hide grant action for free plugins
- Remove "View on GitHub" and "View on Packagist" actions from the edit page menu - Hide "Grant to User" action for free plugins on both list and edit pages - Add tests for grant action visibility Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 8c12845 commit 61a1bc2

4 files changed

Lines changed: 65 additions & 18 deletions

File tree

app/Filament/Resources/PluginResource.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ public static function table(Table $table): Table
371371
->label('Grant to User')
372372
->icon('heroicon-o-gift')
373373
->color('success')
374+
->visible(fn (Plugin $record): bool => ! $record->isFree())
374375
->form([
375376
Forms\Components\Select::make('user_id')
376377
->label('User')

app/Filament/Resources/PluginResource/Pages/EditPlugin.php

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ protected function getHeaderActions(): array
106106
->label('Grant to User')
107107
->icon('heroicon-o-gift')
108108
->color('success')
109-
->visible(fn () => $this->record->isApproved())
109+
->visible(fn () => $this->record->isApproved() && ! $this->record->isFree())
110110
->form([
111111
Forms\Components\Select::make('user_id')
112112
->label('User')
@@ -159,14 +159,6 @@ protected function getHeaderActions(): array
159159
->modalDescription(fn () => "Grant '{$this->record->name}' to a user for free.")
160160
->modalSubmitActionLabel('Grant'),
161161

162-
Actions\Action::make('viewPackagist')
163-
->label('View on Packagist')
164-
->icon('heroicon-o-arrow-top-right-on-square')
165-
->color('gray')
166-
->url(fn () => $this->record->getPackagistUrl())
167-
->openUrlInNewTab()
168-
->visible(fn () => $this->record->isFree()),
169-
170162
Actions\Action::make('runReviewChecks')
171163
->label('Run Review Checks')
172164
->icon('heroicon-o-clipboard-document-check')
@@ -245,14 +237,6 @@ protected function getHeaderActions(): array
245237
->send();
246238
}),
247239

248-
Actions\Action::make('viewGithub')
249-
->label('View on GitHub')
250-
->icon('heroicon-o-arrow-top-right-on-square')
251-
->color('gray')
252-
->visible(fn () => $this->record->repository_url !== null)
253-
->url(fn () => $this->record->getGithubUrl())
254-
->openUrlInNewTab(),
255-
256240
Actions\Action::make('viewListing')
257241
->label('View Listing Page')
258242
->icon('heroicon-o-eye')

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
3+
namespace Tests\Feature\Filament;
4+
5+
use App\Filament\Resources\PluginResource\Pages\EditPlugin;
6+
use App\Filament\Resources\PluginResource\Pages\ListPlugins;
7+
use App\Models\Plugin;
8+
use App\Models\User;
9+
use Illuminate\Foundation\Testing\RefreshDatabase;
10+
use Livewire\Livewire;
11+
use Tests\TestCase;
12+
13+
class GrantPluginToUserActionTest extends TestCase
14+
{
15+
use RefreshDatabase;
16+
17+
private User $admin;
18+
19+
protected function setUp(): void
20+
{
21+
parent::setUp();
22+
23+
$this->admin = User::factory()->create(['email' => 'admin@test.com']);
24+
config(['filament.users' => ['admin@test.com']]);
25+
}
26+
27+
public function test_grant_to_user_action_is_hidden_for_free_plugins_on_list(): void
28+
{
29+
$plugin = Plugin::factory()->free()->approved()->create();
30+
31+
Livewire::actingAs($this->admin)
32+
->test(ListPlugins::class)
33+
->assertTableActionHidden('grantToUser', $plugin);
34+
}
35+
36+
public function test_grant_to_user_action_is_visible_for_paid_plugins_on_list(): void
37+
{
38+
$plugin = Plugin::factory()->paid()->approved()->create();
39+
40+
Livewire::actingAs($this->admin)
41+
->test(ListPlugins::class)
42+
->assertTableActionVisible('grantToUser', $plugin);
43+
}
44+
45+
public function test_grant_to_user_action_is_hidden_for_free_plugins_on_edit(): void
46+
{
47+
$plugin = Plugin::factory()->free()->approved()->create();
48+
49+
Livewire::actingAs($this->admin)
50+
->test(EditPlugin::class, ['record' => $plugin->getRouteKey()])
51+
->assertActionHidden('grantToUser');
52+
}
53+
54+
public function test_grant_to_user_action_is_visible_for_paid_plugins_on_edit(): void
55+
{
56+
$plugin = Plugin::factory()->paid()->approved()->create();
57+
58+
Livewire::actingAs($this->admin)
59+
->test(EditPlugin::class, ['record' => $plugin->getRouteKey()])
60+
->assertActionVisible('grantToUser');
61+
}
62+
}

0 commit comments

Comments
 (0)