Skip to content

Commit

Permalink
fix: user filament access
Browse files Browse the repository at this point in the history
  • Loading branch information
AndyTWF committed Apr 22, 2024
1 parent ffe8588 commit 3c25709
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/Models/User/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public function dependencies(): BelongsToMany

public function canAccessPanel(\Filament\Panel $panel): bool
{
return true;
return $panel->getId() === 'admin';
}

public function getFilamentName(): string
Expand Down
11 changes: 9 additions & 2 deletions tests/app/Models/User/UserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use App\BaseFunctionalTestCase;
use Carbon\Carbon;
use App\Providers\AuthServiceProvider;
use Filament\Facades\Filament;
use Filament\Panel;
use Illuminate\Database\Eloquent\Collection;
use TestingUtils\Traits\WithSeedUsers;

Expand Down Expand Up @@ -62,9 +64,14 @@ public function testItCanBeSerializedToJson()
$this->assertEquals($token, $jsonData['tokens']->first()->id);
}

public function testItCanAccessFilament()
public function testItCanAccessDefaultFilamentPanel()
{
$this->assertTrue((new User(['id' => 1234]))->canAccessFilament());
$this->assertTrue((new User(['id' => 1234]))->canAccessPanel(Filament::getPanel('admin')));
}

public function testItCantAccessOtherFilamentPanels()
{
$this->assertFalse((new User(['id' => 1234]))->canAccessPanel(Panel::make()->id('foo')));
}

public function testItHasAFilamentName()
Expand Down

0 comments on commit 3c25709

Please sign in to comment.