diff --git a/app/Filament/Resources/Achievements/AchievementResource.php b/app/Filament/Resources/Achievements/AchievementResource.php index 628ccd9..e993c5f 100644 --- a/app/Filament/Resources/Achievements/AchievementResource.php +++ b/app/Filament/Resources/Achievements/AchievementResource.php @@ -2,10 +2,8 @@ namespace App\Filament\Resources\Achievements; -use App\Filament\Resources\Achievements\Pages\CreateAchievement; -use App\Filament\Resources\Achievements\Pages\EditAchievement; use App\Filament\Resources\Achievements\Pages\ListAchievements; -use App\Filament\Resources\Achievements\Schemas\AchievementForm; +use App\Filament\Resources\Achievements\Schemas\AchievementInfolist; use App\Filament\Resources\Achievements\Tables\AchievementsTable; use BackedEnum; use Filament\Resources\Resource; @@ -13,16 +11,32 @@ use Filament\Schemas\Schema; use Filament\Support\Icons\Heroicon; use Filament\Tables\Table; use Functional\Streaks\Models\Achievement; +use Illuminate\Database\Eloquent\Model; +use UnitEnum; +/** + * Badges débloqués par StreakService aux paliers de streak — consultation + suppression + * uniquement, jamais de création/édition manuelle depuis le back-office. + */ class AchievementResource extends Resource { protected static ?string $model = Achievement::class; - protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedRectangleStack; + protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedTrophy; - public static function form(Schema $schema): Schema + protected static string|UnitEnum|null $navigationGroup = 'Gamification'; + + protected static ?int $navigationSort = 2; + + protected static ?string $modelLabel = 'badge'; + + protected static ?string $pluralModelLabel = 'badges'; + + protected static ?string $recordTitleAttribute = 'key'; + + public static function infolist(Schema $schema): Schema { - return AchievementForm::configure($schema); + return AchievementInfolist::configure($schema); } public static function table(Table $table): Table @@ -30,19 +44,28 @@ class AchievementResource extends Resource return AchievementsTable::configure($table); } - public static function getRelations(): array + public static function canCreate(): bool { - return [ - // - ]; + return false; + } + + public static function canEdit(Model $record): bool + { + return false; + } + + /** + * @return array + */ + public static function getGloballySearchableAttributes(): array + { + return ['key', 'user.name']; } public static function getPages(): array { return [ 'index' => ListAchievements::route('/'), - 'create' => CreateAchievement::route('/create'), - 'edit' => EditAchievement::route('/{record}/edit'), ]; } } diff --git a/app/Filament/Resources/Achievements/Pages/CreateAchievement.php b/app/Filament/Resources/Achievements/Pages/CreateAchievement.php deleted file mode 100644 index f0a4bce..0000000 --- a/app/Filament/Resources/Achievements/Pages/CreateAchievement.php +++ /dev/null @@ -1,11 +0,0 @@ -components([ - Select::make('user_id') - ->relationship('user', 'name') - ->required(), - TextInput::make('key') - ->required(), - DateTimePicker::make('earned_at') - ->required(), - TextInput::make('meta'), - ]); - } -} diff --git a/app/Filament/Resources/Achievements/Schemas/AchievementInfolist.php b/app/Filament/Resources/Achievements/Schemas/AchievementInfolist.php new file mode 100644 index 0000000..17e0a9f --- /dev/null +++ b/app/Filament/Resources/Achievements/Schemas/AchievementInfolist.php @@ -0,0 +1,32 @@ +components([ + TextEntry::make('user.name') + ->label('Utilisateur'), + TextEntry::make('key') + ->label('Badge') + ->badge(), + TextEntry::make('earned_at') + ->label('Obtenu le') + ->dateTime(), + TextEntry::make('meta') + ->label('Métadonnées') + ->columnSpanFull() + ->placeholder('—'), + ]); + } +} diff --git a/app/Filament/Resources/Achievements/Tables/AchievementsTable.php b/app/Filament/Resources/Achievements/Tables/AchievementsTable.php index ec1f51a..0ed10cd 100644 --- a/app/Filament/Resources/Achievements/Tables/AchievementsTable.php +++ b/app/Filament/Resources/Achievements/Tables/AchievementsTable.php @@ -3,13 +3,18 @@ namespace App\Filament\Resources\Achievements\Tables; use Filament\Actions\BulkActionGroup; +use Filament\Actions\DeleteAction; use Filament\Actions\DeleteBulkAction; -use Filament\Actions\EditAction; +use Filament\Actions\ViewAction; +use Filament\Forms\Components\DatePicker; use Filament\Tables\Columns\TextColumn; +use Filament\Tables\Filters\Filter; use Filament\Tables\Table; +use Illuminate\Database\Eloquent\Builder; /** * Table des badges débloqués : utilisateur, clé du badge, date d'obtention. + * Lecture seule + suppression : posé par StreakService, jamais créé/édité ici. */ class AchievementsTable { @@ -24,14 +29,29 @@ class AchievementsTable TextColumn::make('key') ->label('Badge') ->badge() - ->searchable(), + ->searchable() + ->sortable(), TextColumn::make('earned_at') ->label('Obtenu le') ->dateTime() ->sortable(), ]) + ->filters([ + Filter::make('earned_at') + ->label('Période') + ->schema([ + DatePicker::make('from')->label('Du'), + DatePicker::make('until')->label('Au'), + ]) + ->query(function (Builder $query, array $data): Builder { + return $query + ->when($data['from'] ?? null, fn (Builder $q, string $date): Builder => $q->whereDate('earned_at', '>=', $date)) + ->when($data['until'] ?? null, fn (Builder $q, string $date): Builder => $q->whereDate('earned_at', '<=', $date)); + }), + ]) ->recordActions([ - EditAction::make(), + ViewAction::make(), + DeleteAction::make(), ]) ->toolbarActions([ BulkActionGroup::make([ diff --git a/app/Filament/Resources/Exercises/ExerciseResource.php b/app/Filament/Resources/Exercises/ExerciseResource.php index 8feb4ff..34aa138 100644 --- a/app/Filament/Resources/Exercises/ExerciseResource.php +++ b/app/Filament/Resources/Exercises/ExerciseResource.php @@ -25,6 +25,8 @@ class ExerciseResource extends Resource protected static string|UnitEnum|null $navigationGroup = 'Catalogue'; + protected static ?int $navigationSort = 1; + protected static ?string $modelLabel = 'exercice'; protected static ?string $pluralModelLabel = 'exercices'; @@ -47,6 +49,14 @@ class ExerciseResource extends Resource return false; } + /** + * @return array + */ + public static function getGloballySearchableAttributes(): array + { + return ['name', 'category', 'body_part', 'target']; + } + public static function getPages(): array { return [ diff --git a/app/Filament/Resources/Exercises/Tables/ExercisesTable.php b/app/Filament/Resources/Exercises/Tables/ExercisesTable.php index d57a903..324963b 100644 --- a/app/Filament/Resources/Exercises/Tables/ExercisesTable.php +++ b/app/Filament/Resources/Exercises/Tables/ExercisesTable.php @@ -25,18 +25,28 @@ class ExercisesTable ->label('Nom') ->searchable() ->sortable(), + TextColumn::make('category') + ->label('Catégorie') + ->badge() + ->color('gray') + ->sortable() + ->toggleable(isToggledHiddenByDefault: true), TextColumn::make('body_part') ->label('Partie du corps') ->badge() ->sortable(), TextColumn::make('equipment') ->label('Équipement') - ->badge(), + ->badge() + ->toggleable(), TextColumn::make('target') ->label('Muscle cible') ->badge(), ]) ->filters([ + SelectFilter::make('category') + ->label('Catégorie') + ->options(fn (): array => self::distinctOptions('category')), SelectFilter::make('body_part') ->label('Partie du corps') ->options(fn (): array => self::distinctOptions('body_part')), diff --git a/app/Filament/Resources/Integrations/IntegrationResource.php b/app/Filament/Resources/Integrations/IntegrationResource.php index 8e94ab4..cf7b365 100644 --- a/app/Filament/Resources/Integrations/IntegrationResource.php +++ b/app/Filament/Resources/Integrations/IntegrationResource.php @@ -13,12 +13,21 @@ use Filament\Schemas\Schema; use Filament\Support\Icons\Heroicon; use Filament\Tables\Table; use Technical\Integrations\Models\Integration; +use UnitEnum; class IntegrationResource extends Resource { protected static ?string $model = Integration::class; - protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedRectangleStack; + protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedArrowsRightLeft; + + protected static string|UnitEnum|null $navigationGroup = 'Système'; + + protected static ?int $navigationSort = 1; + + protected static ?string $modelLabel = 'intégration'; + + protected static ?string $pluralModelLabel = 'intégrations'; public static function form(Schema $schema): Schema { @@ -37,6 +46,14 @@ class IntegrationResource extends Resource ]; } + /** + * @return array + */ + public static function getGloballySearchableAttributes(): array + { + return ['provider', 'external_user_id', 'user.name']; + } + public static function getPages(): array { return [ diff --git a/app/Filament/Resources/Integrations/Tables/IntegrationsTable.php b/app/Filament/Resources/Integrations/Tables/IntegrationsTable.php index 8aa6719..030a731 100644 --- a/app/Filament/Resources/Integrations/Tables/IntegrationsTable.php +++ b/app/Filament/Resources/Integrations/Tables/IntegrationsTable.php @@ -2,13 +2,17 @@ namespace App\Filament\Resources\Integrations\Tables; +use Filament\Actions\BulkAction; use Filament\Actions\BulkActionGroup; use Filament\Actions\DeleteBulkAction; use Filament\Actions\EditAction; +use Filament\Support\Icons\Heroicon; use Filament\Tables\Columns\TextColumn; use Filament\Tables\Filters\SelectFilter; use Filament\Tables\Table; +use Illuminate\Database\Eloquent\Collection; use Technical\Integrations\Enums\IntegrationStatus; +use Technical\Integrations\Models\Integration; /** * Table des intégrations externes : utilisateur, fournisseur, état, dernière synchro. @@ -27,7 +31,17 @@ class IntegrationsTable TextColumn::make('provider') ->label('Fournisseur') ->badge() - ->searchable(), + ->color(fn (string $state): string => match (strtolower($state)) { + 'strava' => 'danger', + 'garmin' => 'info', + default => 'gray', + }) + ->searchable() + ->sortable(), + TextColumn::make('external_user_id') + ->label('ID externe') + ->toggleable(isToggledHiddenByDefault: true) + ->placeholder('—'), TextColumn::make('status') ->label('État') ->badge() @@ -36,6 +50,11 @@ class IntegrationsTable IntegrationStatus::Revoked => 'gray', IntegrationStatus::Error => 'danger', }), + TextColumn::make('connected_at') + ->label('Connecté le') + ->dateTime() + ->sortable() + ->toggleable(isToggledHiddenByDefault: true), TextColumn::make('last_synced_at') ->label('Dernière synchro') ->dateTime() @@ -43,6 +62,9 @@ class IntegrationsTable ->placeholder('Jamais'), ]) ->filters([ + SelectFilter::make('provider') + ->label('Fournisseur') + ->options(fn (): array => self::distinctProviders()), SelectFilter::make('status') ->label('État') ->options(IntegrationStatus::class), @@ -53,8 +75,34 @@ class IntegrationsTable ->toolbarActions([ BulkActionGroup::make([ DeleteBulkAction::make(), + // Révocation groupée : coupe l'accès sans supprimer l'historique de connexion. + BulkAction::make('revoke') + ->label('Révoquer') + ->icon(Heroicon::OutlinedBoltSlash) + ->color('danger') + ->requiresConfirmation() + ->action(function (Collection $records): void { + $records->each(fn (Integration $integration) => $integration->update([ + 'status' => IntegrationStatus::Revoked, + ])); + }) + ->deselectRecordsAfterCompletion(), ]), ]) ->defaultSort('last_synced_at', 'desc'); } + + /** + * Valeurs distinctes de la colonne "provider" pour alimenter le filtre. + * + * @return array + */ + private static function distinctProviders(): array + { + return Integration::query() + ->distinct() + ->orderBy('provider') + ->pluck('provider', 'provider') + ->all(); + } } diff --git a/app/Filament/Resources/Programs/ProgramResource.php b/app/Filament/Resources/Programs/ProgramResource.php index 6601ef9..28a16c2 100644 --- a/app/Filament/Resources/Programs/ProgramResource.php +++ b/app/Filament/Resources/Programs/ProgramResource.php @@ -13,12 +13,23 @@ use Filament\Schemas\Schema; use Filament\Support\Icons\Heroicon; use Filament\Tables\Table; use Functional\Programs\Models\Program; +use UnitEnum; class ProgramResource extends Resource { protected static ?string $model = Program::class; - protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedRectangleStack; + protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedCalendarDays; + + protected static string|UnitEnum|null $navigationGroup = 'Entraînement'; + + protected static ?int $navigationSort = 2; + + protected static ?string $modelLabel = 'programme'; + + protected static ?string $pluralModelLabel = 'programmes'; + + protected static ?string $recordTitleAttribute = 'name'; public static function form(Schema $schema): Schema { @@ -37,6 +48,14 @@ class ProgramResource extends Resource ]; } + /** + * @return array + */ + public static function getGloballySearchableAttributes(): array + { + return ['name', 'slug', 'user.name']; + } + public static function getPages(): array { return [ diff --git a/app/Filament/Resources/Programs/Schemas/ProgramForm.php b/app/Filament/Resources/Programs/Schemas/ProgramForm.php index ba56238..af1c1f7 100644 --- a/app/Filament/Resources/Programs/Schemas/ProgramForm.php +++ b/app/Filament/Resources/Programs/Schemas/ProgramForm.php @@ -3,8 +3,8 @@ namespace App\Filament\Resources\Programs\Schemas; use Filament\Forms\Components\Select; -use Filament\Forms\Components\TextInput; use Filament\Forms\Components\Textarea; +use Filament\Forms\Components\TextInput; use Filament\Forms\Components\Toggle; use Filament\Schemas\Schema; diff --git a/app/Filament/Resources/Programs/Tables/ProgramsTable.php b/app/Filament/Resources/Programs/Tables/ProgramsTable.php index c8e1109..ed56391 100644 --- a/app/Filament/Resources/Programs/Tables/ProgramsTable.php +++ b/app/Filament/Resources/Programs/Tables/ProgramsTable.php @@ -7,6 +7,8 @@ use Filament\Actions\DeleteBulkAction; use Filament\Actions\EditAction; use Filament\Tables\Columns\IconColumn; use Filament\Tables\Columns\TextColumn; +use Filament\Tables\Filters\SelectFilter; +use Filament\Tables\Filters\TernaryFilter; use Filament\Tables\Table; /** @@ -30,6 +32,11 @@ class ProgramsTable ->label('Semaines') ->numeric() ->sortable(), + TextColumn::make('days_per_week') + ->label('Jours / semaine') + ->numeric() + ->sortable() + ->toggleable(isToggledHiddenByDefault: true), IconColumn::make('is_public') ->label('Public') ->boolean(), @@ -38,6 +45,16 @@ class ProgramsTable ->dateTime() ->sortable(), ]) + ->filters([ + TernaryFilter::make('is_public') + ->label('Visibilité') + ->trueLabel('Publics') + ->falseLabel('Privés'), + SelectFilter::make('user') + ->label('Utilisateur') + ->relationship('user', 'name') + ->searchable(), + ]) ->recordActions([ EditAction::make(), ]) diff --git a/app/Filament/Resources/Routines/RoutineResource.php b/app/Filament/Resources/Routines/RoutineResource.php index eeda793..772fc15 100644 --- a/app/Filament/Resources/Routines/RoutineResource.php +++ b/app/Filament/Resources/Routines/RoutineResource.php @@ -13,12 +13,23 @@ use Filament\Schemas\Schema; use Filament\Support\Icons\Heroicon; use Filament\Tables\Table; use Functional\Routines\Models\Routine; +use UnitEnum; class RoutineResource extends Resource { protected static ?string $model = Routine::class; - protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedRectangleStack; + protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedClipboardDocumentList; + + protected static string|UnitEnum|null $navigationGroup = 'Entraînement'; + + protected static ?int $navigationSort = 1; + + protected static ?string $modelLabel = 'routine'; + + protected static ?string $pluralModelLabel = 'routines'; + + protected static ?string $recordTitleAttribute = 'name'; public static function form(Schema $schema): Schema { @@ -37,6 +48,14 @@ class RoutineResource extends Resource ]; } + /** + * @return array + */ + public static function getGloballySearchableAttributes(): array + { + return ['name', 'slug', 'user.name']; + } + public static function getPages(): array { return [ diff --git a/app/Filament/Resources/Routines/Schemas/RoutineForm.php b/app/Filament/Resources/Routines/Schemas/RoutineForm.php index 3abc502..66d312f 100644 --- a/app/Filament/Resources/Routines/Schemas/RoutineForm.php +++ b/app/Filament/Resources/Routines/Schemas/RoutineForm.php @@ -3,8 +3,8 @@ namespace App\Filament\Resources\Routines\Schemas; use Filament\Forms\Components\Select; -use Filament\Forms\Components\TextInput; use Filament\Forms\Components\Textarea; +use Filament\Forms\Components\TextInput; use Filament\Forms\Components\Toggle; use Filament\Schemas\Schema; diff --git a/app/Filament/Resources/Routines/Tables/RoutinesTable.php b/app/Filament/Resources/Routines/Tables/RoutinesTable.php index e4f0bb0..52d2f66 100644 --- a/app/Filament/Resources/Routines/Tables/RoutinesTable.php +++ b/app/Filament/Resources/Routines/Tables/RoutinesTable.php @@ -7,6 +7,8 @@ use Filament\Actions\DeleteBulkAction; use Filament\Actions\EditAction; use Filament\Tables\Columns\IconColumn; use Filament\Tables\Columns\TextColumn; +use Filament\Tables\Filters\SelectFilter; +use Filament\Tables\Filters\TernaryFilter; use Filament\Tables\Table; /** @@ -26,6 +28,11 @@ class RoutinesTable ->label('Utilisateur') ->searchable() ->sortable(), + TextColumn::make('estimated_minutes') + ->label('Durée (min)') + ->numeric() + ->sortable() + ->toggleable(isToggledHiddenByDefault: true), IconColumn::make('is_public') ->label('Publique') ->boolean(), @@ -34,6 +41,16 @@ class RoutinesTable ->dateTime() ->sortable(), ]) + ->filters([ + TernaryFilter::make('is_public') + ->label('Visibilité') + ->trueLabel('Publiques') + ->falseLabel('Privées'), + SelectFilter::make('user') + ->label('Utilisateur') + ->relationship('user', 'name') + ->searchable(), + ]) ->recordActions([ EditAction::make(), ]) diff --git a/app/Filament/Resources/Streaks/Pages/CreateStreak.php b/app/Filament/Resources/Streaks/Pages/CreateStreak.php deleted file mode 100644 index feb4b63..0000000 --- a/app/Filament/Resources/Streaks/Pages/CreateStreak.php +++ /dev/null @@ -1,11 +0,0 @@ -components([ - Select::make('user_id') - ->relationship('user', 'name') - ->required(), - TextInput::make('current_count') - ->required() - ->numeric() - ->default(0), - TextInput::make('longest_count') - ->required() - ->numeric() - ->default(0), - DatePicker::make('last_active_date'), - TextInput::make('freezes_available') - ->required() - ->numeric() - ->default(0), - DatePicker::make('freeze_last_granted_on'), - ]); - } -} diff --git a/app/Filament/Resources/Streaks/Schemas/StreakInfolist.php b/app/Filament/Resources/Streaks/Schemas/StreakInfolist.php new file mode 100644 index 0000000..45b5823 --- /dev/null +++ b/app/Filament/Resources/Streaks/Schemas/StreakInfolist.php @@ -0,0 +1,44 @@ +components([ + TextEntry::make('user.name') + ->label('Utilisateur'), + TextEntry::make('current_count') + ->label('Streak courant') + ->badge() + ->color('warning'), + TextEntry::make('longest_count') + ->label('Record') + ->numeric(), + TextEntry::make('freezes_available') + ->label('Freezes disponibles') + ->numeric(), + TextEntry::make('last_active_date') + ->label('Dernière activité') + ->date() + ->placeholder('—'), + TextEntry::make('freeze_last_granted_on') + ->label('Dernier freeze accordé') + ->date() + ->placeholder('—'), + TextEntry::make('last_reminded_on') + ->label('Dernier rappel envoyé') + ->date() + ->placeholder('—'), + ]); + } +} diff --git a/app/Filament/Resources/Streaks/StreakResource.php b/app/Filament/Resources/Streaks/StreakResource.php index 07be6df..46a8661 100644 --- a/app/Filament/Resources/Streaks/StreakResource.php +++ b/app/Filament/Resources/Streaks/StreakResource.php @@ -2,10 +2,8 @@ namespace App\Filament\Resources\Streaks; -use App\Filament\Resources\Streaks\Pages\CreateStreak; -use App\Filament\Resources\Streaks\Pages\EditStreak; use App\Filament\Resources\Streaks\Pages\ListStreaks; -use App\Filament\Resources\Streaks\Schemas\StreakForm; +use App\Filament\Resources\Streaks\Schemas\StreakInfolist; use App\Filament\Resources\Streaks\Tables\StreaksTable; use BackedEnum; use Filament\Resources\Resource; @@ -13,16 +11,30 @@ use Filament\Schemas\Schema; use Filament\Support\Icons\Heroicon; use Filament\Tables\Table; use Functional\Streaks\Models\Streak; +use Illuminate\Database\Eloquent\Model; +use UnitEnum; +/** + * Streaks calculés par StreakService (1 par user) — consultation + suppression uniquement, + * jamais de création/édition manuelle depuis le back-office. + */ class StreakResource extends Resource { protected static ?string $model = Streak::class; - protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedRectangleStack; + protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedFire; - public static function form(Schema $schema): Schema + protected static string|UnitEnum|null $navigationGroup = 'Gamification'; + + protected static ?int $navigationSort = 1; + + protected static ?string $modelLabel = 'streak'; + + protected static ?string $pluralModelLabel = 'streaks'; + + public static function infolist(Schema $schema): Schema { - return StreakForm::configure($schema); + return StreakInfolist::configure($schema); } public static function table(Table $table): Table @@ -30,19 +42,28 @@ class StreakResource extends Resource return StreaksTable::configure($table); } - public static function getRelations(): array + public static function canCreate(): bool { - return [ - // - ]; + return false; + } + + public static function canEdit(Model $record): bool + { + return false; + } + + /** + * @return array + */ + public static function getGloballySearchableAttributes(): array + { + return ['user.name']; } public static function getPages(): array { return [ 'index' => ListStreaks::route('/'), - 'create' => CreateStreak::route('/create'), - 'edit' => EditStreak::route('/{record}/edit'), ]; } } diff --git a/app/Filament/Resources/Streaks/Tables/StreaksTable.php b/app/Filament/Resources/Streaks/Tables/StreaksTable.php index 612078e..30f0e58 100644 --- a/app/Filament/Resources/Streaks/Tables/StreaksTable.php +++ b/app/Filament/Resources/Streaks/Tables/StreaksTable.php @@ -3,13 +3,15 @@ namespace App\Filament\Resources\Streaks\Tables; use Filament\Actions\BulkActionGroup; +use Filament\Actions\DeleteAction; use Filament\Actions\DeleteBulkAction; -use Filament\Actions\EditAction; +use Filament\Actions\ViewAction; use Filament\Tables\Columns\TextColumn; use Filament\Tables\Table; /** * Table des streaks : régularité par utilisateur (courant, record, freezes, dernière activité). + * Lecture seule + suppression : calculé par StreakService, jamais créé/édité ici. */ class StreaksTable { @@ -33,14 +35,16 @@ class StreaksTable TextColumn::make('freezes_available') ->label('Freezes dispo') ->numeric() - ->sortable(), + ->sortable() + ->toggleable(isToggledHiddenByDefault: true), TextColumn::make('last_active_date') ->label('Dernière activité') ->date() ->sortable(), ]) ->recordActions([ - EditAction::make(), + ViewAction::make(), + DeleteAction::make(), ]) ->toolbarActions([ BulkActionGroup::make([ diff --git a/app/Filament/Resources/Users/Schemas/UserForm.php b/app/Filament/Resources/Users/Schemas/UserForm.php index d81b59e..d6734a1 100644 --- a/app/Filament/Resources/Users/Schemas/UserForm.php +++ b/app/Filament/Resources/Users/Schemas/UserForm.php @@ -15,25 +15,46 @@ class UserForm return $schema ->components([ TextInput::make('name') + ->label('Nom') ->required(), TextInput::make('email') - ->label('Email address') + ->label('Email') ->email() ->required(), - DateTimePicker::make('email_verified_at'), + DateTimePicker::make('email_verified_at') + ->label('Email vérifié le'), + // Requis à la création, laissé vide à l'édition pour ne pas écraser le mot de passe + // existant (le cast 'hashed' du modèle User se charge du hachage à la sauvegarde). TextInput::make('password') + ->label('Mot de passe') ->password() - ->required(), + ->revealable() + ->required(fn (string $operation): bool => $operation === 'create') + ->dehydrated(fn (?string $state): bool => filled($state)) + ->dehydrateStateUsing(fn (?string $state): ?string => filled($state) ? $state : null), TextInput::make('locale') + ->label('Langue') ->required() ->default('fr'), Select::make('units') + ->label('Unités') ->options(Units::class) ->default('metric') ->required(), - TextInput::make('timezone'), - TextInput::make('avatar_path'), - TextInput::make('oidc_sub'), + TextInput::make('timezone') + ->label('Fuseau horaire'), + TextInput::make('avatar_path') + ->label('Avatar (chemin)'), + TextInput::make('oidc_sub') + ->label('Identifiant OIDC'), + // Assignation des rôles Spatie (guard 'web') : pilote l'accès au back-office. + Select::make('roles') + ->label('Rôles') + ->relationship('roles', 'name') + ->multiple() + ->preload() + ->searchable() + ->columnSpanFull(), ]); } } diff --git a/app/Filament/Resources/Users/Tables/UsersTable.php b/app/Filament/Resources/Users/Tables/UsersTable.php index a5fc28d..226aaf2 100644 --- a/app/Filament/Resources/Users/Tables/UsersTable.php +++ b/app/Filament/Resources/Users/Tables/UsersTable.php @@ -2,14 +2,22 @@ namespace App\Filament\Resources\Users\Tables; +use Filament\Actions\BulkAction; use Filament\Actions\BulkActionGroup; use Filament\Actions\DeleteBulkAction; use Filament\Actions\EditAction; +use Filament\Forms\Components\Select; +use Filament\Support\Icons\Heroicon; use Filament\Tables\Columns\TextColumn; +use Filament\Tables\Filters\SelectFilter; +use Filament\Tables\Filters\TernaryFilter; use Filament\Tables\Table; +use Functional\Users\Enums\Units; +use Illuminate\Database\Eloquent\Collection; +use Spatie\Permission\Models\Role; /** - * Table des utilisateurs : identité, préférences d'affichage, date d'inscription. + * Table des utilisateurs : identité, rôles, préférences d'affichage, date d'inscription. */ class UsersTable { @@ -25,23 +33,59 @@ class UsersTable ->label('Email') ->searchable() ->sortable(), + TextColumn::make('roles.name') + ->label('Rôles') + ->badge() + ->color('primary'), TextColumn::make('locale') ->label('Langue') - ->badge(), + ->badge() + ->toggleable(isToggledHiddenByDefault: true), TextColumn::make('units') ->label('Unités') ->badge(), + TextColumn::make('email_verified_at') + ->label('Email vérifié') + ->dateTime() + ->placeholder('Non vérifié') + ->toggleable(isToggledHiddenByDefault: true), TextColumn::make('created_at') ->label('Inscrit le') ->dateTime() ->sortable(), ]) + ->filters([ + SelectFilter::make('roles') + ->label('Rôle') + ->relationship('roles', 'name'), + SelectFilter::make('units') + ->label('Unités') + ->options(Units::class), + TernaryFilter::make('email_verified_at') + ->label('Email vérifié') + ->nullable(), + ]) ->recordActions([ EditAction::make(), ]) ->toolbarActions([ BulkActionGroup::make([ DeleteBulkAction::make(), + // Assignation groupée d'un rôle Spatie sans repasser par chaque fiche. + BulkAction::make('assignRole') + ->label('Assigner un rôle') + ->icon(Heroicon::OutlinedShieldCheck) + ->color('primary') + ->schema([ + Select::make('role') + ->label('Rôle') + ->options(fn (): array => Role::query()->pluck('name', 'name')->all()) + ->required(), + ]) + ->action(function (Collection $records, array $data): void { + $records->each(fn ($user) => $user->assignRole($data['role'])); + }) + ->deselectRecordsAfterCompletion(), ]), ]) ->defaultSort('created_at', 'desc'); diff --git a/app/Filament/Resources/Users/UserResource.php b/app/Filament/Resources/Users/UserResource.php index 99a9700..847ee2e 100644 --- a/app/Filament/Resources/Users/UserResource.php +++ b/app/Filament/Resources/Users/UserResource.php @@ -13,12 +13,23 @@ use Filament\Schemas\Schema; use Filament\Support\Icons\Heroicon; use Filament\Tables\Table; use Functional\Users\Models\User; +use UnitEnum; class UserResource extends Resource { protected static ?string $model = User::class; - protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedRectangleStack; + protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedUsers; + + protected static string|UnitEnum|null $navigationGroup = 'Communauté'; + + protected static ?int $navigationSort = 1; + + protected static ?string $modelLabel = 'utilisateur'; + + protected static ?string $pluralModelLabel = 'utilisateurs'; + + protected static ?string $recordTitleAttribute = 'name'; public static function form(Schema $schema): Schema { @@ -37,6 +48,14 @@ class UserResource extends Resource ]; } + /** + * @return array + */ + public static function getGloballySearchableAttributes(): array + { + return ['name', 'email']; + } + public static function getPages(): array { return [ diff --git a/app/Filament/Resources/WorkoutSessions/Pages/CreateWorkoutSession.php b/app/Filament/Resources/WorkoutSessions/Pages/CreateWorkoutSession.php deleted file mode 100644 index c0d254d..0000000 --- a/app/Filament/Resources/WorkoutSessions/Pages/CreateWorkoutSession.php +++ /dev/null @@ -1,11 +0,0 @@ -components([ - Select::make('user_id') - ->relationship('user', 'name') - ->required(), - Select::make('routine_id') - ->relationship('routine', 'name'), - Select::make('program_id') - ->relationship('program', 'name'), - TextInput::make('title'), - DateTimePicker::make('started_at') - ->required(), - DateTimePicker::make('ended_at'), - Select::make('status') - ->options(WorkoutSessionStatus::class) - ->default('active') - ->required(), - Textarea::make('notes') - ->columnSpanFull(), - TextInput::make('total_volume') - ->numeric(), - ]); - } -} diff --git a/app/Filament/Resources/WorkoutSessions/Schemas/WorkoutSessionInfolist.php b/app/Filament/Resources/WorkoutSessions/Schemas/WorkoutSessionInfolist.php new file mode 100644 index 0000000..f4e0b0f --- /dev/null +++ b/app/Filament/Resources/WorkoutSessions/Schemas/WorkoutSessionInfolist.php @@ -0,0 +1,55 @@ +components([ + TextEntry::make('user.name') + ->label('Utilisateur'), + TextEntry::make('title') + ->label('Titre') + ->placeholder('—'), + TextEntry::make('routine.name') + ->label('Routine') + ->placeholder('—'), + TextEntry::make('program.name') + ->label('Programme') + ->placeholder('—'), + TextEntry::make('status') + ->label('Statut') + ->badge() + ->color(fn (WorkoutSessionStatus $state): string => match ($state) { + WorkoutSessionStatus::Active => 'warning', + WorkoutSessionStatus::Completed => 'success', + WorkoutSessionStatus::Abandoned => 'danger', + }), + TextEntry::make('started_at') + ->label('Débutée le') + ->dateTime(), + TextEntry::make('ended_at') + ->label('Terminée le') + ->dateTime() + ->placeholder('—'), + TextEntry::make('total_volume') + ->label('Volume total') + ->numeric() + ->placeholder('—'), + TextEntry::make('notes') + ->label('Notes') + ->columnSpanFull() + ->placeholder('—'), + ]); + } +} diff --git a/app/Filament/Resources/WorkoutSessions/Tables/WorkoutSessionsTable.php b/app/Filament/Resources/WorkoutSessions/Tables/WorkoutSessionsTable.php index 6bc7589..dcd5b72 100644 --- a/app/Filament/Resources/WorkoutSessions/Tables/WorkoutSessionsTable.php +++ b/app/Filament/Resources/WorkoutSessions/Tables/WorkoutSessionsTable.php @@ -3,15 +3,20 @@ namespace App\Filament\Resources\WorkoutSessions\Tables; use Filament\Actions\BulkActionGroup; +use Filament\Actions\DeleteAction; use Filament\Actions\DeleteBulkAction; -use Filament\Actions\EditAction; +use Filament\Actions\ViewAction; +use Filament\Forms\Components\DatePicker; use Filament\Tables\Columns\TextColumn; +use Filament\Tables\Filters\Filter; use Filament\Tables\Filters\SelectFilter; use Filament\Tables\Table; use Functional\Tracking\Enums\WorkoutSessionStatus; +use Illuminate\Database\Eloquent\Builder; /** * Table des séances : utilisateur, statut, début, volume total. + * Lecture seule + suppression : les séances sont loguées par l'app, jamais créées/éditées ici. */ class WorkoutSessionsTable { @@ -23,6 +28,11 @@ class WorkoutSessionsTable ->label('Utilisateur') ->searchable() ->sortable(), + TextColumn::make('title') + ->label('Titre') + ->searchable() + ->toggleable(isToggledHiddenByDefault: true) + ->placeholder('—'), TextColumn::make('status') ->label('Statut') ->badge() @@ -38,15 +48,28 @@ class WorkoutSessionsTable TextColumn::make('total_volume') ->label('Volume total') ->numeric() - ->sortable(), + ->sortable() + ->placeholder('—'), ]) ->filters([ SelectFilter::make('status') ->label('Statut') ->options(WorkoutSessionStatus::class), + Filter::make('started_at') + ->label('Période') + ->schema([ + DatePicker::make('from')->label('Du'), + DatePicker::make('until')->label('Au'), + ]) + ->query(function (Builder $query, array $data): Builder { + return $query + ->when($data['from'] ?? null, fn (Builder $q, string $date): Builder => $q->whereDate('started_at', '>=', $date)) + ->when($data['until'] ?? null, fn (Builder $q, string $date): Builder => $q->whereDate('started_at', '<=', $date)); + }), ]) ->recordActions([ - EditAction::make(), + ViewAction::make(), + DeleteAction::make(), ]) ->toolbarActions([ BulkActionGroup::make([ diff --git a/app/Filament/Resources/WorkoutSessions/WorkoutSessionResource.php b/app/Filament/Resources/WorkoutSessions/WorkoutSessionResource.php index 18dfa0c..a7c55a7 100644 --- a/app/Filament/Resources/WorkoutSessions/WorkoutSessionResource.php +++ b/app/Filament/Resources/WorkoutSessions/WorkoutSessionResource.php @@ -2,10 +2,8 @@ namespace App\Filament\Resources\WorkoutSessions; -use App\Filament\Resources\WorkoutSessions\Pages\CreateWorkoutSession; -use App\Filament\Resources\WorkoutSessions\Pages\EditWorkoutSession; use App\Filament\Resources\WorkoutSessions\Pages\ListWorkoutSessions; -use App\Filament\Resources\WorkoutSessions\Schemas\WorkoutSessionForm; +use App\Filament\Resources\WorkoutSessions\Schemas\WorkoutSessionInfolist; use App\Filament\Resources\WorkoutSessions\Tables\WorkoutSessionsTable; use BackedEnum; use Filament\Resources\Resource; @@ -13,16 +11,32 @@ use Filament\Schemas\Schema; use Filament\Support\Icons\Heroicon; use Filament\Tables\Table; use Functional\Tracking\Models\WorkoutSession; +use Illuminate\Database\Eloquent\Model; +use UnitEnum; +/** + * Séances loguées par les utilisateurs (via l'app) — consultation + suppression uniquement, + * jamais de création/édition manuelle depuis le back-office. + */ class WorkoutSessionResource extends Resource { protected static ?string $model = WorkoutSession::class; - protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedRectangleStack; + protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedBolt; - public static function form(Schema $schema): Schema + protected static string|UnitEnum|null $navigationGroup = 'Entraînement'; + + protected static ?int $navigationSort = 3; + + protected static ?string $modelLabel = 'séance'; + + protected static ?string $pluralModelLabel = 'séances'; + + protected static ?string $recordTitleAttribute = 'title'; + + public static function infolist(Schema $schema): Schema { - return WorkoutSessionForm::configure($schema); + return WorkoutSessionInfolist::configure($schema); } public static function table(Table $table): Table @@ -30,19 +44,28 @@ class WorkoutSessionResource extends Resource return WorkoutSessionsTable::configure($table); } - public static function getRelations(): array + public static function canCreate(): bool { - return [ - // - ]; + return false; + } + + public static function canEdit(Model $record): bool + { + return false; + } + + /** + * @return array + */ + public static function getGloballySearchableAttributes(): array + { + return ['title', 'user.name']; } public static function getPages(): array { return [ 'index' => ListWorkoutSessions::route('/'), - 'create' => CreateWorkoutSession::route('/create'), - 'edit' => EditWorkoutSession::route('/{record}/edit'), ]; } } diff --git a/app/Filament/Widgets/ExercisesByBodyPartChart.php b/app/Filament/Widgets/ExercisesByBodyPartChart.php new file mode 100644 index 0000000..ffcfd13 --- /dev/null +++ b/app/Filament/Widgets/ExercisesByBodyPartChart.php @@ -0,0 +1,52 @@ +whereNotNull('body_part') + ->selectRaw('body_part, COUNT(*) as total') + ->groupBy('body_part') + ->orderByDesc('total') + ->pluck('total', 'body_part'); + + return [ + 'datasets' => [ + [ + 'data' => $countsByBodyPart->values()->all(), + 'backgroundColor' => self::PALETTE, + ], + ], + 'labels' => $countsByBodyPart->keys()->all(), + ]; + } + + protected function getType(): string + { + return 'doughnut'; + } +} diff --git a/app/Filament/Widgets/StreakFitStatsOverview.php b/app/Filament/Widgets/StreakFitStatsOverview.php index f499cd1..72b12ce 100644 --- a/app/Filament/Widgets/StreakFitStatsOverview.php +++ b/app/Filament/Widgets/StreakFitStatsOverview.php @@ -16,6 +16,8 @@ use Illuminate\Support\Carbon; */ class StreakFitStatsOverview extends StatsOverviewWidget { + protected static ?int $sort = 1; + protected function getStats(): array { $sessionsThisWeek = WorkoutSession::query() @@ -29,7 +31,7 @@ class StreakFitStatsOverview extends StatsOverviewWidget ->color('primary'), Stat::make('Séances', (string) WorkoutSession::query()->count()) - ->description($sessionsThisWeek . ' cette semaine') + ->description($sessionsThisWeek.' cette semaine') ->descriptionIcon('heroicon-m-fire') ->color('warning'), diff --git a/app/Filament/Widgets/TopExercisesChart.php b/app/Filament/Widgets/TopExercisesChart.php new file mode 100644 index 0000000..ea48f85 --- /dev/null +++ b/app/Filament/Widgets/TopExercisesChart.php @@ -0,0 +1,51 @@ +join('exercises', 'exercises.id', '=', 'set_logs.exercise_id') + ->selectRaw('exercises.name as name, COUNT(*) as total') + ->groupBy('exercises.id', 'exercises.name') + ->orderByDesc('total') + ->limit(self::TOP_COUNT) + ->get(); + + return [ + 'datasets' => [ + [ + 'label' => 'Séries loguées', + 'data' => $topExercises->pluck('total')->all(), + 'backgroundColor' => '#f97316', + 'borderRadius' => 4, + ], + ], + 'labels' => $topExercises->pluck('name')->all(), + ]; + } + + protected function getType(): string + { + return 'bar'; + } +} diff --git a/app/Filament/Widgets/UsersGrowthChart.php b/app/Filament/Widgets/UsersGrowthChart.php new file mode 100644 index 0000000..68b1583 --- /dev/null +++ b/app/Filament/Widgets/UsersGrowthChart.php @@ -0,0 +1,59 @@ +selectRaw('DATE(created_at) as day, COUNT(*) as total') + ->groupBy('day') + ->orderBy('day') + ->pluck('total', 'day'); + + $labels = []; + $data = []; + $cumulative = 0; + + foreach ($countsByDay as $day => $total) { + $cumulative += (int) $total; + $labels[] = Carbon::parse($day)->format('d/m/Y'); + $data[] = $cumulative; + } + + return [ + 'datasets' => [ + [ + 'label' => 'Utilisateurs inscrits (cumulé)', + 'data' => $data, + 'borderColor' => '#f59e0b', + 'backgroundColor' => 'rgba(245, 158, 11, 0.15)', + 'fill' => true, + ], + ], + 'labels' => $labels, + ]; + } + + protected function getType(): string + { + return 'line'; + } +} diff --git a/app/Filament/Widgets/WorkoutSessionsPerDayChart.php b/app/Filament/Widgets/WorkoutSessionsPerDayChart.php new file mode 100644 index 0000000..c422797 --- /dev/null +++ b/app/Filament/Widgets/WorkoutSessionsPerDayChart.php @@ -0,0 +1,66 @@ +subDays(29)->startOfDay(); + + // Nombre de séances complétées par jour, sur la fenêtre glissante de 30 jours. + $countsByDay = WorkoutSession::query() + ->where('status', WorkoutSessionStatus::Completed) + ->where('started_at', '>=', $start) + ->selectRaw('DATE(started_at) as day, COUNT(*) as total') + ->groupBy('day') + ->pluck('total', 'day'); + + $labels = []; + $data = []; + + // On matérialise chaque jour (même sans séance) pour un axe continu. + for ($offset = 0; $offset < 30; $offset++) { + $date = $start->copy()->addDays($offset); + $key = $date->format('Y-m-d'); + + $labels[] = $date->format('d/m'); + $data[] = (int) ($countsByDay[$key] ?? 0); + } + + return [ + 'datasets' => [ + [ + 'label' => 'Séances complétées', + 'data' => $data, + 'backgroundColor' => '#f59e0b', + 'borderRadius' => 4, + ], + ], + 'labels' => $labels, + ]; + } + + protected function getType(): string + { + return 'bar'; + } +} diff --git a/app/Providers/Filament/AdminPanelProvider.php b/app/Providers/Filament/AdminPanelProvider.php index 4c172f0..1f895d5 100644 --- a/app/Providers/Filament/AdminPanelProvider.php +++ b/app/Providers/Filament/AdminPanelProvider.php @@ -2,7 +2,12 @@ namespace App\Providers\Filament; +use App\Filament\Widgets\ExercisesByBodyPartChart; use App\Filament\Widgets\StreakFitStatsOverview; +use App\Filament\Widgets\TopExercisesChart; +use App\Filament\Widgets\UsersGrowthChart; +use App\Filament\Widgets\WorkoutSessionsPerDayChart; +use BezhanSalleh\FilamentShield\FilamentShieldPlugin; use Filament\Http\Middleware\Authenticate; use Filament\Http\Middleware\AuthenticateSession; use Filament\Http\Middleware\DisableBladeIconComponents; @@ -21,10 +26,11 @@ use Illuminate\View\Middleware\ShareErrorsFromSession; /** * Back-office StreakFit (Filament). * - * Thème "flamme" : accent orange/amber sur base claire + dark mode. + * Thème "flamme" : accent amber/orange sur base zinc + dark mode. + * Navigation regroupée par domaine métier (Catalogue, Communauté, Entraînement, + * Gamification, Système), dashboard enrichi de charts (cf. app/Filament/Widgets). * Auth via le guard 'web' standard (compatible avec le flow Sanctum SPA du front) ; - * l'accès effectif au panel sera verrouillé quand le model User implémentera - * Filament\Models\Contracts\FilamentUser::canAccessPanel(). + * l'accès effectif au panel est verrouillé par User::canAccessPanel() (hasRole('admin')). */ class AdminPanelProvider extends PanelProvider { @@ -35,17 +41,30 @@ class AdminPanelProvider extends PanelProvider ->id('admin') ->path('admin') ->brandName('StreakFit 🔥') + ->favicon(asset('favicon.ico')) ->login() // Guard web standard : n'interfère pas avec l'auth Sanctum du front. ->authGuard('web') - // Accent "flamme" : orange en primaire, amber en secondaire (warning). + // Accent "flamme" : amber en primaire, orange en secondaire (warning), gris zinc neutre. ->colors([ - 'primary' => Color::Orange, - 'warning' => Color::Amber, + 'primary' => Color::Amber, + 'warning' => Color::Orange, 'danger' => Color::Red, 'success' => Color::Emerald, + 'gray' => Color::Zinc, + ]) + // Dark mode disponible via le sélecteur clair/sombre (activé explicitement, non forcé). + ->darkMode(condition: true, isForced: false) + // Barre latérale repliable sur desktop (gain de place sur les grandes tables). + ->sidebarCollapsibleOnDesktop() + // Ordre d'affichage des groupes de navigation dans la sidebar. + ->navigationGroups([ + 'Catalogue', + 'Communauté', + 'Entraînement', + 'Gamification', + 'Système', ]) - // Dark mode disponible via le sélecteur clair/sombre (activé par défaut). ->discoverResources(in: app_path('Filament/Resources'), for: 'App\Filament\Resources') ->discoverPages(in: app_path('Filament/Pages'), for: 'App\Filament\Pages') ->pages([ @@ -54,6 +73,17 @@ class AdminPanelProvider extends PanelProvider ->discoverWidgets(in: app_path('Filament/Widgets'), for: 'App\Filament\Widgets') ->widgets([ StreakFitStatsOverview::class, + WorkoutSessionsPerDayChart::class, + UsersGrowthChart::class, + ExercisesByBodyPartChart::class, + TopExercisesChart::class, + ]) + // Gestion des rôles/permissions (Spatie) via Filament Shield — fournit sa propre + // RoleResource, rangée dans "Communauté" à côté de l'utilisateur. + ->plugins([ + FilamentShieldPlugin::make() + ->navigationGroup('Communauté') + ->navigationSort(2), ]) ->middleware([ EncryptCookies::class, diff --git a/composer.json b/composer.json index 66f3424..46c2c2f 100644 --- a/composer.json +++ b/composer.json @@ -7,6 +7,7 @@ "license": "MIT", "require": { "php": "^8.3", + "bezhansalleh/filament-shield": "^4.2", "filament/filament": "^5.0", "functional/exercises": "*", "functional/programs": "*", @@ -22,7 +23,7 @@ "league/flysystem-aws-s3-v3": "^3.0", "lomkit/laravel-access-control": "^0.5.0", "lomkit/laravel-rest-api": "^2.22", - "spatie/laravel-permission": "^8.3", + "spatie/laravel-permission": "^7.0", "technical/integrations": "*", "technical/osdd": "*", "xefi/laravel-osdd": "^2.0" diff --git a/composer.lock b/composer.lock index de77652..3687f96 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "1fd71e714394b125185f4b12ac7e5165", + "content-hash": "154031ad784b188e7ceda6ba0ded7192", "packages": [ { "name": "anourvalar/eloquent-serialize", @@ -222,6 +222,179 @@ }, "time": "2026-07-17T18:11:29+00:00" }, + { + "name": "bezhansalleh/filament-plugin-essentials", + "version": "1.2.1", + "source": { + "type": "git", + "url": "https://github.com/bezhanSalleh/filament-plugin-essentials.git", + "reference": "de3a8a07edcf1bc9fe829480ae09aa00265e7f03" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/bezhanSalleh/filament-plugin-essentials/zipball/de3a8a07edcf1bc9fe829480ae09aa00265e7f03", + "reference": "de3a8a07edcf1bc9fe829480ae09aa00265e7f03", + "shasum": "" + }, + "require": { + "filament/filament": "^4.0|^5.0", + "illuminate/contracts": "^11.28|^12.0|^13.0", + "php": "^8.2|^8.3", + "spatie/laravel-package-tools": "^1.0" + }, + "require-dev": { + "larastan/larastan": "^3.0", + "laravel/pint": "^1.14", + "nunomaduro/collision": "^7.10.0|^8.1.1", + "orchestra/testbench": "^9.0.0|^10.0.0|^11.0.0", + "pestphp/pest": "^3.0|^4.0", + "pestphp/pest-plugin-arch": "^3.0|^4.0", + "pestphp/pest-plugin-laravel": "^3.0|^4.0", + "pestphp/pest-plugin-type-coverage": "^3.5|^4.0", + "phpstan/extension-installer": "^1.3|^2.0", + "phpstan/phpstan-deprecation-rules": "^1.1|^2.0", + "phpstan/phpstan-phpunit": "^1.3|^2.0", + "rector/rector": "^2.1", + "spatie/laravel-ray": "^1.40" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "BezhanSalleh\\PluginEssentials\\PluginEssentialsServiceProvider" + ] + } + }, + "autoload": { + "psr-4": { + "BezhanSalleh\\PluginEssentials\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Bezhan Salleh", + "email": "bezhan_salleh@yahoo.com", + "role": "Developer" + } + ], + "description": "A collection of essential traits that streamline Filament plugin development by taking care of the boilerplate, so you can focus on shipping real features faster", + "homepage": "https://github.com/bezhansalleh/filament-plugin-essentials", + "keywords": [ + "Bezhan Salleh", + "filament-plugin-essentials", + "laravel" + ], + "support": { + "issues": "https://github.com/bezhanSalleh/filament-plugin-essentials/issues", + "source": "https://github.com/bezhanSalleh/filament-plugin-essentials/tree/1.2.1" + }, + "funding": [ + { + "url": "https://github.com/bezhanSalleh", + "type": "github" + } + ], + "time": "2026-03-22T08:15:32+00:00" + }, + { + "name": "bezhansalleh/filament-shield", + "version": "4.2.0", + "source": { + "type": "git", + "url": "https://github.com/bezhanSalleh/filament-shield.git", + "reference": "a48ea9ca115c644ce40380b853142afcd65e38d1" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/bezhanSalleh/filament-shield/zipball/a48ea9ca115c644ce40380b853142afcd65e38d1", + "reference": "a48ea9ca115c644ce40380b853142afcd65e38d1", + "shasum": "" + }, + "require": { + "bezhansalleh/filament-plugin-essentials": "^1.0", + "filament/filament": "^4.0|^5.0", + "illuminate/contracts": "^11.28|^12.0|^13.0", + "illuminate/support": "^11.28|^12.0|^13.0", + "php": "^8.2|^8.3", + "spatie/laravel-package-tools": "^1.0", + "spatie/laravel-permission": "^6.0|^7.0" + }, + "require-dev": { + "larastan/larastan": "^3.0", + "laravel/pint": "^1.26", + "nunomaduro/collision": "^8.8", + "orchestra/testbench": "^9.0|^10.0|^11.0", + "pestphp/pest": "^3.8|^4.0", + "pestphp/pest-plugin-laravel": "^3.2|^4.0", + "pestphp/pest-plugin-livewire": "^3.0|^4.0", + "pestphp/pest-plugin-type-coverage": "^3.6|^4.0", + "phpstan/extension-installer": "^1.4", + "phpstan/phpstan": "^2.1", + "phpstan/phpstan-deprecation-rules": "^2.0", + "phpstan/phpstan-phpunit": "^2.0", + "phpunit/phpunit": "^11.0|^12.0", + "rector/jack": "^0.4.0", + "rector/rector": "^2.2", + "spatie/laravel-ray": "^1.43" + }, + "type": "library", + "extra": { + "laravel": { + "aliases": { + "FilamentShield": "BezhanSalleh\\FilamentShield\\Facades\\FilamentShield" + }, + "providers": [ + "BezhanSalleh\\FilamentShield\\FilamentShieldServiceProvider" + ] + } + }, + "autoload": { + "psr-4": { + "BezhanSalleh\\FilamentShield\\": "src", + "BezhanSalleh\\FilamentShield\\Database\\Factories\\": "database/factories" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Bezhan Salleh", + "email": "bezhan_salleh@yahoo.com", + "role": "Developer" + } + ], + "description": "Filament support for `spatie/laravel-permission`.", + "homepage": "https://github.com/bezhansalleh/filament-shield", + "keywords": [ + "acl", + "bezhanSalleh", + "filament", + "filament-shield", + "laravel", + "permission", + "permissions", + "rbac", + "roles", + "security" + ], + "support": { + "issues": "https://github.com/bezhanSalleh/filament-shield/issues", + "source": "https://github.com/bezhanSalleh/filament-shield/tree/4.2.0" + }, + "funding": [ + { + "url": "https://github.com/bezhanSalleh", + "type": "github" + } + ], + "time": "2026-03-22T08:31:44+00:00" + }, { "name": "blade-ui-kit/blade-heroicons", "version": "2.7.0", @@ -6200,16 +6373,16 @@ }, { "name": "spatie/laravel-permission", - "version": "8.3.0", + "version": "7.4.2", "source": { "type": "git", "url": "https://github.com/spatie/laravel-permission.git", - "reference": "60e8ed5b2fbf043c2264433fc2680c76b8b66aa6" + "reference": "15a9daf02ba02d3ae77aaa6da582708231ef999b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/spatie/laravel-permission/zipball/60e8ed5b2fbf043c2264433fc2680c76b8b66aa6", - "reference": "60e8ed5b2fbf043c2264433fc2680c76b8b66aa6", + "url": "https://api.github.com/repos/spatie/laravel-permission/zipball/15a9daf02ba02d3ae77aaa6da582708231ef999b", + "reference": "15a9daf02ba02d3ae77aaa6da582708231ef999b", "shasum": "" }, "require": { @@ -6222,7 +6395,6 @@ }, "require-dev": { "larastan/larastan": "^3.9", - "laravel/octane": "^2.0", "laravel/passport": "^13.0", "laravel/pint": "^1.0", "orchestra/testbench": "^10.0|^11.0", @@ -6238,8 +6410,8 @@ ] }, "branch-alias": { - "dev-main": "8.x-dev", - "dev-master": "8.x-dev" + "dev-main": "7.x-dev", + "dev-master": "7.x-dev" } }, "autoload": { @@ -6276,7 +6448,7 @@ ], "support": { "issues": "https://github.com/spatie/laravel-permission/issues", - "source": "https://github.com/spatie/laravel-permission/tree/8.3.0" + "source": "https://github.com/spatie/laravel-permission/tree/7.4.2" }, "funding": [ { @@ -6284,7 +6456,7 @@ "type": "github" } ], - "time": "2026-07-03T15:36:01+00:00" + "time": "2026-05-30T19:21:26+00:00" }, { "name": "spatie/shiki-php", diff --git a/config/filament-shield.php b/config/filament-shield.php new file mode 100644 index 0000000..cca19bf --- /dev/null +++ b/config/filament-shield.php @@ -0,0 +1,267 @@ + [ + 'slug' => 'shield/roles', + 'show_model_path' => true, + 'cluster' => null, + 'tabs' => [ + 'pages' => true, + 'widgets' => true, + 'resources' => true, + 'custom_permissions' => false, + ], + ], + + /* + |-------------------------------------------------------------------------- + | Multi-Tenancy + |-------------------------------------------------------------------------- + | + | When your application supports teams, Shield will automatically detect + | and configure the tenant model during setup. This enables tenant-scoped + | roles and permissions throughout your application. + | + */ + + 'tenant_model' => null, + + /* + |-------------------------------------------------------------------------- + | User Model + |-------------------------------------------------------------------------- + | + | This value contains the class name of your user model. This model will + | be used for role assignments and must implement the HasRoles trait + | provided by the Spatie\Permission package. + | + */ + + 'auth_provider_model' => 'App\\Models\\User', + + /* + |-------------------------------------------------------------------------- + | Super Admin + |-------------------------------------------------------------------------- + | + | Here you may define a super admin that has unrestricted access to your + | application. You can choose to implement this via Laravel's gate system + | or as a traditional role with all permissions explicitly assigned. + | + */ + + 'super_admin' => [ + 'enabled' => true, + 'name' => 'super_admin', + 'define_via_gate' => false, + 'intercept_gate' => 'before', + ], + + /* + |-------------------------------------------------------------------------- + | Panel User + |-------------------------------------------------------------------------- + | + | When enabled, Shield will create a basic panel user role that can be + | assigned to users who should have access to your Filament panels but + | don't need any specific permissions beyond basic authentication. + | + */ + + 'panel_user' => [ + 'enabled' => true, + 'name' => 'panel_user', + ], + + /* + |-------------------------------------------------------------------------- + | Permission Builder + |-------------------------------------------------------------------------- + | + | You can customize how permission keys are generated to match your + | preferred naming convention and organizational standards. Shield uses + | these settings when creating permission names from your resources. + | + | Supported formats: snake, kebab, pascal, camel, upper_snake, lower_snake + | + */ + + 'permissions' => [ + 'separator' => ':', + 'case' => 'pascal', + 'generate' => true, + ], + + /* + |-------------------------------------------------------------------------- + | Policies + |-------------------------------------------------------------------------- + | + | Shield can automatically generate Laravel policies for your resources. + | When merge is enabled, the methods below will be combined with any + | resource-specific methods you define in the resources section. + | + */ + + 'policies' => [ + 'path' => app_path('Policies'), + 'merge' => true, + 'generate' => true, + 'methods' => [ + 'viewAny', 'view', 'create', 'update', 'delete', 'deleteAny', 'restore', + 'forceDelete', 'forceDeleteAny', 'restoreAny', 'replicate', 'reorder', + ], + 'single_parameter_methods' => [ + 'viewAny', + 'create', + 'deleteAny', + 'forceDeleteAny', + 'restoreAny', + 'reorder', + ], + ], + + /* + |-------------------------------------------------------------------------- + | Localization + |-------------------------------------------------------------------------- + | + | Shield supports multiple languages out of the box. When enabled, you + | can provide translated labels for permissions to create a more + | localized experience for your international users. + | + */ + + 'localization' => [ + 'enabled' => false, + 'key' => 'filament-shield::filament-shield.resource_permission_prefixes_labels', + ], + + /* + |-------------------------------------------------------------------------- + | Resources + |-------------------------------------------------------------------------- + | + | Here you can fine-tune permissions for specific Filament resources. + | Use the 'manage' array to override the default policy methods for + | individual resources, giving you granular control over permissions. + | + */ + + 'resources' => [ + 'subject' => 'model', + 'manage' => [ + RoleResource::class => [ + 'viewAny', + 'view', + 'create', + 'update', + 'delete', + ], + ], + 'exclude' => [ + // + ], + ], + + /* + |-------------------------------------------------------------------------- + | Pages + |-------------------------------------------------------------------------- + | + | Most Filament pages only require view permissions. Pages listed in the + | exclude array will be skipped during permission generation and won't + | appear in your role management interface. + | + */ + + 'pages' => [ + 'subject' => 'class', + 'prefix' => 'view', + 'exclude' => [ + Dashboard::class, + ], + ], + + /* + |-------------------------------------------------------------------------- + | Widgets + |-------------------------------------------------------------------------- + | + | Like pages, widgets typically only need view permissions. Add widgets + | to the exclude array if you don't want them to appear in your role + | management interface. + | + */ + + 'widgets' => [ + 'subject' => 'class', + 'prefix' => 'view', + 'exclude' => [ + AccountWidget::class, + FilamentInfoWidget::class, + ], + ], + + /* + |-------------------------------------------------------------------------- + | Custom Permissions + |-------------------------------------------------------------------------- + | + | Sometimes you need permissions that don't map to resources, pages, or + | widgets. Define any custom permissions here and they'll be available + | when editing roles in your application. + | + */ + + 'custom_permissions' => [], + + /* + |-------------------------------------------------------------------------- + | Entity Discovery + |-------------------------------------------------------------------------- + | + | By default, Shield only looks for entities in your default Filament + | panel. Enable these options if you're using multiple panels and want + | Shield to discover entities across all of them. + | + */ + + 'discovery' => [ + 'discover_all_resources' => false, + 'discover_all_widgets' => false, + 'discover_all_pages' => false, + ], + + /* + |-------------------------------------------------------------------------- + | Role Policy + |-------------------------------------------------------------------------- + | + | Shield can automatically register a policy for role management itself. + | This lets you control who can manage roles using Laravel's built-in + | authorization system. Requires a RolePolicy class in your app. + | + */ + + 'register_role_policy' => true, + +]; diff --git a/config/permission.php b/config/permission.php new file mode 100644 index 0000000..8f1f452 --- /dev/null +++ b/config/permission.php @@ -0,0 +1,219 @@ + [ + + /* + * When using the "HasPermissions" trait from this package, we need to know which + * Eloquent model should be used to retrieve your permissions. Of course, it + * is often just the "Permission" model but you may use whatever you like. + * + * The model you want to use as a Permission model needs to implement the + * `Spatie\Permission\Contracts\Permission` contract. + */ + + 'permission' => Permission::class, + + /* + * When using the "HasRoles" trait from this package, we need to know which + * Eloquent model should be used to retrieve your roles. Of course, it + * is often just the "Role" model but you may use whatever you like. + * + * The model you want to use as a Role model needs to implement the + * `Spatie\Permission\Contracts\Role` contract. + */ + + 'role' => Role::class, + + /* + * When using the "Teams" feature from this package, we need to know which + * Eloquent model should be used to retrieve your teams. Of course, it + * is often just the "Team" model but you may use whatever you like. + */ + 'team' => null, + + /* + * When using the "HasModels" trait and passing raw IDs to syncModels, + * attachModels, or detachModels, this model class will be used to + * resolve those IDs. If null, defaults to the guard's model. + */ + 'default_model' => null, + ], + + 'table_names' => [ + + /* + * When using the "HasRoles" trait from this package, we need to know which + * table should be used to retrieve your roles. We have chosen a basic + * default value but you may easily change it to any table you like. + */ + + 'roles' => 'roles', + + /* + * When using the "HasPermissions" trait from this package, we need to know which + * table should be used to retrieve your permissions. We have chosen a basic + * default value but you may easily change it to any table you like. + */ + + 'permissions' => 'permissions', + + /* + * When using the "HasPermissions" trait from this package, we need to know which + * table should be used to retrieve your models permissions. We have chosen a + * basic default value but you may easily change it to any table you like. + */ + + 'model_has_permissions' => 'model_has_permissions', + + /* + * When using the "HasRoles" trait from this package, we need to know which + * table should be used to retrieve your models roles. We have chosen a + * basic default value but you may easily change it to any table you like. + */ + + 'model_has_roles' => 'model_has_roles', + + /* + * When using the "HasRoles" trait from this package, we need to know which + * table should be used to retrieve your roles permissions. We have chosen a + * basic default value but you may easily change it to any table you like. + */ + + 'role_has_permissions' => 'role_has_permissions', + ], + + 'column_names' => [ + /* + * Change this if you want to name the related pivots other than defaults + */ + 'role_pivot_key' => null, // default 'role_id', + 'permission_pivot_key' => null, // default 'permission_id', + + /* + * Change this if you want to name the related model primary key other than + * `model_id`. + * + * For example, this would be nice if your primary keys are all UUIDs. In + * that case, name this `model_uuid`. + */ + + 'model_morph_key' => 'model_id', + + /* + * Change this if you want to use the teams feature and your related model's + * foreign key is other than `team_id`. + */ + + 'team_foreign_key' => 'team_id', + ], + + /* + * When set to true, the method for checking permissions will be registered on the gate. + * Set this to false if you want to implement custom logic for checking permissions. + */ + + 'register_permission_check_method' => true, + + /* + * When set to true, Laravel\Octane\Events\OperationTerminated event listener will be registered + * this will refresh permissions on every TickTerminated, TaskTerminated and RequestTerminated + * NOTE: This should not be needed in most cases, but an Octane/Vapor combination benefited from it. + */ + 'register_octane_reset_listener' => false, + + /* + * Events will fire when a role or permission is assigned/unassigned: + * \Spatie\Permission\Events\RoleAttachedEvent + * \Spatie\Permission\Events\RoleDetachedEvent + * \Spatie\Permission\Events\PermissionAttachedEvent + * \Spatie\Permission\Events\PermissionDetachedEvent + * + * To enable, set to true, and then create listeners to watch these events. + */ + 'events_enabled' => false, + + /* + * Teams Feature. + * When set to true the package implements teams using the 'team_foreign_key'. + * If you want the migrations to register the 'team_foreign_key', you must + * set this to true before doing the migration. + * If you already did the migration then you must make a new migration to also + * add 'team_foreign_key' to 'roles', 'model_has_roles', and 'model_has_permissions' + * (view the latest version of this package's migration file) + */ + + 'teams' => false, + + /* + * The class to use to resolve the permissions team id + */ + 'team_resolver' => DefaultTeamResolver::class, + + /* + * Passport Client Credentials Grant + * When set to true the package will use Passports Client to check permissions + */ + + 'use_passport_client_credentials' => false, + + /* + * When set to true, the required permission names are added to exception messages. + * This could be considered an information leak in some contexts, so the default + * setting is false here for optimum safety. + */ + + 'display_permission_in_exception' => false, + + /* + * When set to true, the required role names are added to exception messages. + * This could be considered an information leak in some contexts, so the default + * setting is false here for optimum safety. + */ + + 'display_role_in_exception' => false, + + /* + * By default wildcard permission lookups are disabled. + * See documentation to understand supported syntax. + */ + + 'enable_wildcard_permission' => false, + + /* + * The class to use for interpreting wildcard permissions. + * If you need to modify delimiters, override the class and specify its name here. + */ + // 'wildcard_permission' => Spatie\Permission\WildcardPermission::class, + + /* Cache-specific settings */ + + 'cache' => [ + + /* + * By default all permissions are cached for 24 hours to speed up performance. + * When permissions or roles are updated the cache is flushed automatically. + */ + + 'expiration_time' => DateInterval::createFromDateString('24 hours'), + + /* + * The cache key used to store all permissions. + */ + + 'key' => 'spatie.permission.cache', + + /* + * You may optionally indicate a specific cache driver to use for permission and + * role caching using any of the `store` drivers listed in the cache.php config + * file. Using 'default' here means to use the `default` set in cache.php. + */ + + 'store' => 'default', + ], +]; diff --git a/database/migrations/2026_07_19_024900_create_permission_tables.php b/database/migrations/2026_07_19_024900_create_permission_tables.php new file mode 100644 index 0000000..8986275 --- /dev/null +++ b/database/migrations/2026_07_19_024900_create_permission_tables.php @@ -0,0 +1,137 @@ +id(); // permission id + $table->string('name'); + $table->string('guard_name'); + $table->timestamps(); + + $table->unique(['name', 'guard_name']); + }); + + /** + * See `docs/prerequisites.md` for suggested lengths on 'name' and 'guard_name' if "1071 Specified key was too long" errors are encountered. + */ + Schema::create($tableNames['roles'], static function (Blueprint $table) use ($teams, $columnNames) { + $table->id(); // role id + if ($teams || config('permission.testing')) { // permission.testing is a fix for sqlite testing + $table->unsignedBigInteger($columnNames['team_foreign_key'])->nullable(); + $table->index($columnNames['team_foreign_key'], 'roles_team_foreign_key_index'); + } + $table->string('name'); + $table->string('guard_name'); + $table->timestamps(); + if ($teams || config('permission.testing')) { + $table->unique([$columnNames['team_foreign_key'], 'name', 'guard_name']); + } else { + $table->unique(['name', 'guard_name']); + } + }); + + Schema::create($tableNames['model_has_permissions'], static function (Blueprint $table) use ($tableNames, $columnNames, $pivotPermission, $teams) { + $table->unsignedBigInteger($pivotPermission); + + $table->string('model_type'); + $table->unsignedBigInteger($columnNames['model_morph_key']); + $table->index([$columnNames['model_morph_key'], 'model_type'], 'model_has_permissions_model_id_model_type_index'); + + $table->foreign($pivotPermission) + ->references('id') // permission id + ->on($tableNames['permissions']) + ->cascadeOnDelete(); + if ($teams) { + $table->unsignedBigInteger($columnNames['team_foreign_key']); + $table->index($columnNames['team_foreign_key'], 'model_has_permissions_team_foreign_key_index'); + + $table->primary([$columnNames['team_foreign_key'], $pivotPermission, $columnNames['model_morph_key'], 'model_type'], + 'model_has_permissions_permission_model_type_primary'); + } else { + $table->primary([$pivotPermission, $columnNames['model_morph_key'], 'model_type'], + 'model_has_permissions_permission_model_type_primary'); + } + }); + + Schema::create($tableNames['model_has_roles'], static function (Blueprint $table) use ($tableNames, $columnNames, $pivotRole, $teams) { + $table->unsignedBigInteger($pivotRole); + + $table->string('model_type'); + $table->unsignedBigInteger($columnNames['model_morph_key']); + $table->index([$columnNames['model_morph_key'], 'model_type'], 'model_has_roles_model_id_model_type_index'); + + $table->foreign($pivotRole) + ->references('id') // role id + ->on($tableNames['roles']) + ->cascadeOnDelete(); + if ($teams) { + $table->unsignedBigInteger($columnNames['team_foreign_key']); + $table->index($columnNames['team_foreign_key'], 'model_has_roles_team_foreign_key_index'); + + $table->primary([$columnNames['team_foreign_key'], $pivotRole, $columnNames['model_morph_key'], 'model_type'], + 'model_has_roles_role_model_type_primary'); + } else { + $table->primary([$pivotRole, $columnNames['model_morph_key'], 'model_type'], + 'model_has_roles_role_model_type_primary'); + } + }); + + Schema::create($tableNames['role_has_permissions'], static function (Blueprint $table) use ($tableNames, $pivotRole, $pivotPermission) { + $table->unsignedBigInteger($pivotPermission); + $table->unsignedBigInteger($pivotRole); + + $table->foreign($pivotPermission) + ->references('id') // permission id + ->on($tableNames['permissions']) + ->cascadeOnDelete(); + + $table->foreign($pivotRole) + ->references('id') // role id + ->on($tableNames['roles']) + ->cascadeOnDelete(); + + $table->primary([$pivotPermission, $pivotRole], 'role_has_permissions_permission_id_role_id_primary'); + }); + + app('cache') + ->store(config('permission.cache.store') != 'default' ? config('permission.cache.store') : null) + ->forget(config('permission.cache.key')); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + $tableNames = config('permission.table_names'); + + throw_if(empty($tableNames), 'Error: config/permission.php not found and defaults could not be merged. Please publish the package configuration before proceeding, or drop the tables manually.'); + + Schema::dropIfExists($tableNames['role_has_permissions']); + Schema::dropIfExists($tableNames['model_has_roles']); + Schema::dropIfExists($tableNames['model_has_permissions']); + Schema::dropIfExists($tableNames['roles']); + Schema::dropIfExists($tableNames['permissions']); + } +}; diff --git a/functional/routines/src/Http/Resources/RoutineExerciseResource.php b/functional/routines/src/Http/Resources/RoutineExerciseResource.php index 3ad8073..09cd68a 100644 --- a/functional/routines/src/Http/Resources/RoutineExerciseResource.php +++ b/functional/routines/src/Http/Resources/RoutineExerciseResource.php @@ -2,16 +2,21 @@ namespace Functional\Routines\Http\Resources; +use Functional\Exercises\Models\Exercise; use Illuminate\Http\Request; use Illuminate\Http\Resources\Json\JsonResource; /** - * Une ligne du pivot routine_exercises, avec un sous-objet exercice minimal prêt-à-afficher. + * Une ligne du pivot routine_exercises, avec un sous-objet exercice minimal prêt-à-afficher + * (nom + muscle localisés selon la locale de la requête). */ class RoutineExerciseResource extends JsonResource { public function toArray(Request $request): array { + $locale = (string) ($request->query('locale') ?: 'fr'); + $exercise = $this->exercise; + return [ 'exercise_id' => $this->exercise_id, 'position' => $this->position, @@ -21,12 +26,12 @@ class RoutineExerciseResource extends JsonResource 'tempo' => $this->tempo, 'target_weight' => $this->target_weight, 'notes' => $this->notes, - 'exercise' => [ - 'id' => $this->exercise->id, - 'name' => $this->exercise->name, - 'image_url' => $this->exercise->image_url, - 'target' => $this->exercise->target, - ], + 'exercise' => $exercise ? [ + 'id' => $exercise->id, + 'name' => $exercise->localizedName($locale), + 'image_url' => $exercise->image_url, + 'target' => Exercise::localizeTerm($exercise->target, $locale), + ] : null, ]; } } diff --git a/functional/users/src/Models/User.php b/functional/users/src/Models/User.php index 2f1aee4..c62f699 100644 --- a/functional/users/src/Models/User.php +++ b/functional/users/src/Models/User.php @@ -15,6 +15,7 @@ use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; use Laravel\Sanctum\HasApiTokens; use NotificationChannels\WebPush\HasPushSubscriptions; +use Spatie\Permission\Traits\HasRoles; /** * @property string $locale @@ -28,12 +29,12 @@ use NotificationChannels\WebPush\HasPushSubscriptions; #[UseFactory(UserFactory::class)] class User extends Authenticatable implements FilamentUser { - use HasApiTokens, HasFactory, HasPushSubscriptions, Notifiable; + use HasApiTokens, HasFactory, HasPushSubscriptions, HasRoles, Notifiable; - /** Accès au back-office Filament (à affiner : rôle admin plus tard). */ + /** Accès au back-office Filament : réservé aux rôles "super_admin" ou "admin" (Filament Shield). */ public function canAccessPanel(Panel $panel): bool { - return true; + return $this->hasAnyRole(['super_admin', 'admin']); } /**