Skip to content

Commit

Permalink
Banned Player Table (Undocumented) (#1559)
Browse files Browse the repository at this point in the history
* feat: add "Banned" table

* build: add psr violation check

* chore: fix psr mismatch

* test: add tests for banned players

* fix: add player-ban mock

* test: add latestBan seed
  • Loading branch information
iBotPeaches authored Jan 8, 2025
1 parent b783f31 commit f4fff43
Show file tree
Hide file tree
Showing 13 changed files with 193 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/laravel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ jobs:
- name: PHPCS
run: vendor/bin/pint --test

- name: Check PSR Violations
run: composer dump-autoload --strict-psr

- name: Execute tests (With Coverage) via PHPUnit
env:
DB_PORT: ${{ job.services.maria.ports[3306] }}
Expand Down
17 changes: 17 additions & 0 deletions app/Http/Controllers/ListController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace App\Http\Controllers;

use Artesaos\SEOTools\Facades\SEOTools;
use Illuminate\View\View;

class ListController extends Controller
{
public function banned(): View
{
SEOTools::setTitle(e('Banned Players'));
SEOTools::setDescription(e('Halo Infinite - Banned Players'));

return view('pages.lists.banned');
}
}
32 changes: 32 additions & 0 deletions app/Livewire/BannedPlayerTable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace App\Livewire;

use App\Models\Player;
use Illuminate\View\View;
use Livewire\Component;
use Livewire\WithPagination;

class BannedPlayerTable extends Component
{
use WithPagination;

public function paginationView(): string
{
return 'pagination::bulma';
}

public function render(): View
{
$players = Player::query()
->with('latestBan.player')
->whereHas('latestBan', fn ($query) => $query->whereDate('ends_at', '>=', now()))
->where('is_cheater', true)
->orderBy('gamertag')
->paginate();

return view('livewire.banned-player-table', [
'players' => $players,
]);
}
}
6 changes: 6 additions & 0 deletions app/Models/Player.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
* @property-read Collection<int, PlayerBan> $bans
* @property-read Collection<int, MedalAnalytic> $medals
* @property-read Collection<int, Analytic> $analytics
* @property-read PlayerBan|null $latestBan
* @property-read ServiceRecord $serviceRecord
* @property-read ServiceRecord $serviceRecordPvp
* @property-read string $url_safe_gamertag
Expand Down Expand Up @@ -419,6 +420,11 @@ public function bans(): HasMany
return $this->hasMany(PlayerBan::class);
}

public function latestBan(): HasOne
{
return $this->hasOne(PlayerBan::class)->latestOfMany();
}

public function medals(): HasMany
{
return $this->hasMany(MedalAnalytic::class);
Expand Down
12 changes: 12 additions & 0 deletions app/Models/PlayerBan.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
* @property string $scope
* @property-read Player $player
* @property-read bool $is_expired
* @property-read string $days_remaining
* @property-read string $short_message
*
* @method static PlayerBanFactory factory(...$parameters)
*/
Expand Down Expand Up @@ -49,6 +51,16 @@ public function getMessageAttribute(string $value): string
return (string) str_replace(array_keys($replacements), $replacements, $value);
}

public function getShortMessageAttribute(): string
{
return Str::beforeLast($this->message, $this->player->gamertag);
}

public function getDaysRemainingAttribute(): string
{
return number_format($this->ends_at->diffInDays(absolute: true));
}

