Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
andreiio committed Mar 7, 2024
1 parent 9b2ef47 commit be5adb0
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 10 deletions.
12 changes: 12 additions & 0 deletions app/Filament/Pages/Auth/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Filament\Pages\Auth;

use Filament\Forms\Components\Hidden;
use Filament\Forms\Components\TextInput;
use JeffGreco13\FilamentBreezy\Pages\MyProfile;

Expand Down Expand Up @@ -41,4 +42,15 @@ protected function getUpdateProfileFormSchema(): array
->label(__('user.field.email')),
];
}

protected function getCreateApiTokenFormSchema(): array
{
return [
TextInput::make('token_name')
->label(__('filament-breezy::default.fields.token_name'))
->required(),

Hidden::make('abilities'),
];
}
}
5 changes: 4 additions & 1 deletion app/Http/Controllers/OrganisationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@

use App\Http\Resources\OrganisationResource;
use App\Models\Organisation;
use Illuminate\Http\Resources\Json\JsonResource;

class OrganisationController extends Controller
{
public function __invoke()
public function __invoke(): JsonResource
{
$this->authorize('accessApi');

return OrganisationResource::collection(
Organisation::query()
->withoutEagerLoads(['city'])
Expand Down
5 changes: 4 additions & 1 deletion app/Http/Controllers/ResourceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@

use App\Http\Resources\ResourceResource;
use App\Models\Resource;
use Illuminate\Http\Resources\Json\JsonResource;

class ResourceController extends Controller
{
public function __invoke()
public function __invoke(): JsonResource
{
$this->authorize('accessApi');

return ResourceResource::collection(
Resource::query()
->with([
Expand Down
6 changes: 0 additions & 6 deletions app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace App\Providers;

use App\Filament\Pages\Auth\Settings;
use App\Models\User;
use Carbon\Carbon;
use Dedoc\Scramble\Scramble;
use Dedoc\Scramble\Support\Generator\OpenApi;
Expand All @@ -14,7 +13,6 @@
use Filament\Navigation\UserMenuItem;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
Expand Down Expand Up @@ -58,10 +56,6 @@ public function boot()
]);
});

Gate::define('viewApiDocs', function (User $user) {
return $user->canAccessFilament() && $user->isPlatformAdmin();
});

Scramble::extendOpenApi(function (OpenApi $openApi) {
$openApi->secure(
SecurityScheme::http('bearer', 'JWT')
Expand Down
10 changes: 10 additions & 0 deletions app/Providers/AuthServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

namespace App\Providers;

use App\Models\User;
use Illuminate\Auth\EloquentUserProvider;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Gate;

class AuthServiceProvider extends ServiceProvider
{
Expand All @@ -33,5 +35,13 @@ public function boot()
return (new EloquentUserProvider($app['hash'], $config['model']))
->withQuery(fn (Builder $query) => $query->withoutGlobalScopes());
});

Gate::define('accessApi', function (User $user) {
if (! config('filament-breezy.enable_sanctum')) {
return false;
}

return $user->isPlatformAdmin();
});
}
}
4 changes: 3 additions & 1 deletion config/filament-breezy.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,5 +117,7 @@
|--------------------------------------------------------------------------
| Sanctum permissions
*/
'sanctum_permissions' => ['create', 'read', 'update', 'delete'],
'sanctum_permissions' => [
// 'create', 'read', 'update', 'delete',
],
];
2 changes: 1 addition & 1 deletion config/scramble.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@

'middleware' => [
'web',
RestrictedDocsAccess::class,
// RestrictedDocsAccess::class,
],

'extensions' => [],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<x-filament::page>

<x-filament-breezy::sections.personal-info />

<x-filament::hr />

<x-filament-breezy::sections.passwords />

@if (config('filament-breezy.enable_2fa'))
<x-filament::hr />

<x-filament-breezy::sections.2fa />
@endif

@can('accessApi')
<x-filament::hr />

<x-filament-breezy::grid-section class="mt-8">

<x-slot name="title">
{{ __('filament-breezy::default.profile.sanctum.title') }}
</x-slot>

<x-slot name="description">
{{ __('filament-breezy::default.profile.sanctum.description') }}
</x-slot>

<div class="space-y-3">

<form wire:submit.prevent="createApiToken" class="col-span-2 mt-5 sm:col-span-1 md:mt-0">

<x-filament::card>
@if ($plain_text_token)
<input type="text" disabled @class([
'w-full py-1 px-3 rounded-lg bg-gray-100 border-gray-200',
' dark:bg-gray-900 dark:border-gray-700' => config('filament.dark_mode'),
]) name="plain_text_token"
value="{{ $plain_text_token }}" />
@endif

{{ $this->createApiTokenForm }}

<div class="text-right">
<x-filament::button type="submit" form="createApiToken">
{{ __('filament-breezy::default.profile.sanctum.create.submit.label') }}
</x-filament::button>
</div>
</x-filament::card>
</form>

<x-filament::hr />

@livewire(\JeffGreco13\FilamentBreezy\Http\Livewire\BreezySanctumTokens::class)

</div>
</x-filament-breezy::grid-section>
@endcan

</x-filament::page>

0 comments on commit be5adb0

Please sign in to comment.