Skip to content

Commit

Permalink
fix: remove profile & fix mappings for related
Browse files Browse the repository at this point in the history
  • Loading branch information
phpsa committed Nov 30, 2023
1 parent cb54d84 commit 1801ddf
Show file tree
Hide file tree
Showing 13 changed files with 78 additions and 215 deletions.
56 changes: 28 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,28 @@ artisan vendor:publish --tag=filament-authentication-views
artisan vendor:publish --tag=filament-authentication-translations
```


in the panel file you are using: you will need to do the follwing:

1) add the resources
```php
public function panel(Panel $panel): Panel
{
return $panel
->default()
->id('admin')
->path('/admin')
...
->profile() //to publish filaments one :-)
->resources(
FilamentAuthentication::resources()
)
->widgets([
...
LatestUsersWidget::make(['limit' => 5, 'paginate' => true])
```


## Additional Resources:
### Spatie Roles & Permissions
If you have not yet configured this package it is automatically added by this installer, run the following steps:
Expand Down Expand Up @@ -76,37 +98,15 @@ We have a Custom Page Trait: `Phpsa\FilamentAuthentication\Traits\PagePolicyTrai
By defining a model and mapping it with a `viewAny($user)` method you can define per policies whether or not to show the page in navigation.

## Widgets
`LatestUsersWidget` is by default published to your dashboard, this can be configured / disabled by editing the config in the filament-authentication config file:
```php
'Widgets' => [
'LatesetUsers' => [
'enabled' => true,
'limit' => 5,
],
],
`LatestUsersWidget` can be added to your dashboard by adding it to your panel widgets area..
```
LatestUsersWidget::class
or
LatestUsersWidget::make(['limit' => 5, 'paginate' => true])
```

Note that it is also attached to the UserPolicy::viewAny policy value if the policy exists

--It is planned to update the enabled to accept a callback function to allow for roles etc in the next version--

## Profile
Profile view for currently authed user

## Extending
Extend Profile:
```php
<?php

namespace App\Filament\Pages;

use Filament\Pages\Page;
use Phpsa\FilamentAuthentication\Pages\Profile as PagesProfile;

class Profile extends PagesProfile
{}
```
or the view: `resources/views/vendor/filament-authentication/filament/pages/profile.blade.php` (you can publish existing one)


## Events
Expand All @@ -118,8 +118,8 @@ or the view: `resources/views/vendor/filament-authentication/filament/pages/prof
## Intergration with other packages:
** Comming soon **

- https://filamentphp.com/plugins/socialite
- https://filamentphp.com/plugins/2fa
- https://filamentphp.com/plugins/socialite

## Changelog

Expand Down
5 changes: 5 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
Upgrading V2 - V3

- Widget / panels no longer auto-published
- Profile screen removed in favour of Filaments default one

Breaking Change V1 - V2
*****

Expand Down
20 changes: 5 additions & 15 deletions config/filament-authentication.php
Original file line number Diff line number Diff line change
@@ -1,29 +1,19 @@
<?php

return [
'models' => [
'models' => [
'User' => \App\Models\User::class,
'Role' => \Spatie\Permission\Models\Role::class,
'Permission' => \Spatie\Permission\Models\Permission::class,
],
'resources' => [
'resources' => [
'UserResource' => \Phpsa\FilamentAuthentication\Resources\UserResource::class,
'RoleResource' => \Phpsa\FilamentAuthentication\Resources\RoleResource::class,
'PermissionResource' => \Phpsa\FilamentAuthentication\Resources\PermissionResource::class,
],
'pages' => [
'Profile' => \Phpsa\FilamentAuthentication\Pages\Profile::class
],
'Widgets' => [
'LatestUsers' => [
'enabled' => true,
'limit' => 5,
'sort' => 0,
'paginate' => false
],
],
'preload_roles' => true,
'impersonate' => [
'preload_roles' => true,
'preload_permissions' => true,
'impersonate' => [
'enabled' => true,
'guard' => 'web',
'redirect' => '/'
Expand Down
3 changes: 3 additions & 0 deletions resources/lang/en/filament-authentication.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,7 @@
'button.impersonate' => "Impersonate User",
'text.impersonating' => 'Impersonating User: ',
'text.impersonating.end' => ' - End Impersonation ',

'text.profile' => 'Profile',

];
16 changes: 0 additions & 16 deletions resources/views/filament/pages/profile.blade.php

This file was deleted.

17 changes: 17 additions & 0 deletions src/FilamentAuthentication.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Phpsa\FilamentAuthentication;

use Filament\Navigation\MenuItem;
use Filament\Panel;

class FilamentAuthentication
{
public static function resources(array $with = []): array
{
return array_merge(
config('filament-authentication.resources'),
$with
);
}
}
7 changes: 1 addition & 6 deletions src/FilamentAuthenticationProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,8 @@ public function getPages(): array
return config('filament-authentication.pages');
}

protected function registerMacros(): void
public function packageRegistered(): void
{
Filament::serving(function () {
Filament::registerUserMenuItems([
'account' => UserMenuItem::make()->url(route('filament.pages.profile')),
]);
});

TextColumn::macro('humanDate', function () {
/** @var \Filament\Tables\Columns\TextColumn&\Filament\Tables\Columns\Concerns\CanFormatState $this */
Expand Down
133 changes: 0 additions & 133 deletions src/Pages/Profile.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ public function table(Table $table): Table
])
->headerActions([
CreateAction::make(),
AttachAction::make(),
AttachAction::make()->preloadRecordSelect(config('filament-authentication.preload_roles', true))
->recordSelect(fn($select) => $select->multiple())
->closeModalByClickingAway(false),
])
->actions([
DetachAction::make()
Expand Down
1 change: 0 additions & 1 deletion src/Resources/RoleResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use Filament\Tables\Filters\SelectFilter;
use Filament\Tables\Actions\DeleteBulkAction;
use Filament\Forms\Components\Section as Card;
use Filament\Forms\Components\BelongsToManyMultiSelect;
use Phpsa\FilamentAuthentication\Resources\RoleResource\Pages\EditRole;
use Phpsa\FilamentAuthentication\Resources\RoleResource\Pages\ViewRole;
use Phpsa\FilamentAuthentication\Resources\RoleResource\Pages\ListRoles;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
use Filament\Tables\Actions\AttachAction;
use Filament\Tables\Actions\DetachAction;
use Spatie\Permission\PermissionRegistrar;
use Filament\Tables\Actions\DissociateBulkAction;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Tables\Actions\CreateAction;
use Filament\Tables\Actions\DetachBulkAction;

class PermissionRelationManager extends RelationManager
{
Expand Down Expand Up @@ -47,15 +47,18 @@ public function table(Table $table): Table
])
->headerActions([
CreateAction::make(),
AttachAction::make(),
AttachAction::make()
->preloadRecordSelect(config('filament-authentication.preload_permissions', true))
->recordSelect(fn($select) => $select->multiple())
->closeModalByClickingAway(false),
])
->actions([
DetachAction::make()
])

->bulkActions([

DissociateBulkAction::make(),
DetachBulkAction::make(),

]);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/UserResource/Pages/ViewUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected function impersonateAction(): ?Action
$record = $this->getRecord();
$user = Filament::auth()->user();
if ($user === null || ImpersonateLink::allowed($user, $record) === false) {
throw null;
return null;
}

return Action::make('impersonate')
Expand Down
Loading

0 comments on commit 1801ddf

Please sign in to comment.