public function getIsExpiredAttribute(): bool
{
return $this->ends_at->isPast();
Expand Down
60 changes: 60 additions & 0 deletions resources/views/livewire/banned-player-table.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php
/** @var App\Models\Player[] $players */
?>
<div>
<h1 class="title">Banned Halo Infinite Players</h1>
<h2 class="subtitle">A collection of banned players that Leaf knows about.</h2>
<div class="table-container">
<table class="table is-striped is-narrow is-hoverable is-fullwidth">
<thead>
<tr>
<th>Gamertag</th>
<th>Reason</th>
<th>Scope</th>
<th>Expiration</th>
</tr>
</thead>
<tbody>
@foreach ($players as $player)
<tr>
<td>
<article class="media">
<figure class="media-left">
<p class="image is-32x32">
<img src="{{ $player->emblem_url }}" alt="emblem">
</p>
</figure>
<div class="media-content">
<div class="content" style="white-space: nowrap">
@include('partials.links.player', ['player' => $player])
@if ($player->is_donator)
<span class="tag is-success" data-tooltip="Donated via BuyMeACoffee" style="border-bottom: 0;">
<i class="fas fa-leaf"></i>
</span>
@endif
@if ($player->is_cheater)
<span class="tag is-danger">Cheater</span>
@endif
@if ($player->is_botfarmer)
<span class="tag is-info">Farmer</span>
@endif
</div>
</div>
</article>
</td>
<td class="has-tooltip-arrow has-tooltip-text-left-mobile"
data-tooltip="{{ $player->latestBan->days_remaining }} days remaining"
>
{{ $player->latestBan->short_message }}
</td>
<td>{{ $player->latestBan->scope }}, {{ $player->latestBan->type }}</td>
<td>
{{ $player->latestBan->ends_at->toFormattedDateString() }}
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
{{ $players->links(data: ['scrollTo' => false]) }}
</div>
7 changes: 7 additions & 0 deletions resources/views/pages/lists/banned.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@extends('layouts.app')
@section('title', 'Banned Players')
@section('description', 'Banned Halo Infinite Players')

@section('content')
<livewire:banned-player-table />
@endsection
2 changes: 1 addition & 1 deletion resources/views/partials/player/ban-header.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
@if (! $ban->is_expired)
<br /><br />
<p class="is-size-7">
Days remaining: {{ number_format($ban->ends_at->diffInDays(absolute: true)) }}, for '{{ $ban->type }}', on scope: '{{ $ban->scope }}'
Days remaining: {{ $ban->days_remaining }}, for '{{ $ban->type }}', on scope: '{{ $ban->scope }}'
</p>
@endif
</div>
Expand Down
4 changes: 4 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use App\Http\Controllers\HcsController;
use App\Http\Controllers\HomeController;
use App\Http\Controllers\LeaderboardController;
use App\Http\Controllers\ListController;
use App\Http\Controllers\OverviewController;
use App\Http\Controllers\PlayerController;
use App\Http\Controllers\PlaylistController;
Expand Down Expand Up @@ -77,6 +78,9 @@
Route::get('/auth/google/callback', [GoogleController::class, 'callback'])->name('googleCallback');
Route::post('/auth/logout', [BaseAuthController::class, 'logout'])->name('logout');

// Lists
Route::get('/lists/banned', [ListController::class, 'banned'])->name('bannedList');

// Home
Route::get('/about', [HomeController::class, 'about'])->name('about');
Route::get('/legal', [HomeController::class, 'legal'])->name('legal');
Expand Down
29 changes: 29 additions & 0 deletions tests/Feature/Forms/BannedPlayerTable/ValidBannedPlayersTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace Tests\Feature\Forms\BannedPlayerTable;

use App\Livewire\BannedPlayerTable;
use App\Models\Player;
use App\Models\PlayerBan;
use Livewire\Livewire;
use Tests\TestCase;

class ValidBannedPlayersTest extends TestCase
{
public function test_valid_loading_of_banned_players(): void
{
// Arrange
$player = Player::factory()
->has(PlayerBan::factory(), 'latestBan')
->createOne([
'is_cheater' => true,
]);

// Act & Assert
Livewire::test(BannedPlayerTable::class)
->assertViewHas('players')
->assertSee($player->gamertag);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Feature\Forms\OverviewsTable;
namespace Tests\Feature\Forms\OverviewsTable;

use App\Livewire\OverviewsTable;
use App\Models\Overview;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Feature\Forms\PlayerBanCard;
namespace Tests\Feature\Forms\PlayerBanCard;

use App\Livewire\PlayerBanCard;
use App\Models\Player;
Expand Down
20 changes: 20 additions & 0 deletions tests/Feature/Pages/ListsPageTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace Tests\Feature\Pages;

use Symfony\Component\HttpFoundation\Response;
use Tests\TestCase;

class ListsPageTest extends TestCase
{
public function test_example_banned_players(): void
{
// Arrange & Act
$response = $this->get('/lists/banned');

// Assert
$response->assertStatus(Response::HTTP_OK);
}
}

0 comments on commit f4fff43

Please sign in to comment.