-
-
Notifications
You must be signed in to change notification settings - Fork 15
feat: (LAR-86) add bannished sysem #218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
StevyMarlino
merged 34 commits into
develop
from
feature/lar-86-mettre-en-place-un-systeme-pour-bannir-un-utilisateur
Nov 14, 2024
Merged
Changes from 24 commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
9647e17
feat: (LAR-107) Modification du formulaire de mot de passe oublié
Stephen2304 cd4c813
fix: (LAR-107) correction des conflits
Stephen2304 e3dfba4
feat: (LAR-107) Mise a jour
Stephen2304 583a633
feat: (LAR-107) Suppression des commentaire
Stephen2304 23882cf
fix: (LAR-107) suppresion du fichier auth-session
Stephen2304 a8cd309
fix: (LAR-107) correction des espaces
Stephen2304 374f8fa
feat: (LAR-86) add bannished sysem
StevyMarlino bf10e0c
feat(test): (LAR-86) add test
StevyMarlino 9687fde
feat: (LAR-107) Authentification avec Breeze (#216)
Stephen2304 a602c5a
feat(test): (LAR-86) adding test for bannished user
StevyMarlino 00009db
refact: (LAR-86) refactoring of the mail ban and unban
StevyMarlino c977b1c
fix: [LAR-116] publish scope on single tag articles list
mckenziearts 4bd49e1
feat(translation): (LAR-86) add translation for UserResource
StevyMarlino af8674d
fix: [LAR-116] publish scope on single tag articles list (#220)
StevyMarlino 6c2fe5b
fix (LAR-107) correction du fichier verify-email (#221)
Stephen2304 bc721e4
refactor: (LAR-86) refactoring test and translation 🥲
StevyMarlino 13e5282
feat: (LAR-86) add bannished sysem
StevyMarlino 10f30ba
feat(test): (LAR-86) add test
StevyMarlino a66589b
feat(test): (LAR-86) adding test for bannished user
StevyMarlino a2579b3
refact: (LAR-86) refactoring of the mail ban and unban
StevyMarlino 23691c1
feat(translation): (LAR-86) add translation for UserResource
StevyMarlino 7eef7be
refactor: (LAR-86) refactoring test and translation 🥲
StevyMarlino 7cdf064
Merge branch 'feature/lar-86-mettre-en-place-un-systeme-pour-bannir-u…
StevyMarlino 9133988
fix: (LAR-86) fixing phpstan error
StevyMarlino 2a9af9a
fix: (LAR-86) fix testing error 500
StevyMarlino 8c31f0f
Revert "fix: (LAR-86) fix testing error 500"
StevyMarlino 3cd63fd
fix: (LAR-86) update test file
StevyMarlino 381385f
fix(test): (LAR-86) fixing test bug
StevyMarlino 8f64dc0
refact: (LAR-86) change key message ban
StevyMarlino a3633d7
feat: (LAR-86) improvement to Banning function
StevyMarlino 02b039b
feat(test): (LAR-86) updating test and other file
StevyMarlino 0c221dc
fix(pint): (LAR-86) fixing laravel pint format
StevyMarlino 18eefd6
refact: (LAR-86) refactoring test email and other some files
StevyMarlino d6c731f
refact: (LAR-86) refactoring add ban migration
StevyMarlino File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,4 +37,4 @@ public function execute(CreateArticleData $articleData): Article | |
|
||
return $article; | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace App\Actions\User; | ||
|
||
use App\Models\User; | ||
use App\Events\UserBannedEvent; | ||
|
||
final class BanUserAction | ||
{ | ||
public function execute(User $user, string $reason): void | ||
{ | ||
if($user->banned_at == null) { | ||
$user->banned_at = now(); | ||
StevyMarlino marked this conversation as resolved.
Show resolved
Hide resolved
|
||
$user->banned_reason = $reason; | ||
$user->save(); | ||
|
||
event(new UserBannedEvent($user)); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace App\Actions\User; | ||
|
||
use App\Models\User; | ||
use App\Events\UserUnbannedEvent; | ||
|
||
final class UnBanUserAction | ||
{ | ||
public function execute(User $user) : void | ||
{ | ||
$user->banned_at = null; | ||
StevyMarlino marked this conversation as resolved.
Show resolved
Hide resolved
|
||
$user->banned_reason = null; | ||
$user->save(); | ||
|
||
event(new UserUnbannedEvent($user)); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,8 @@ | |
use App\Events\UserBannedEvent; | ||
use Filament\Resources\Resource; | ||
use App\Events\UserUnbannedEvent; | ||
use App\Actions\User\BanUserAction; | ||
use App\Actions\User\UnBanUserAction; | ||
use Filament\Forms\Components\TextInput; | ||
use Filament\Notifications\Notification; | ||
use Illuminate\Database\Eloquent\Builder; | ||
|
@@ -56,16 +58,16 @@ public static function table(Table $table): Table | |
->icon('untitledui-inbox') | ||
->description(fn ($record): ?string => $record->phone_number), | ||
Tables\Columns\TextColumn::make('email_verified_at') | ||
->label(__('global.ban.label.validate_email')) | ||
->label(__('user.validate_email')) | ||
->placeholder('N/A') | ||
->date(), | ||
Tables\Columns\TextColumn::make(name: 'created_at') | ||
->label(__('global.ban.label.inscription')) | ||
->label(__('use.inscription')) | ||
->date(), | ||
]) | ||
->filters([ | ||
Tables\Filters\TernaryFilter::make('email_verified_at') | ||
->label(__('global.ban.label.email_verified')) | ||
->label(__('user.email_verified')) | ||
->nullable(), | ||
]) | ||
->actions([ | ||
|
@@ -74,26 +76,44 @@ public static function table(Table $table): Table | |
->icon('untitledui-archive') | ||
->color('warning') | ||
->visible(fn ($record) => $record->banned_at == null) | ||
->modalHeading(__('global.ban.heading')) | ||
->modalDescription(__('global.ban.description')) | ||
->modalHeading(__('user.ban.heading')) | ||
->modalDescription(__('user.ban.description')) | ||
->form([ | ||
|
||
TextInput::make('banned_reason') | ||
->label(__('global.ban.reason')) | ||
->label(__('user.ban.reason')) | ||
->required(), | ||
]) | ||
->action(function (User $record, array $data) { | ||
if (!self::canBanUser($record)) { | ||
StevyMarlino marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Notification::make() | ||
->warning() | ||
->title(__('notifications.user.cannot.title')) | ||
->body(__('notifications.user.cannot.ban_admin')) | ||
->title(__('notifications.user.cannot_ban_title')) | ||
->body(__('notifications.user.cannot_ban_admin')) | ||
->duration(5000) | ||
->send(); | ||
|
||
return; | ||
} | ||
self::BanUserAction($record, $data['banned_reason']); | ||
|
||
if ($record->banned_at !== null) { | ||
StevyMarlino marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Notification::make() | ||
->warning() | ||
->title(__('notifications.user.cannot_ban_title')) | ||
->body(__('notifications.user.cannot_ban_body')) | ||
->send(); | ||
|
||
return; | ||
} | ||
|
||
app(BanUserAction::class)->execute($record, $data['banned_reason']); | ||
|
||
Notification::make() | ||
->success() | ||
->duration(5000) | ||
->title(__('notifications.user.banned_title')) | ||
->body(__('notifications.user.banned_body')) | ||
->send(); | ||
}) | ||
->requiresConfirmation(), | ||
|
||
|
@@ -103,7 +123,14 @@ public static function table(Table $table): Table | |
->color('success') | ||
->visible(fn ($record) => $record->banned_at !== null) | ||
->action(function (User $record) { | ||
self::UnbanUserAction($record); | ||
app(UnBanUserAction::class)->execute($record); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ajouter une Policy pour se rassurer de qui peut ban ou unban |
||
|
||
Notification::make() | ||
->success() | ||
->title(__('notifications.user.unbanned_title')) | ||
->duration(5000) | ||
->body(__('notifications.user.unbanned_body')) | ||
->send(); | ||
}) | ||
->requiresConfirmation(), | ||
|
||
|
@@ -121,48 +148,6 @@ public static function getPages(): array | |
]; | ||
} | ||
|
||
public static function BanUserAction(User $record, $reason): void | ||
{ | ||
if ($record->banned_at !== null) { | ||
Notification::make() | ||
->warning() | ||
->title(__('notifications.user.cannot.title')) | ||
->body(__('notifications.user.cannot.body')) | ||
->send(); | ||
|
||
return; | ||
} | ||
|
||
$record->banned_at = Carbon::now(); | ||
$record->banned_reason = $reason; | ||
$record->save(); | ||
|
||
Notification::make() | ||
->success() | ||
->duration(5000) | ||
->title(__('notifications.user.banned.title')) | ||
->body(__('notifications.user.banned.body')) | ||
->send(); | ||
|
||
event(new UserBannedEvent($record)); | ||
} | ||
|
||
public static function UnbanUserAction(User $record): void | ||
{ | ||
$record->banned_at = null; | ||
$record->banned_reason = null; | ||
$record->save(); | ||
|
||
Notification::make() | ||
->success() | ||
->title(__('notifications.user.unbanned.title')) | ||
->duration(5000) | ||
->body(__('notifications.user.unbanned.body')) | ||
->send(); | ||
|
||
event(new UserUnbannedEvent($record)); | ||
} | ||
|
||
public static function canBanUser(User $record): bool | ||
{ | ||
return !$record->hasRole('admin'); | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.