-
-
Notifications
You must be signed in to change notification settings - Fork 15
fea: (LAR-87) Mise en place des test pour la signalisation d'un contenu #222
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
mckenziearts
merged 5 commits into
develop
from
feature/LAR-87-signalisation-d-un-contenu
Nov 21, 2024
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7729e0e
feat: [LAR-87] update SpamReportActionTest
Stephen2304 2d0d07e
chore: rebase develop
mckenziearts 0f32fb7
feat: [LAR-87] add new spam report test
mckenziearts 55332a9
fix: phpstan
mckenziearts 8a05bf9
feat: [LAR-87] update test and create Trait for spamReports relation
mckenziearts 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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Actions; | ||
|
||
use App\Contracts\SpamReportableContract; | ||
use App\Exceptions\CanReportSpamException; | ||
use App\Models\User; | ||
use App\Notifications\ReportedSpamToTelegram; | ||
|
||
final class ReportSpamAction | ||
{ | ||
public function execute(User $user, SpamReportableContract $model, ?string $content = null): void | ||
{ | ||
if ($model->spamReports()->whereBelongsTo($user)->exists()) { | ||
throw new CanReportSpamException( | ||
message: __('notifications.exceptions.spam_exist'), | ||
); | ||
} | ||
|
||
$spam = $model->spamReports()->create([ | ||
'user_id' => $user->id, | ||
'reason' => $content, | ||
]); | ||
|
||
$user->notify(new ReportedSpamToTelegram($spam)); | ||
} | ||
} |
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,14 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Contracts; | ||
|
||
use Illuminate\Database\Eloquent\Relations\MorphMany; | ||
|
||
interface SpamReportableContract | ||
{ | ||
public function getPathUrl(): string; | ||
|
||
public function spamReports(): MorphMany; | ||
} | ||
mckenziearts marked this conversation as resolved.
Show resolved
Hide resolved
|
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,9 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Exceptions; | ||
|
||
use Exception; | ||
|
||
final class CanReportSpamException extends Exception {} |
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,66 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Livewire; | ||
|
||
use App\Actions\ReportSpamAction; | ||
use App\Contracts\SpamReportableContract; | ||
use App\Exceptions\CanReportSpamException; | ||
use Filament\Actions\Action; | ||
use Filament\Actions\Concerns\InteractsWithActions; | ||
use Filament\Actions\Contracts\HasActions; | ||
use Filament\Forms\Concerns\InteractsWithForms; | ||
use Filament\Forms\Contracts\HasForms; | ||
use Filament\Notifications\Notification; | ||
use Illuminate\Contracts\View\View; | ||
use Illuminate\Support\Facades\Auth; | ||
use Livewire\Component; | ||
|
||
final class ReportSpam extends Component implements HasActions, HasForms | ||
{ | ||
use InteractsWithActions; | ||
use InteractsWithForms; | ||
|
||
public SpamReportableContract $model; | ||
|
||
public ?string $reason = null; | ||
|
||
public function reportAction(): Action | ||
{ | ||
return Action::make('report') | ||
->color('danger') | ||
->badge() | ||
->label(__('pages/forum.report_spam')) | ||
->authorize('report', $this->model) // @phpstan-ignore-line | ||
->requiresConfirmation() | ||
->action(function (): void { | ||
try { | ||
app(ReportSpamAction::class)->execute( | ||
user: Auth::user(), // @phpstan-ignore-line | ||
model: $this->model, | ||
content: $this->reason, | ||
); | ||
|
||
Notification::make() | ||
->title(__('notifications.spam_send')) | ||
->success() | ||
->duration(3500) | ||
->send(); | ||
|
||
$this->reset('reason'); | ||
} catch (CanReportSpamException $e) { | ||
Notification::make() | ||
->title($e->getMessage()) | ||
->danger() | ||
->duration(3500) | ||
->send(); | ||
} | ||
}); | ||
} | ||
|
||
public function render(): View | ||
{ | ||
return view('livewire.components.report-spam'); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Models; | ||
|
||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Database\Eloquent\Relations\BelongsTo; | ||
use Illuminate\Database\Eloquent\Relations\MorphTo; | ||
|
||
/** | ||
* @property-read int $id | ||
* @property int $user_id | ||
* @property int $reportable_id | ||
* @property string $reportable_type | ||
* @property string | null $reason | ||
* @property User | null $user | ||
*/ | ||
final class SpamReport extends Model | ||
{ | ||
use HasFactory; | ||
|
||
protected $fillable = [ | ||
'user_id', | ||
'reportable_id', | ||
'reportable_type', | ||
'reason', | ||
]; | ||
|
||
public function user(): BelongsTo | ||
{ | ||
return $this->belongsTo(User::class); | ||
} | ||
|
||
public function reportable(): MorphTo | ||
{ | ||
return $this->morphTo(); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Notifications; | ||
|
||
use App\Models\SpamReport; | ||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Notifications\Notification; | ||
use NotificationChannels\Telegram\TelegramChannel; | ||
use NotificationChannels\Telegram\TelegramMessage; | ||
|
||
final class ReportedSpamToTelegram extends Notification | ||
{ | ||
use Queueable; | ||
|
||
public function __construct(public SpamReport $spamReport) {} | ||
|
||
public function via(object $notifiable): array | ||
{ | ||
return [TelegramChannel::class]; | ||
} | ||
|
||
public function toTelegram(): TelegramMessage | ||
{ | ||
return TelegramMessage::create() | ||
->to('@laravelcm') | ||
->content("{$this->spamReport->user?->name} vient de reporter un contenu spam") | ||
->button('Voir les spams', route('filament.admin.pages.dashboard')); | ||
StevyMarlino marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Traits; | ||
|
||
use App\Models\SpamReport; | ||
use Illuminate\Database\Eloquent\Relations\MorphMany; | ||
|
||
trait HasSpamReports | ||
{ | ||
public function spamReports(): MorphMany | ||
{ | ||
return $this->morphMany(SpamReport::class, 'reportable'); | ||
} | ||
} |
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.