From e8ebf80fd11de75f6dbdbc051bee52cf8f50ddfd Mon Sep 17 00:00:00 2001 From: Andy Saw <7236312+andyksaw@users.noreply.github.com> Date: Sun, 13 Oct 2024 13:30:16 +0000 Subject: [PATCH] refactor: clean up repositories and old APIs (#803) --- app/AppServiceProvider.php | 12 - app/Core/Data/MinecraftUUID.php | 41 -- app/Core/Data/PlayerIdentifierType.php | 14 - .../PlayerLookup/Data/PlayerIdentifier.php | 43 -- .../InvalidMinecraftUUIDException.php | 12 - .../Exceptions/NoLinkedAccountException.php | 12 - .../NonCreatableIdentifierException.php | 12 - .../Exceptions/PlayerNotFoundException.php | 12 - app/Core/Domains/PlayerLookup/Player.php | 26 -- .../Service/ConcretePlayerLookup.php | 66 --- .../PlayerLookup/Service/PlayerLookup.php | 17 - .../PlayerLookup/Service/PlayerLookupMock.php | 25 -- .../Horizon/HorizonServiceProvider.php | 16 - app/Domains/Badges/UseCases/GetBadges.php | 18 +- .../BanAppeals/UseCases/CreateBanAppeal.php | 20 +- .../BanAppeals/UseCases/UpdateBanAppeal.php | 27 +- .../UseCases/ConvertToPermanentPlayerBan.php | 79 ---- app/Domains/Bans/UseCases/CreateIPBan.php | 34 +- app/Domains/Bans/UseCases/CreateIPUnban.php | 29 +- app/Domains/Bans/UseCases/CreatePlayerBan.php | 61 +-- .../Bans/UseCases/CreatePlayerUnban.php | 40 +- app/Domains/Bans/UseCases/GetActiveIPBan.php | 10 +- .../Bans/UseCases/GetActivePlayerBan.php | 22 +- .../Bans/UseCases/GetAllPlayerBans.php | 30 +- app/Domains/Bans/UseCases/LookupPlayerBan.php | 31 +- .../UseCases/CreateBuildRankApplication.php | 31 +- app/Domains/Donations/DonationsProvider.php | 32 -- .../Donations/UseCases/BeginCheckout.php | 10 +- .../Donations/UseCases/ProcessPayment.php | 74 ++-- app/Domains/Login/UseCases/LoginAccount.php | 2 - .../UseCases/UpdateSeenMinecraftPlayer.php | 16 +- .../Warnings/UseCases/AcknowledgeWarning.php | 30 -- .../Warnings/UseCases/CreateWarning.php | 44 -- app/Domains/Warnings/UseCases/GetWarnings.php | 31 -- .../Api/v1/MinecraftAggregateController.php | 16 +- .../Api/v1/MinecraftBadgeController.php | 7 +- .../Api/v1/MinecraftTelemetryController.php | 10 +- .../Api/v1/PlayerWarningController.php | 100 ----- .../Api/v2/GameIPBanController.php | 101 ----- .../Api/v2/GamePlayerBanController.php | 192 --------- .../Front/BanAppeal/BanLookupController.php | 16 +- .../BuilderRankApplicationController.php | 12 +- .../Controllers/Panel/BanAppealController.php | 9 +- .../Panel/BuilderRanksController.php | 7 +- .../Requests/AccountChangePasswordRequest.php | 1 - .../Requests/AccountSaveNewEmailRequest.php | 11 - .../Requests/SendPasswordEmailRequest.php | 1 - app/Models/MinecraftPlayer.php | 20 +- bootstrap/providers.php | 2 - repositories/BanAppealRepository.php | 67 ---- .../BuilderRankApplicationRepository.php | 57 --- repositories/DonationPerkRepository.php | 40 -- repositories/DonationRepository.php | 22 - .../GameIPBanEloquentRepository.php | 43 -- .../GameIPBans/GameIPBanMockRepository.php | 38 -- .../GameIPBans/GameIPBanRepository.php | 26 -- repositories/GamePlayerBanRepository.php | 65 --- .../MinecraftPlayerAliasRepository.php | 28 -- repositories/MinecraftPlayerRepository.php | 32 -- repositories/PaymentRepository.php | 30 -- repositories/PlayerFetchRepository.php | 38 -- .../PlayerWarningEloquentRepository.php | 49 --- .../PlayerWarningMockRepository.php | 44 -- .../PlayerWarningRepository.php | 26 -- repositories/StripeProductRepository.php | 18 - routes/api_v2.php | 23 -- tests/Integration/Api/APIBanAllTest.php | 115 ------ tests/Integration/Api/APIBanCreateTest.php | 187 --------- tests/Integration/Api/APIBanIPCreateTest.php | 103 ----- tests/Integration/Api/APIBanIPStatusTest.php | 98 ----- tests/Integration/Api/APIBanStatusTest.php | 187 --------- .../Api/APIMinecraftAggregateTest.php | 377 +++++++++--------- .../Api/APIMinecraftTelemetryTest.php | 148 +++++-- tests/Integration/Api/APIUnbanCreateTest.php | 130 ------ .../Integration/Api/APIUnbanIPCreateTest.php | 95 ----- .../Api/APIWarningAcknowledgeTest.php | 93 ----- tests/Integration/Api/APIWarningAllTest.php | 105 ----- .../Integration/Api/APIWarningCreateTest.php | 78 ---- .../Api/v3/MinecraftRegisterCompleteTest.php | 3 - .../Api/v3/MinecraftRegisterCreateTest.php | 1 - tests/Integration/Front/BanLookupTest.php | 18 +- tests/IntegrationTestCase.php | 2 + .../PlayerLookup/ConcretePlayerLookupTest.php | 187 --------- .../UseCases/CreateBanAppealTest.php | 132 ------ .../UseCases/UpdateBanAppealTest.php | 147 ------- .../Domain/Bans/UseCases/CreateBanTest.php | 93 ----- .../Domain/Bans/UseCases/LookupBanTest.php | 118 ------ .../UpdateSeenMinecraftPlayerTest.php | 84 ---- .../UseCases/AcknowledgeWarningTest.php | 102 ----- .../Warnings/UseCases/CreateWarningTest.php | 52 --- .../Warnings/UseCases/GetWarningsTest.php | 75 ---- 91 files changed, 539 insertions(+), 4321 deletions(-) delete mode 100644 app/Core/Data/MinecraftUUID.php delete mode 100644 app/Core/Data/PlayerIdentifierType.php delete mode 100644 app/Core/Domains/PlayerLookup/Data/PlayerIdentifier.php delete mode 100644 app/Core/Domains/PlayerLookup/Exceptions/InvalidMinecraftUUIDException.php delete mode 100644 app/Core/Domains/PlayerLookup/Exceptions/NoLinkedAccountException.php delete mode 100644 app/Core/Domains/PlayerLookup/Exceptions/NonCreatableIdentifierException.php delete mode 100644 app/Core/Domains/PlayerLookup/Exceptions/PlayerNotFoundException.php delete mode 100644 app/Core/Domains/PlayerLookup/Player.php delete mode 100644 app/Core/Domains/PlayerLookup/Service/ConcretePlayerLookup.php delete mode 100644 app/Core/Domains/PlayerLookup/Service/PlayerLookup.php delete mode 100644 app/Core/Domains/PlayerLookup/Service/PlayerLookupMock.php delete mode 100644 app/Core/Support/Horizon/HorizonServiceProvider.php delete mode 100644 app/Domains/Bans/UseCases/ConvertToPermanentPlayerBan.php delete mode 100644 app/Domains/Donations/DonationsProvider.php delete mode 100644 app/Domains/Warnings/UseCases/AcknowledgeWarning.php delete mode 100644 app/Domains/Warnings/UseCases/CreateWarning.php delete mode 100644 app/Domains/Warnings/UseCases/GetWarnings.php delete mode 100644 app/Http/Controllers/Api/v1/PlayerWarningController.php delete mode 100644 app/Http/Controllers/Api/v2/GameIPBanController.php delete mode 100644 app/Http/Controllers/Api/v2/GamePlayerBanController.php delete mode 100644 repositories/BanAppealRepository.php delete mode 100644 repositories/BuilderRankApplicationRepository.php delete mode 100644 repositories/DonationPerkRepository.php delete mode 100644 repositories/DonationRepository.php delete mode 100644 repositories/GameIPBans/GameIPBanEloquentRepository.php delete mode 100644 repositories/GameIPBans/GameIPBanMockRepository.php delete mode 100644 repositories/GameIPBans/GameIPBanRepository.php delete mode 100644 repositories/GamePlayerBanRepository.php delete mode 100644 repositories/MinecraftPlayerAliasRepository.php delete mode 100644 repositories/MinecraftPlayerRepository.php delete mode 100644 repositories/PaymentRepository.php delete mode 100644 repositories/PlayerFetchRepository.php delete mode 100644 repositories/PlayerWarnings/PlayerWarningEloquentRepository.php delete mode 100644 repositories/PlayerWarnings/PlayerWarningMockRepository.php delete mode 100644 repositories/PlayerWarnings/PlayerWarningRepository.php delete mode 100644 repositories/StripeProductRepository.php delete mode 100644 tests/Integration/Api/APIBanAllTest.php delete mode 100644 tests/Integration/Api/APIBanCreateTest.php delete mode 100644 tests/Integration/Api/APIBanIPCreateTest.php delete mode 100644 tests/Integration/Api/APIBanIPStatusTest.php delete mode 100644 tests/Integration/Api/APIBanStatusTest.php delete mode 100644 tests/Integration/Api/APIUnbanCreateTest.php delete mode 100644 tests/Integration/Api/APIUnbanIPCreateTest.php delete mode 100644 tests/Integration/Api/APIWarningAcknowledgeTest.php delete mode 100644 tests/Integration/Api/APIWarningAllTest.php delete mode 100644 tests/Integration/Api/APIWarningCreateTest.php delete mode 100644 tests/Unit/App/Core/Domains/PlayerLookup/ConcretePlayerLookupTest.php delete mode 100644 tests/Unit/Domain/BanAppeals/UseCases/CreateBanAppealTest.php delete mode 100644 tests/Unit/Domain/BanAppeals/UseCases/UpdateBanAppealTest.php delete mode 100644 tests/Unit/Domain/Bans/UseCases/CreateBanTest.php delete mode 100644 tests/Unit/Domain/Bans/UseCases/LookupBanTest.php delete mode 100644 tests/Unit/Domain/MinecraftTelemetry/UseCases/UpdateSeenMinecraftPlayerTest.php delete mode 100644 tests/Unit/Domain/Warnings/UseCases/AcknowledgeWarningTest.php delete mode 100644 tests/Unit/Domain/Warnings/UseCases/CreateWarningTest.php delete mode 100644 tests/Unit/Domain/Warnings/UseCases/GetWarningsTest.php diff --git a/app/AppServiceProvider.php b/app/AppServiceProvider.php index 57e495afd..93d7f1fbe 100644 --- a/app/AppServiceProvider.php +++ b/app/AppServiceProvider.php @@ -26,10 +26,6 @@ use Illuminate\Support\Facades\RateLimiter; use Illuminate\Support\ServiceProvider; use Illuminate\Validation\Rules\Password; -use Repositories\GameIPBans\GameIPBanEloquentRepository; -use Repositories\GameIPBans\GameIPBanRepository; -use Repositories\PlayerWarnings\PlayerWarningEloquentRepository; -use Repositories\PlayerWarnings\PlayerWarningRepository; use Stripe\StripeClient; final class AppServiceProvider extends ServiceProvider @@ -48,14 +44,6 @@ public function register() abstract: PlayerLookup::class, concrete: ConcretePlayerLookup::class, ); - $this->app->bind( - abstract: GameIPBanRepository::class, - concrete: GameIPBanEloquentRepository::class, - ); - $this->app->bind( - abstract: PlayerWarningRepository::class, - concrete: PlayerWarningEloquentRepository::class, - ); } /** diff --git a/app/Core/Data/MinecraftUUID.php b/app/Core/Data/MinecraftUUID.php deleted file mode 100644 index 1f3d757cc..000000000 --- a/app/Core/Data/MinecraftUUID.php +++ /dev/null @@ -1,41 +0,0 @@ -uuid = str_replace(search: '-', replace: '', subject: $rawValue); - } - - public function __toString(): string - { - return $this->uuid; - } - - public function rawValue(): string - { - return $this->uuid; - } - - public function hyphenated(): string - { - $parts = [ - substr(string: $this->uuid, offset: 0, length: 8), - substr(string: $this->uuid, offset: 8, length: 4), - substr(string: $this->uuid, offset: 12, length: 4), - substr(string: $this->uuid, offset: 16, length: 4), - substr(string: $this->uuid, offset: 20), - ]; - - return collect($parts)->join(glue: '-'); - } -} diff --git a/app/Core/Data/PlayerIdentifierType.php b/app/Core/Data/PlayerIdentifierType.php deleted file mode 100644 index f444df111..000000000 --- a/app/Core/Data/PlayerIdentifierType.php +++ /dev/null @@ -1,14 +0,0 @@ -gameIdentifierType) { - PlayerIdentifierType::MINECRAFT_UUID => $this->minecraftPlayerRepository->getByUUID(new MinecraftUUID($identifier->key)), - PlayerIdentifierType::PCB_PLAYER_ID => $this->minecraftPlayerRepository->getById($identifier->key), - }; - } - - public function findOrCreate( - PlayerIdentifier $identifier, - ?string $playerAlias = null, - ): Player { - return $this->find($identifier) - ?? $this->create(identifier: $identifier, playerAlias: $playerAlias); - } - - /** - * @throws NonCreatableIdentifierException - */ - private function create( - PlayerIdentifier $identifier, - ?string $playerAlias = null, - ): Player { - $player = null; - - switch ($identifier->gameIdentifierType) { - case PlayerIdentifierType::MINECRAFT_UUID: - $uuid = new MinecraftUUID($identifier->key); - $player = $this->minecraftPlayerRepository->store($uuid); - - if (! empty($playerAlias)) { - $this->minecraftPlayerAliasRepository->store( - minecraftPlayerId: $player->getKey(), - alias: $playerAlias, - registeredAt: now(), - ); - } - break; - case PlayerIdentifierType::PCB_PLAYER_ID: - throw new NonCreatableIdentifierException(); - } - - return $player; - } -} diff --git a/app/Core/Domains/PlayerLookup/Service/PlayerLookup.php b/app/Core/Domains/PlayerLookup/Service/PlayerLookup.php deleted file mode 100644 index 71ac8e3d4..000000000 --- a/app/Core/Domains/PlayerLookup/Service/PlayerLookup.php +++ /dev/null @@ -1,17 +0,0 @@ -find; - } - - public function findOrCreate( - PlayerIdentifier $identifier, - ?string $playerAlias = null, - ): Player { - return $this->findOrCreate; - } -} diff --git a/app/Core/Support/Horizon/HorizonServiceProvider.php b/app/Core/Support/Horizon/HorizonServiceProvider.php deleted file mode 100644 index a1aa72837..000000000 --- a/app/Core/Support/Horizon/HorizonServiceProvider.php +++ /dev/null @@ -1,16 +0,0 @@ -isAdmin(); - }); - } -} diff --git a/app/Domains/Badges/UseCases/GetBadges.php b/app/Domains/Badges/UseCases/GetBadges.php index 93d4aca2e..10e0577d5 100644 --- a/app/Domains/Badges/UseCases/GetBadges.php +++ b/app/Domains/Badges/UseCases/GetBadges.php @@ -2,22 +2,20 @@ namespace App\Domains\Badges\UseCases; -use App\Core\Domains\PlayerLookup\Data\PlayerIdentifier; -use App\Core\Domains\PlayerLookup\Service\PlayerLookup; +use App\Core\Domains\MinecraftUUID\Data\MinecraftUUID; use App\Models\Badge; +use App\Models\MinecraftPlayer; final class GetBadges { - public function __construct( - private readonly PlayerLookup $playerLookup, - ) {} - - public function execute(PlayerIdentifier $identifier): array + public function execute(MinecraftUUID $uuid): array { - $account = $this->playerLookup - ->find(identifier: $identifier) - ?->getLinkedAccount(); + $player = MinecraftPlayer::whereUuid($uuid)->first(); + if ($player === null) { + return []; + } + $account = $player->account; if ($account === null) { return []; } diff --git a/app/Domains/BanAppeals/UseCases/CreateBanAppeal.php b/app/Domains/BanAppeals/UseCases/CreateBanAppeal.php index 828f2e560..963fe364d 100644 --- a/app/Domains/BanAppeals/UseCases/CreateBanAppeal.php +++ b/app/Domains/BanAppeals/UseCases/CreateBanAppeal.php @@ -2,20 +2,15 @@ namespace App\Domains\BanAppeals\UseCases; +use App\Domains\BanAppeals\Entities\BanAppealStatus; use App\Domains\BanAppeals\Exceptions\EmailRequiredException; use App\Domains\BanAppeals\Notifications\BanAppealConfirmationNotification; use App\Models\Account; use App\Models\BanAppeal; use App\Models\GamePlayerBan; -use Repositories\BanAppealRepository; final class CreateBanAppeal { - public function __construct( - private readonly BanAppealRepository $banAppealRepository - ) { - } - /** * Returns whether an account owns the player associated with a ban * @@ -42,12 +37,13 @@ public function execute( throw new EmailRequiredException(); } - $banAppeal = $this->banAppealRepository->create( - gamePlayerBanId: $ban->getKey(), - isAccountVerified: $isAccountVerified, - explanation: $explanation, - email: $email - ); + $banAppeal = BanAppeal::create([ + 'game_ban_id' => $ban->getKey(), + 'is_account_verified' => $isAccountVerified, + 'explanation' => $explanation, + 'email' => $email, + 'status' => BanAppealStatus::PENDING, + ]); $banAppeal->notify(new BanAppealConfirmationNotification($banAppeal)); diff --git a/app/Domains/BanAppeals/UseCases/UpdateBanAppeal.php b/app/Domains/BanAppeals/UseCases/UpdateBanAppeal.php index 2f94185f0..aa412cfe0 100644 --- a/app/Domains/BanAppeals/UseCases/UpdateBanAppeal.php +++ b/app/Domains/BanAppeals/UseCases/UpdateBanAppeal.php @@ -3,6 +3,7 @@ namespace App\Domains\BanAppeals\UseCases; use App\Core\Data\Exceptions\NotImplementedException; +use App\Core\Domains\MinecraftUUID\Data\MinecraftUUID; use App\Core\Domains\PlayerLookup\Data\PlayerIdentifier; use App\Domains\BanAppeals\Entities\BanAppealStatus; use App\Domains\BanAppeals\Exceptions\AppealAlreadyDecidedException; @@ -14,12 +15,10 @@ use App\Models\BanAppeal; use Exception; use Illuminate\Support\Facades\DB; -use Repositories\BanAppealRepository; class UpdateBanAppeal { public function __construct( - private readonly BanAppealRepository $banAppealRepository, private readonly CreatePlayerUnban $unbanUseCase ) { } @@ -59,20 +58,24 @@ public function execute( try { DB::beginTransaction(); - $this->banAppealRepository->updateDecision( - banAppeal: $banAppeal, - decisionNote: $decisionNote, - deciderPlayerMinecraftId: $decidingPlayer->getKey(), - status: $status, - ); + + $banAppeal->decision_note = $decisionNote; + $banAppeal->decider_player_minecraft_id = $decidingPlayer->getKey(); + $banAppeal->status = $status; + $banAppeal->decided_at = now(); + $banAppeal->save(); + + activity() + ->on($banAppeal) + ->log(strtolower($status->humanReadable())); if ($status == BanAppealStatus::ACCEPTED_UNBAN) { - $bannedPlayerIdentifier = PlayerIdentifier::pcbAccountId($banAppeal->gamePlayerBan->bannedPlayer->getKey()); - $staffPlayerIdentifier = PlayerIdentifier::pcbAccountId($decidingPlayer->getKey()); + $bannedPlayerUuid = new MinecraftUUID($banAppeal->gamePlayerBan->bannedPlayer->uuid); + $staffPlayerIdentifier = new MinecraftUUID($decidingPlayer->uuid); $this->unbanUseCase->execute( - bannedPlayerIdentifier: $bannedPlayerIdentifier, - unbannerPlayerIdentifier: $staffPlayerIdentifier, + bannedPlayerUuid: $bannedPlayerUuid, + unbannerPlayerUuid: $staffPlayerIdentifier, unbanType: UnbanType::APPEALED, ); } diff --git a/app/Domains/Bans/UseCases/ConvertToPermanentPlayerBan.php b/app/Domains/Bans/UseCases/ConvertToPermanentPlayerBan.php deleted file mode 100644 index c26cf4c0a..000000000 --- a/app/Domains/Bans/UseCases/ConvertToPermanentPlayerBan.php +++ /dev/null @@ -1,79 +0,0 @@ -gamePlayerBanRepository->find($banId); - if ($ban === null) { - throw new NotFoundException(id: 'ban_not_found', message: 'Cannot find a ban matching the given id'); - } - if (! $ban->isActive()) { - throw new Exception('Cannot modify an inactive ban'); - } - if ($ban->expires_at === null) { - throw new Exception('The given ban id is already a permanent ban'); - } - - $bannerPlayer = $this->playerLookup->findOrCreate( - identifier: $bannerPlayerIdentifier, - playerAlias: $bannerPlayerAlias, - ); - - DB::beginTransaction(); - try { - $ban->unbanned_at = now(); - $ban->unbanned_by = $bannerPlayer->getKey(); - $ban->unban_type = UnbanType::CONVERTED_TO_PERMANENT; - $ban->save(); - - $newBan = $this->gamePlayerBanRepository->create( - serverId: $ban->serverId, - bannedPlayerId: $ban->banned_player_id, - bannedPlayerAlias: $ban->banned_alias_at_time, - bannerPlayerId: $bannerPlayer->getKey(), - reason: $banReason ?: $ban->reason, - expiresAt: null, - ); - DB::commit(); - - return $newBan; - } catch (Throwable $e) { - DB::rollBack(); - throw $e; - } - } -} diff --git a/app/Domains/Bans/UseCases/CreateIPBan.php b/app/Domains/Bans/UseCases/CreateIPBan.php index 43e6d5d4f..289367bd1 100644 --- a/app/Domains/Bans/UseCases/CreateIPBan.php +++ b/app/Domains/Bans/UseCases/CreateIPBan.php @@ -2,40 +2,36 @@ namespace App\Domains\Bans\UseCases; -use App\Core\Domains\PlayerLookup\Data\PlayerIdentifier; -use App\Core\Domains\PlayerLookup\Service\PlayerLookup; +use App\Core\Domains\MinecraftUUID\Data\MinecraftUUID; use App\Domains\Bans\Exceptions\AlreadyIPBannedException; use App\Models\GameIPBan; -use Repositories\GameIPBans\GameIPBanRepository; +use App\Models\MinecraftPlayer; final class CreateIPBan { - public function __construct( - private readonly GameIPBanRepository $gameIPBanRepository, - private readonly PlayerLookup $playerLookup, - ) { - } - public function execute( string $ip, - PlayerIdentifier $bannerPlayerIdentifier, + MinecraftUUID $bannerPlayerUuid, string $bannerPlayerAlias, string $banReason, ): GameIPBan { - $existingBan = $this->gameIPBanRepository->firstActive(ip: $ip); + $existingBan = GameIPBan::where('ip_address', $ip) + ->whereNull('unbanned_at') + ->first(); + if ($existingBan !== null) { throw new AlreadyIPBannedException(); } - $bannerPlayer = $this->playerLookup->findOrCreate( - identifier: $bannerPlayerIdentifier, - playerAlias: $bannerPlayerAlias, + $bannerPlayer = MinecraftPlayer::firstOrCreate( + uuid: $bannerPlayerUuid, + alias: $bannerPlayerAlias, ); - return $this->gameIPBanRepository->create( - ip: $ip, - bannerPlayerId: $bannerPlayer->getKey(), - reason: $banReason, - ); + return GameIPBan::create([ + 'banner_player_id' => $bannerPlayer->getKey(), + 'ip_address' => $ip, + 'reason' => $banReason, + ]); } } diff --git a/app/Domains/Bans/UseCases/CreateIPUnban.php b/app/Domains/Bans/UseCases/CreateIPUnban.php index 8cb9e2d5f..e8797e459 100644 --- a/app/Domains/Bans/UseCases/CreateIPUnban.php +++ b/app/Domains/Bans/UseCases/CreateIPUnban.php @@ -2,36 +2,31 @@ namespace App\Domains\Bans\UseCases; -use App\Core\Domains\PlayerLookup\Data\PlayerIdentifier; -use App\Core\Domains\PlayerLookup\Service\PlayerLookup; +use App\Core\Domains\MinecraftUUID\Data\MinecraftUUID; use App\Domains\Bans\Data\UnbanType; use App\Domains\Bans\Exceptions\NotIPBannedException; use App\Models\GameIPBan; -use Repositories\GameIPBans\GameIPBanRepository; +use App\Models\MinecraftPlayer; class CreateIPUnban { - public function __construct( - private readonly GameIPBanRepository $gameIPBanRepository, - private readonly PlayerLookup $playerLookup, - ) { - } - public function execute( string $ip, - PlayerIdentifier $unbannerPlayerIdentifier, + MinecraftUUID $unbannerPlayerUuid, UnbanType $unbanType, ): GameIPBan { - $existingBan = $this->gameIPBanRepository->firstActive(ip: $ip) + $existingBan = GameIPBan::where('ip_address', $ip) + ->whereNull('unbanned_at') + ->first() ?? throw new NotIPBannedException(); - $unbannerPlayer = $this->playerLookup->findOrCreate(identifier: $unbannerPlayerIdentifier); + $unbannerPlayer = MinecraftPlayer::firstOrCreate(uuid: $unbannerPlayerUuid); - $this->gameIPBanRepository->unban( - ban: $existingBan, - unbannerPlayerId: $unbannerPlayer->getKey(), - unbanType: $unbanType, - ); + $existingBan->update([ + 'unbanned_at' => now(), + 'unbanner_player_id' => $unbannerPlayer->getKey(), + 'unban_type' => $unbanType->value, + ]); return $existingBan->refresh(); } diff --git a/app/Domains/Bans/UseCases/CreatePlayerBan.php b/app/Domains/Bans/UseCases/CreatePlayerBan.php index c55a1e036..83b26b485 100644 --- a/app/Domains/Bans/UseCases/CreatePlayerBan.php +++ b/app/Domains/Bans/UseCases/CreatePlayerBan.php @@ -2,50 +2,33 @@ namespace App\Domains\Bans\UseCases; -use App\Core\Domains\PlayerLookup\Data\PlayerIdentifier; -use App\Core\Domains\PlayerLookup\Service\PlayerLookup; +use App\Core\Domains\MinecraftUUID\Data\MinecraftUUID; use App\Domains\Bans\Exceptions\AlreadyPermBannedException; use App\Domains\Bans\Exceptions\AlreadyTempBannedException; use App\Models\GamePlayerBan; +use App\Models\MinecraftPlayer; use Illuminate\Support\Carbon; -use Repositories\GamePlayerBanRepository; final class CreatePlayerBan { - public function __construct( - private readonly GamePlayerBanRepository $gamePlayerBanRepository, - private readonly PlayerLookup $playerLookup, - ) { - } - - /** - * @param int $serverId ID of the server the player was banned on - * @param PlayerIdentifier $bannedPlayerIdentifier Player to be banned - * @param string $bannedPlayerAlias Name of the player at the time of ban - * @param PlayerIdentifier $bannerPlayerIdentifier Player that created the ban - * @param string $bannerPlayerAlias Name of the player that created the ban at the time - * @param string|null $banReason Reason the player was banned - * @param Carbon|null $expiresAt Date the ban will expire. If null, ban is permanent - * @return GamePlayerBan - * - * @throws AlreadyTempBannedException if a player is already banned temporarily - * @throws AlreadyPermBannedException if player is already banned permanently - */ public function execute( int $serverId, - PlayerIdentifier $bannedPlayerIdentifier, + MinecraftUUID $bannedPlayerUuid, string $bannedPlayerAlias, - PlayerIdentifier $bannerPlayerIdentifier, + MinecraftUUID $bannerPlayerUuid, string $bannerPlayerAlias, ?string $banReason, ?Carbon $expiresAt, ): GamePlayerBan { - $bannedPlayer = $this->playerLookup->findOrCreate( - identifier: $bannedPlayerIdentifier, - playerAlias: $bannedPlayerAlias, + $bannedPlayer = MinecraftPlayer::firstOrCreate( + uuid: $bannedPlayerUuid, + alias: $bannedPlayerAlias, ); - $existingBan = $this->gamePlayerBanRepository->firstActiveBan(player: $bannedPlayer); + $existingBan = GamePlayerBan::where('banned_player_id', $bannedPlayer->getKey()) + ->active() + ->first(); + if ($existingBan !== null) { if ($existingBan->isTemporaryBan()) { throw new AlreadyTempBannedException(); @@ -53,18 +36,18 @@ public function execute( throw new AlreadyPermBannedException(); } - $bannerPlayer = $this->playerLookup->findOrCreate( - identifier: $bannerPlayerIdentifier, - playerAlias: $bannerPlayerAlias, + $bannerPlayer = MinecraftPlayer::firstOrCreate( + uuid: $bannerPlayerUuid, + alias: $bannerPlayerAlias, ); - return $this->gamePlayerBanRepository->create( - serverId: $serverId, - bannedPlayerId: $bannedPlayer->getKey(), - bannedPlayerAlias: $bannedPlayerAlias, - bannerPlayerId: $bannerPlayer->getKey(), - reason: $banReason, - expiresAt: $expiresAt, - ); + return GamePlayerBan::create([ + 'server_id' => $serverId, + 'banned_player_id' => $bannedPlayer->getKey(), + 'banned_alias_at_time' => $bannedPlayerAlias, + 'banner_player_id' => $bannerPlayer->getKey(), + 'reason' => $banReason, + 'expires_at' => $expiresAt, + ]); } } diff --git a/app/Domains/Bans/UseCases/CreatePlayerUnban.php b/app/Domains/Bans/UseCases/CreatePlayerUnban.php index 6117d1335..42fe76af1 100644 --- a/app/Domains/Bans/UseCases/CreatePlayerUnban.php +++ b/app/Domains/Bans/UseCases/CreatePlayerUnban.php @@ -2,46 +2,34 @@ namespace App\Domains\Bans\UseCases; -use App\Core\Domains\PlayerLookup\Data\PlayerIdentifier; -use App\Core\Domains\PlayerLookup\Service\PlayerLookup; +use App\Core\Domains\MinecraftUUID\Data\MinecraftUUID; use App\Domains\Bans\Data\UnbanType; use App\Domains\Bans\Exceptions\NotBannedException; use App\Models\GamePlayerBan; -use Repositories\GamePlayerBanRepository; +use App\Models\MinecraftPlayer; class CreatePlayerUnban { - public function __construct( - private readonly GamePlayerBanRepository $gamePlayerBanRepository, - private readonly PlayerLookup $playerLookup, - ) { - } - - /** - * @param PlayerIdentifier $bannedPlayerIdentifier Player currently banned - * @param PlayerIdentifier $unbannerPlayerIdentifier Player unbanning the banned player - * @return GamePlayerBan - * - * @throws NotBannedException if the banned player is not actually banned - */ public function execute( - PlayerIdentifier $bannedPlayerIdentifier, - PlayerIdentifier $unbannerPlayerIdentifier, + MinecraftUUID $bannedPlayerUuid, + MinecraftUUID $unbannerPlayerUuid, UnbanType $unbanType, ): GamePlayerBan { - $player = $this->playerLookup->find(identifier: $bannedPlayerIdentifier) + $player = MinecraftPlayer::whereUuid($bannedPlayerUuid)->first() ?? throw new NotBannedException(); - $existingBan = $this->gamePlayerBanRepository->firstActiveBan(player: $player) + $existingBan = GamePlayerBan::where('banned_player_id', $player->getKey()) + ->active() + ->first() ?? throw new NotBannedException(); - $unbannerPlayer = $this->playerLookup->findOrCreate(identifier: $unbannerPlayerIdentifier); + $unbannerPlayer = MinecraftPlayer::whereUuid($unbannerPlayerUuid)->first(); - $this->gamePlayerBanRepository->unban( - ban: $existingBan, - unbannerPlayerId: $unbannerPlayer->getKey(), - unbanType: $unbanType, - ); + $existingBan->update([ + 'unbanned_at' => now(), + 'unbanner_player_id' => $unbannerPlayer->getKey(), + 'unban_type' => $unbanType->value, + ]); return $existingBan->refresh(); } diff --git a/app/Domains/Bans/UseCases/GetActiveIPBan.php b/app/Domains/Bans/UseCases/GetActiveIPBan.php index 74d6652dd..2d2ff10c1 100644 --- a/app/Domains/Bans/UseCases/GetActiveIPBan.php +++ b/app/Domains/Bans/UseCases/GetActiveIPBan.php @@ -3,17 +3,13 @@ namespace App\Domains\Bans\UseCases; use App\Models\GameIPBan; -use Repositories\GameIPBans\GameIPBanRepository; final class GetActiveIPBan { - public function __construct( - private readonly GameIPBanRepository $gameIPBanRepository, - ) { - } - public function execute(string $ip): ?GameIPBan { - return $this->gameIPBanRepository->firstActive(ip: $ip); + return GameIPBan::where('ip_address', $ip) + ->whereNull('unbanned_at') + ->first(); } } diff --git a/app/Domains/Bans/UseCases/GetActivePlayerBan.php b/app/Domains/Bans/UseCases/GetActivePlayerBan.php index 5f6dc756c..6d467d0bf 100644 --- a/app/Domains/Bans/UseCases/GetActivePlayerBan.php +++ b/app/Domains/Bans/UseCases/GetActivePlayerBan.php @@ -2,27 +2,21 @@ namespace App\Domains\Bans\UseCases; -use App\Core\Domains\PlayerLookup\Data\PlayerIdentifier; -use App\Core\Domains\PlayerLookup\Service\PlayerLookup; +use App\Core\Domains\MinecraftUUID\Data\MinecraftUUID; use App\Models\GamePlayerBan; -use Repositories\GamePlayerBanRepository; +use App\Models\MinecraftPlayer; final class GetActivePlayerBan { - public function __construct( - private readonly GamePlayerBanRepository $gamePlayerBanRepository, - private readonly PlayerLookup $playerLookup, - ) { - } - - public function execute( - PlayerIdentifier $playerIdentifier, - ): ?GamePlayerBan { - $player = $this->playerLookup->find($playerIdentifier); + public function execute(MinecraftUUID $uuid): ?GamePlayerBan + { + $player = MinecraftPlayer::whereUuid($uuid)->first(); if ($player === null) { return null; } - return $this->gamePlayerBanRepository->firstActiveBan(player: $player); + return GamePlayerBan::where('banned_player_id', $player->getKey()) + ->active() + ->first(); } } diff --git a/app/Domains/Bans/UseCases/GetAllPlayerBans.php b/app/Domains/Bans/UseCases/GetAllPlayerBans.php index 7af13f777..8762ae8b0 100644 --- a/app/Domains/Bans/UseCases/GetAllPlayerBans.php +++ b/app/Domains/Bans/UseCases/GetAllPlayerBans.php @@ -2,32 +2,22 @@ namespace App\Domains\Bans\UseCases; -use App\Core\Domains\PlayerLookup\Data\PlayerIdentifier; -use App\Core\Domains\PlayerLookup\Service\PlayerLookup; +use App\Core\Domains\MinecraftUUID\Data\MinecraftUUID; +use App\Models\GamePlayerBan; +use App\Models\MinecraftPlayer; use Illuminate\Support\Collection; -use Repositories\GamePlayerBanRepository; final class GetAllPlayerBans { - public function __construct( - private readonly GamePlayerBanRepository $gamePlayerBanRepository, - private readonly PlayerLookup $playerLookup, - ) { - } - - /** - * @param PlayerIdentifier $playerIdentifier - * @return Collection - */ - public function execute( - PlayerIdentifier $playerIdentifier, - ): Collection { - $player = $this->playerLookup->find($playerIdentifier); + public function execute(MinecraftUUID $uuid): Collection + { + $player = MinecraftPlayer::whereUuid($uuid)->first(); if ($player === null) { return collect(); } - $bans = $this->gamePlayerBanRepository->all(player: $player); - - return $bans; + return GamePlayerBan::where('banned_player_id', $player->getKey()) + ->orderBy('created_at', 'desc') + ->limit(25) + ->get(); } } diff --git a/app/Domains/Bans/UseCases/LookupPlayerBan.php b/app/Domains/Bans/UseCases/LookupPlayerBan.php index 11ae1ab7c..d9b67a6e5 100644 --- a/app/Domains/Bans/UseCases/LookupPlayerBan.php +++ b/app/Domains/Bans/UseCases/LookupPlayerBan.php @@ -2,46 +2,35 @@ namespace App\Domains\Bans\UseCases; -use App\Core\Data\Exceptions\TooManyRequestsException; -use App\Core\Data\MinecraftUUID; use App\Core\Domains\Mojang\Api\MojangPlayerApi; -use App\Core\Domains\PlayerLookup\Exceptions\PlayerNotFoundException; -use App\Domains\Bans\Exceptions\NotBannedException; use App\Models\GamePlayerBan; -use Repositories\GamePlayerBanRepository; -use Repositories\MinecraftPlayerRepository; +use App\Models\MinecraftPlayer; class LookupPlayerBan { public function __construct( private readonly MojangPlayerApi $mojangPlayerApi, - private readonly GamePlayerBanRepository $gamePlayerBanRepository, - private readonly MinecraftPlayerRepository $minecraftPlayerRepository - ) { - } + ) {} - /** - * @throws TooManyRequestsException - * @throws NotBannedException - * @throws PlayerNotFoundException - */ - public function execute(string $username): GamePlayerBan + public function execute(string $username): ?GamePlayerBan { $mojangPlayer = $this->mojangPlayerApi->getUuidOf($username); if ($mojangPlayer === null) { - throw new PlayerNotFoundException(); + return null; } - $mcPlayer = $this->minecraftPlayerRepository->getByUUID(new MinecraftUUID($mojangPlayer->getUuid())); + $mcPlayer = MinecraftPlayer::where('uuid', $mojangPlayer->getUuid())->first(); if ($mcPlayer === null) { - throw new NotBannedException(); + return null; } - $gamePlayerBan = $this->gamePlayerBanRepository->firstActiveBan(player: $mcPlayer); + $gamePlayerBan = GamePlayerBan::where('banned_player_id', $mcPlayer->getKey()) + ->active() + ->first(); if ($gamePlayerBan === null) { - throw new NotBannedException(); + return null; } return $gamePlayerBan; diff --git a/app/Domains/BuilderRankApplications/UseCases/CreateBuildRankApplication.php b/app/Domains/BuilderRankApplications/UseCases/CreateBuildRankApplication.php index 61ab768b8..daf1ebb3a 100644 --- a/app/Domains/BuilderRankApplications/UseCases/CreateBuildRankApplication.php +++ b/app/Domains/BuilderRankApplications/UseCases/CreateBuildRankApplication.php @@ -8,15 +8,9 @@ use App\Domains\BuilderRankApplications\Notifications\BuilderRankAppSubmittedNotification; use App\Models\Account; use App\Models\BuilderRankApplication; -use Repositories\BuilderRankApplicationRepository; class CreateBuildRankApplication { - public function __construct( - private readonly BuilderRankApplicationRepository $applicationRepository, - ) { - } - /** * @throws ApplicationAlreadyInProgressException if the account already has an application in progress */ @@ -28,23 +22,24 @@ public function execute( string $buildDescription, ?string $additionalNotes, ): BuilderRankApplication { - $existingApplication = $this->applicationRepository->countActive( - accountId: $account->getKey(), - ); + $existingApplication = BuilderRankApplication::where('status', ApplicationStatus::IN_PROGRESS->value) + ->where('account_id', $account->getKey()) + ->count(); if ($existingApplication > 0) { throw new ApplicationAlreadyInProgressException(); } - $application = $this->applicationRepository->create( - accountId: $account->getKey(), - minecraftAlias: $minecraftAlias, - currentBuilderRank: $currentBuilderRank, - buildLocation: $buildLocation, - buildDescription: $buildDescription, - additionalNotes: $additionalNotes, - status: ApplicationStatus::IN_PROGRESS, - ); + $application = BuilderRankApplication::create([ + 'account_id' => $account->getKey(), + 'minecraft_alias' => $minecraftAlias, + 'current_builder_rank' => $currentBuilderRank->humanReadable(), + 'build_location' => $buildLocation, + 'build_description' => $buildDescription, + 'additional_notes' => $additionalNotes, + 'status' => ApplicationStatus::IN_PROGRESS->value, + 'closed_at' => null, + ]); $application->notify(new BuilderRankAppSubmittedNotification($application)); diff --git a/app/Domains/Donations/DonationsProvider.php b/app/Domains/Donations/DonationsProvider.php deleted file mode 100644 index b73eb66c7..000000000 --- a/app/Domains/Donations/DonationsProvider.php +++ /dev/null @@ -1,32 +0,0 @@ -app->bind(ProcessPayment::class, function ($app) { - return new ProcessPayment( - paymentRepository: $app->make(PaymentRepository::class), - donationPerkRepository: $app->make(DonationPerkRepository::class), - donationRepository: $app->make(DonationRepository::class), - stripeProductRepository: $app->make(StripeProductRepository::class), - donorGroup: Group::where('name', Group::DONOR_GROUP_NAME)->first() - ?? throw new \Exception('Could not find donor group'), - ); - }); - } -} diff --git a/app/Domains/Donations/UseCases/BeginCheckout.php b/app/Domains/Donations/UseCases/BeginCheckout.php index 412299ac7..16ac883ae 100644 --- a/app/Domains/Donations/UseCases/BeginCheckout.php +++ b/app/Domains/Donations/UseCases/BeginCheckout.php @@ -4,8 +4,8 @@ use App\Domains\Donations\Exceptions\StripeProductNotFoundException; use App\Models\Account; +use App\Models\StripeProduct; use Laravel\Cashier\Checkout; -use Repositories\StripeProductRepository; use Stripe\Exception\ApiErrorException; use Stripe\StripeClient; @@ -13,9 +13,7 @@ final class BeginCheckout { public function __construct( private readonly StripeClient $stripeClient, - private readonly StripeProductRepository $stripeProductRepository, - ) { - } + ) {} /** * @throws ApiErrorException @@ -33,7 +31,9 @@ public function execute( $productId = $price['product']; $priceId = $price['id']; - $product = $this->stripeProductRepository->first(productId: $productId, priceId: $priceId) + $product = StripeProduct::where('product_id', $productId) + ->where('price_id', $priceId) + ->first() ?? throw new StripeProductNotFoundException(); $donationTier = $product->donationTier; diff --git a/app/Domains/Donations/UseCases/ProcessPayment.php b/app/Domains/Donations/UseCases/ProcessPayment.php index c4870073a..64e86de50 100644 --- a/app/Domains/Donations/UseCases/ProcessPayment.php +++ b/app/Domains/Donations/UseCases/ProcessPayment.php @@ -9,25 +9,15 @@ use App\Domains\Donations\Exceptions\StripeProductNotFoundException; use App\Domains\Donations\Notifications\DonationPerkStartedNotification; use App\Models\Account; +use App\Models\Donation; use App\Models\DonationPerk; use App\Models\Group; +use App\Models\Payment; +use App\Models\StripeProduct; use Illuminate\Support\Carbon; -use Repositories\DonationPerkRepository; -use Repositories\DonationRepository; -use Repositories\PaymentRepository; -use Repositories\StripeProductRepository; final class ProcessPayment { - public function __construct( - private readonly PaymentRepository $paymentRepository, - private readonly DonationPerkRepository $donationPerkRepository, - private readonly DonationRepository $donationRepository, - private readonly StripeProductRepository $stripeProductRepository, - private readonly Group $donorGroup, - ) { - } - /** * @throws StripeProductNotFoundException if productId does not exist in the StripeProducts table * @throws BadRequestException if quantity or paidAmount is invalid @@ -48,43 +38,53 @@ public function execute( throw new BadRequestException(id: 'invalid_quantity', message: 'Quantity purchased was zero'); } - $product = $this->stripeProductRepository->first(productId: $productId, priceId: $priceId) + $donorGroup = Group::where('name', Group::DONOR_GROUP_NAME)->first(); + if ($donorGroup === null) { + throw new \Exception('Could not find donor group'); + } + + $product = StripeProduct::where('product_id', $productId) + ->where('price_id', $priceId) + ->first() ?? throw new StripeProductNotFoundException(); - $donation = $this->donationRepository->create( - accountId: $account->getKey(), - paidAmount: $paidAmount, - ); + $donation = Donation::create([ + 'account_id' => $account->getKey(), + 'amount' => $paidAmount->toDollars(), + ]); - $this->paymentRepository->create( - accountId: $account->getKey(), - productId: $productId, - priceId: $priceId, - paidAmount: $paidAmount, - quantity: $quantity, - isSubscription: $donationType == PaymentType::SUBSCRIPTION, - ); + Payment::create([ + 'account_id' => $account->getKey(), + 'stripe_product' => $productId, + 'stripe_price' => $priceId, + 'amount_paid_in_cents' => $paidAmount->toCents(), + 'quantity' => $quantity, + 'is_subscription_payment' => $donationType == PaymentType::SUBSCRIPTION, + ]); $donationTier = $product->donationTier; if ($donationTier !== null) { - $existingPerk = $this->donationPerkRepository->lastToExpire( - accountId: $account->getKey(), - donationTierId: $donationTier->getKey(), - ); + $existingPerk = DonationPerk::where('account_id', $account->getKey()) + ->where('donation_tier_id', $donationTier->getKey()) + ->where('is_active', true) + ->whereNotNull('expires_at') + ->orderBy('expires_at', 'desc') + ->first(); $expiryDate = $this->calculateExpiryDate( numberOfMonths: $quantity, existingPerk: $existingPerk, ); - $newPerk = $this->donationPerkRepository->create( - donationId: $donation->getKey(), - donationTierId: $donationTier?->getKey(), - accountId: $account->getKey(), - expiresAt: $expiryDate, - ); + $newPerk = DonationPerk::create([ + 'donation_id' => $donation->getKey(), + 'donation_tier_id' => $donationTier?->getKey(), + 'account_id' => $account->getKey(), + 'is_active' => true, + 'expires_at' => $expiryDate, + ]); - $account->groups()->attach($this->donorGroup->getKey()); + $account->groups()->attach($donorGroup->getKey()); $notification = new DonationPerkStartedNotification($expiryDate); $account->notify($notification); diff --git a/app/Domains/Login/UseCases/LoginAccount.php b/app/Domains/Login/UseCases/LoginAccount.php index 1bccf626f..a87a0b15f 100644 --- a/app/Domains/Login/UseCases/LoginAccount.php +++ b/app/Domains/Login/UseCases/LoginAccount.php @@ -3,13 +3,11 @@ namespace App\Domains\Login\UseCases; use App\Domains\Login\Data\LoginCredentials; -use App\Domains\Login\Exceptions\AccountNotActivatedException; use App\Domains\Login\Exceptions\InvalidLoginCredentialsException; use App\Http\Middleware\MfaAuthenticated; use App\Models\Account; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Session; -use Repositories\AccountRepository; class LoginAccount { diff --git a/app/Domains/MinecraftTelemetry/UseCases/UpdateSeenMinecraftPlayer.php b/app/Domains/MinecraftTelemetry/UseCases/UpdateSeenMinecraftPlayer.php index da784e5a7..a9d1d1f91 100644 --- a/app/Domains/MinecraftTelemetry/UseCases/UpdateSeenMinecraftPlayer.php +++ b/app/Domains/MinecraftTelemetry/UseCases/UpdateSeenMinecraftPlayer.php @@ -2,23 +2,19 @@ namespace App\Domains\MinecraftTelemetry\UseCases; -use App\Core\Domains\PlayerLookup\Data\PlayerIdentifier; -use App\Core\Domains\PlayerLookup\Service\PlayerLookup; +use App\Core\Domains\MinecraftUUID\Data\MinecraftUUID; +use App\Models\MinecraftPlayer; final class UpdateSeenMinecraftPlayer { - public function __construct( - private readonly PlayerLookup $playerLookup, - ) {} - - public function execute(string $uuid, string $alias): void + public function execute(MinecraftUUID $uuid, string $alias): void { - $player = $this->playerLookup->findOrCreate( - identifier: PlayerIdentifier::minecraftUUID($uuid) + $player = MinecraftPlayer::firstOrCreate( + uuid: $uuid, + alias: $alias, ); $minecraftPlayer = $player->getRawModel(); $minecraftPlayer->last_seen_at = now(); - $minecraftPlayer->alias = $alias; $minecraftPlayer->save(); } } diff --git a/app/Domains/Warnings/UseCases/AcknowledgeWarning.php b/app/Domains/Warnings/UseCases/AcknowledgeWarning.php deleted file mode 100644 index bf9899271..000000000 --- a/app/Domains/Warnings/UseCases/AcknowledgeWarning.php +++ /dev/null @@ -1,30 +0,0 @@ -playerWarningRepository->find($warningId); - if ($warning === null) { - abort(404); - } - if ($accountId !== null && $warning->warnedPlayer->account?->getKey() !== $accountId) { - abort(403); - } - if ($warning->is_acknowledged && $warning->acknowledged_at !== null) { - abort(410); - } - - return $this->playerWarningRepository->acknowledge($warning); - } -} diff --git a/app/Domains/Warnings/UseCases/CreateWarning.php b/app/Domains/Warnings/UseCases/CreateWarning.php deleted file mode 100644 index 366bdf707..000000000 --- a/app/Domains/Warnings/UseCases/CreateWarning.php +++ /dev/null @@ -1,44 +0,0 @@ -playerLookup->findOrCreate( - identifier: $warnedPlayerIdentifier, - playerAlias: $warnedPlayerAlias, - ); - $warnerPlayer = $this->playerLookup->findOrCreate( - identifier: $warnerPlayerIdentifier, - playerAlias: $warnerPlayerAlias, - ); - - return $this->playerWarningRepository->create( - warnedPlayerId: $warnedPlayer->getKey(), - warnerPlayerId: $warnerPlayer->getKey(), - reason: $reason, - weight: $weight, - isAcknowledged: $isAcknowledged, - ); - } -} diff --git a/app/Domains/Warnings/UseCases/GetWarnings.php b/app/Domains/Warnings/UseCases/GetWarnings.php deleted file mode 100644 index 688f18224..000000000 --- a/app/Domains/Warnings/UseCases/GetWarnings.php +++ /dev/null @@ -1,31 +0,0 @@ -playerLookup->find(identifier: $playerIdentifier); - if ($player === null) { - return collect(); - } - - return $this->playerWarningRepository->all( - playerId: $player->getKey(), - ); - } -} diff --git a/app/Http/Controllers/Api/v1/MinecraftAggregateController.php b/app/Http/Controllers/Api/v1/MinecraftAggregateController.php index 0ccc76ff9..f4843fd75 100644 --- a/app/Http/Controllers/Api/v1/MinecraftAggregateController.php +++ b/app/Http/Controllers/Api/v1/MinecraftAggregateController.php @@ -3,7 +3,7 @@ namespace App\Http\Controllers\Api\v1; use App\Core\Data\Exceptions\NotFoundException; -use App\Core\Domains\PlayerLookup\Data\PlayerIdentifier; +use App\Core\Domains\MinecraftUUID\Data\MinecraftUUID; use App\Domains\Badges\UseCases\GetBadges; use App\Domains\Bans\UseCases\GetActiveIPBan; use App\Domains\Bans\UseCases\GetActivePlayerBan; @@ -33,12 +33,10 @@ public function show( 'ip' => 'ip', ]); - $uuid = str_replace(search: '-', replace: '', subject: $uuid); + $uuid = new MinecraftUUID($uuid); - $identifier = PlayerIdentifier::minecraftUUID($uuid); - - $ban = $getBan->execute(playerIdentifier: $identifier); - $badges = $getBadges->execute(identifier: $identifier); + $ban = $getBan->execute(uuid: $uuid); + $badges = $getBadges->execute(uuid: $uuid); try { $donationTiers = $getDonationTier->execute(uuid: $uuid); @@ -46,7 +44,7 @@ public function show( $donationTiers = []; } - $account = $this->getLinkedAccount($uuid); + $account = $this->getAccount($uuid); $ipBan = null; if ($request->has('ip')) { @@ -64,9 +62,9 @@ public function show( ]); } - private function getLinkedAccount(string $uuid): ?Account + private function getAccount(MinecraftUUID $uuid): ?Account { - $existingPlayer = MinecraftPlayer::where('uuid', $uuid)->first(); + $existingPlayer = MinecraftPlayer::whereUuid($uuid)->first(); if ($existingPlayer === null || $existingPlayer->account === null) { return null; diff --git a/app/Http/Controllers/Api/v1/MinecraftBadgeController.php b/app/Http/Controllers/Api/v1/MinecraftBadgeController.php index 7fcf4c3ee..577382d2c 100644 --- a/app/Http/Controllers/Api/v1/MinecraftBadgeController.php +++ b/app/Http/Controllers/Api/v1/MinecraftBadgeController.php @@ -2,7 +2,7 @@ namespace App\Http\Controllers\Api\v1; -use App\Core\Domains\PlayerLookup\Data\PlayerIdentifier; +use App\Core\Domains\MinecraftUUID\Data\MinecraftUUID; use App\Domains\Badges\UseCases\GetBadges; use App\Http\Controllers\ApiController; use Illuminate\Http\Request; @@ -14,9 +14,8 @@ public function show( string $uuid, GetBadges $getBadges, ) { - $badges = $getBadges->execute( - identifier: PlayerIdentifier::minecraftUUID($uuid) - ); + $uuid = new MinecraftUUID($uuid); + $badges = $getBadges->execute(uuid: $uuid); return [ 'data' => $badges, diff --git a/app/Http/Controllers/Api/v1/MinecraftTelemetryController.php b/app/Http/Controllers/Api/v1/MinecraftTelemetryController.php index c7c7a0d78..5107ee3be 100644 --- a/app/Http/Controllers/Api/v1/MinecraftTelemetryController.php +++ b/app/Http/Controllers/Api/v1/MinecraftTelemetryController.php @@ -2,6 +2,8 @@ namespace App\Http\Controllers\Api\v1; +use App\Core\Domains\MinecraftUUID\Data\MinecraftUUID; +use App\Core\Domains\MinecraftUUID\Rules\MinecraftUUIDRule; use App\Domains\MinecraftTelemetry\UseCases\UpdateSeenMinecraftPlayer; use App\Http\Controllers\ApiController; use Illuminate\Http\Request; @@ -12,13 +14,13 @@ public function playerSeen( Request $request, UpdateSeenMinecraftPlayer $updateSeenMinecraftPlayer, ) { - $this->validateRequest($request->all(), [ - 'uuid' => 'required|string', - 'alias' => 'required|string', + $request->validate([ + 'uuid' => ['required', new MinecraftUUIDRule], + 'alias' => ['required', 'string'], ]); $updateSeenMinecraftPlayer->execute( - uuid: $request->get('uuid'), + uuid: new MinecraftUUID($request->get('uuid')), alias: $request->get('alias'), ); diff --git a/app/Http/Controllers/Api/v1/PlayerWarningController.php b/app/Http/Controllers/Api/v1/PlayerWarningController.php deleted file mode 100644 index 24ebda60b..000000000 --- a/app/Http/Controllers/Api/v1/PlayerWarningController.php +++ /dev/null @@ -1,100 +0,0 @@ -validateRequest($request->all(), [ - 'warned_player_id' => 'required|max:60', - 'warned_player_type' => ['required', Rule::in(PlayerIdentifierType::values())], - 'warned_player_alias' => 'required', - 'warner_player_id' => 'required|max:60', - 'warner_player_type' => ['required', Rule::in(PlayerIdentifierType::values())], - 'warner_player_alias' => 'required', - 'reason' => 'required|string', - 'weight' => 'required|integer', - ], [ - 'in' => 'Invalid :attribute given. Must be ['.PlayerIdentifierType::allJoined().']', - ]); - - $warning = $createWarning->execute( - warnedPlayerIdentifier: new PlayerIdentifier( - key: $request->get('warned_player_id'), - gameIdentifierType: PlayerIdentifierType::tryFrom($request->get('warned_player_type')), - ), - warnedPlayerAlias: $request->get('warned_player_alias'), - warnerPlayerIdentifier: new PlayerIdentifier( - key: $request->get('warner_player_id'), - gameIdentifierType: PlayerIdentifierType::tryFrom($request->get('warner_player_type')), - ), - warnerPlayerAlias: $request->get('warner_player_alias'), - reason: $request->get('reason'), - weight: $request->get('weight'), - isAcknowledged: false, - ); - - return new PlayerWarningResource($warning); - } - - /** - * @throws BadRequestException - */ - public function show( - Request $request, - GetWarnings $getWarning, - ): AnonymousResourceCollection { - $this->validateRequest($request->all(), [ - 'player_id' => 'required|max:60', - 'player_type' => ['required', Rule::in(PlayerIdentifierType::values())], - 'player_alias' => 'required', - ], [ - 'in' => 'Invalid :attribute given. Must be ['.PlayerIdentifierType::allJoined().']', - ]); - - $warning = $getWarning->execute( - playerIdentifier: new PlayerIdentifier( - key: $request->get('player_id'), - gameIdentifierType: PlayerIdentifierType::tryFrom($request->get('player_type')), - ), - playerAlias: $request->get('player_alias'), - ); - - return PlayerWarningResource::collection($warning); - } - - /** - * @throws BadRequestException - */ - public function acknowledge( - Request $request, - AcknowledgeWarning $acknowledgeWarning, - ): PlayerWarningResource { - $this->validateRequest($request->all(), [ - 'warning_id' => 'required|integer', - ]); - $warning = $acknowledgeWarning->execute( - warningId: $request->get('warning_id'), - ); - - return new PlayerWarningResource($warning); - } -} diff --git a/app/Http/Controllers/Api/v2/GameIPBanController.php b/app/Http/Controllers/Api/v2/GameIPBanController.php deleted file mode 100644 index 257a331b1..000000000 --- a/app/Http/Controllers/Api/v2/GameIPBanController.php +++ /dev/null @@ -1,101 +0,0 @@ -validateRequest($request->all(), [ - 'banner_player_id' => 'required|max:60', - 'banner_player_type' => ['required', Rule::in(PlayerIdentifierType::values())], - 'banner_player_alias' => 'required|string', - 'ip_address' => 'required|ip', - 'reason' => 'nullable|string', - ], [ - 'in' => 'Invalid :attribute given. Must be ['.PlayerIdentifierType::allJoined().']', - ]); - - $ban = $createIPBan->execute( - ip: $request->get('ip_address'), - bannerPlayerIdentifier: new PlayerIdentifier( - key: $request->get('banner_player_id'), - gameIdentifierType: PlayerIdentifierType::tryFrom($request->get('banner_player_type')), - ), - bannerPlayerAlias: $request->get('banner_player_alias'), - banReason: $request->get('reason'), - ); - - return new GameIPBanResource($ban); - } - - /** - * @throws NotIPBannedException - * @throws BadRequestException - */ - public function unban( - Request $request, - CreateIPUnban $createUnban, - ): GameIPBanResource { - $this->validateRequest($request->all(), [ - 'ip_address' => 'required|ip', - 'unbanner_player_id' => 'max:60', - 'unbanner_player_type' => Rule::in(PlayerIdentifierType::values()), - ], [ - 'in' => 'Invalid :attribute given. Must be ['.PlayerIdentifierType::allJoined().']', - ]); - - $ban = $createUnban->execute( - ip: $request->get('ip_address'), - unbannerPlayerIdentifier: new PlayerIdentifier( - key: $request->get('unbanner_player_id'), - gameIdentifierType: PlayerIdentifierType::tryFrom($request->get('unbanner_player_type')), - ), - unbanType: UnbanType::MANUAL, - ); - - return new GameIPBanResource($ban); - } - - /** - * @throws BadRequestException - */ - public function status( - Request $request, - GetActiveIPBan $getActiveIPBans, - ): JsonResponse { - $this->validateRequest($request->all(), [ - 'ip_address' => 'required|ip', - ]); - $ban = $getActiveIPBans->execute(ip: $request->get('ip_address')); - - if ($ban === null) { - return response()->json(['data' => []]); - } - - return response()->json([ - 'data' => GameIPBanResource::make($ban), - ]); - } -} diff --git a/app/Http/Controllers/Api/v2/GamePlayerBanController.php b/app/Http/Controllers/Api/v2/GamePlayerBanController.php deleted file mode 100644 index f90b8fc99..000000000 --- a/app/Http/Controllers/Api/v2/GamePlayerBanController.php +++ /dev/null @@ -1,192 +0,0 @@ -validateRequest($request->all(), [ - 'banned_player_id' => 'required|max:60', - 'banned_player_type' => ['required', Rule::in(PlayerIdentifierType::values())], - 'banned_player_alias' => 'required|string', - 'banner_player_id' => 'max:60', - 'banner_player_type' => Rule::in(PlayerIdentifierType::values()), - 'banner_player_alias' => 'string', - 'reason' => 'nullable|string', - 'expires_at' => 'integer', - ], [ - 'in' => 'Invalid :attribute given. Must be ['.PlayerIdentifierType::allJoined().']', - ]); - - $expiresAt = $request->get('expires_at'); - if ($expiresAt !== null) { - $expiresAt = Carbon::createFromTimestamp($expiresAt); - - if ($expiresAt->lt(now())) { - throw new BadRequestException('bad_input', 'Expiry date cannot be in the past'); - } - } - - // Temporary measure to get the server without the server token - $server = Server::first(); - - $ban = $createBan->execute( - serverId: $server->getKey(), - bannedPlayerIdentifier: new PlayerIdentifier( - key: $request->get('banned_player_id'), - gameIdentifierType: PlayerIdentifierType::tryFrom($request->get('banned_player_type')), - ), - bannedPlayerAlias: $request->get('banned_player_alias'), - bannerPlayerIdentifier: new PlayerIdentifier( - key: $request->get('banner_player_id'), - gameIdentifierType: PlayerIdentifierType::tryFrom($request->get('banner_player_type')), - ), - bannerPlayerAlias: $request->get('banner_player_alias'), - banReason: $request->get('reason'), - expiresAt: $expiresAt, - ); - - return new GamePlayerBanResource($ban); - } - - /** - * @throws NotBannedException - * @throws BadRequestException - */ - public function unban( - Request $request, - CreatePlayerUnban $createUnban, - ): GamePlayerBanResource { - $this->validateRequest($request->all(), [ - 'banned_player_id' => 'required|max:60', - 'banned_player_type' => ['required', Rule::in(PlayerIdentifierType::values())], - 'unbanner_player_id' => 'max:60', - 'unbanner_player_type' => Rule::in(PlayerIdentifierType::values()), - ], [ - 'in' => 'Invalid :attribute given. Must be ['.PlayerIdentifierType::allJoined().']', - ]); - - $ban = $createUnban->execute( - bannedPlayerIdentifier: new PlayerIdentifier( - key: $request->get('banned_player_id'), - gameIdentifierType: PlayerIdentifierType::tryFrom($request->get('banned_player_type')), - ), - unbannerPlayerIdentifier: new PlayerIdentifier( - key: $request->get('unbanner_player_id'), - gameIdentifierType: PlayerIdentifierType::tryFrom($request->get('unbanner_player_type')), - ), - unbanType: UnbanType::MANUAL, - ); - - return new GamePlayerBanResource($ban); - } - - /** - * @throws AlreadyPermBannedException - * @throws BadRequestException - */ - public function convertToPermanent( - Request $request, - ConvertToPermanentPlayerBan $convertToPermanentBan, - ): GamePlayerBanResource { - $this->validateRequest($request->all(), [ - 'ban_id' => 'required|integer', - 'banner_player_id' => 'required|max:60', - 'banner_player_type' => ['required', Rule::in(PlayerIdentifierType::values())], - 'banner_player_alias' => 'required', - 'reason' => 'string', - ], [ - 'in' => 'Invalid :attribute given. Must be ['.PlayerIdentifierType::allJoined().']', - ]); - - $newBan = $convertToPermanentBan->execute( - banId: $request->get('ban_id'), - bannerPlayerIdentifier: new PlayerIdentifier( - key: $request->get('banner_player_id'), - gameIdentifierType: PlayerIdentifierType::tryFrom($request->get('banner_player_type')), - ), - bannerPlayerAlias: $request->get('banner_player_alias'), - banReason: $request->get('reason'), - ); - - return new GamePlayerBanResource($newBan); - } - - /** - * @throws BadRequestException - */ - public function status( - Request $request, - GetActivePlayerBan $getActiveBans, - ): GamePlayerBanResource|array { - $this->validateRequest($request->all(), [ - 'player_id' => 'required|max:60', - 'player_type' => ['required', Rule::in(PlayerIdentifierType::values())], - ], [ - 'in' => 'Invalid :attribute given. Must be ['.PlayerIdentifierType::allJoined().']', - ]); - - $ban = $getActiveBans->execute( - playerIdentifier: new PlayerIdentifier( - key: $request->get('player_id'), - gameIdentifierType: PlayerIdentifierType::tryFrom($request->get('player_type')), - ), - ); - - if ($ban === null) { - return ['data' => null]; - } - - return new GamePlayerBanResource($ban); - } - - /** - * @throws BadRequestException - */ - public function all( - Request $request, - GetAllPlayerBans $getAllBans, - ): AnonymousResourceCollection { - $this->validateRequest($request->all(), [ - 'player_id' => 'required|max:60', - 'player_type' => ['required', Rule::in(PlayerIdentifierType::values())], - ], [ - 'in' => 'Invalid :attribute given. Must be ['.PlayerIdentifierType::allJoined().']', - ]); - - $bans = $getAllBans->execute( - playerIdentifier: new PlayerIdentifier( - key: $request->get('player_id'), - gameIdentifierType: PlayerIdentifierType::tryFrom($request->get('player_type')), - ), - ); - - return GamePlayerBanResource::collection($bans); - } -} diff --git a/app/Http/Controllers/Front/BanAppeal/BanLookupController.php b/app/Http/Controllers/Front/BanAppeal/BanLookupController.php index 384bad24f..df740663e 100644 --- a/app/Http/Controllers/Front/BanAppeal/BanLookupController.php +++ b/app/Http/Controllers/Front/BanAppeal/BanLookupController.php @@ -3,8 +3,6 @@ namespace App\Http\Controllers\Front\BanAppeal; use App\Core\Data\Exceptions\TooManyRequestsException; -use App\Core\Domains\PlayerLookup\Exceptions\PlayerNotFoundException; -use App\Domains\Bans\Exceptions\NotBannedException; use App\Domains\Bans\UseCases\LookupPlayerBan; use App\Http\Controllers\WebController; use App\Http\Requests\BanLookupRequest; @@ -16,20 +14,16 @@ public function __invoke(BanLookupRequest $request, LookupPlayerBan $useCase) { try { $ban = $useCase->execute($request->get('username')); - + if ($ban === null) { + throw ValidationException::withMessages([ + 'error' => ['This player has no active bans.'], + ]); + } return redirect()->route('front.appeal.create', $ban); } catch (TooManyRequestsException) { throw ValidationException::withMessages([ 'error' => ['The Mojang API is too busy currently. Please try again later'], ]); - } catch (NotBannedException) { - throw ValidationException::withMessages([ - 'error' => ['This player has no active bans.'], - ]); - } catch (PlayerNotFoundException) { - throw ValidationException::withMessages([ - 'error' => ['This username does not belong to a Minecraft player. Check you have entered it correctly.'], - ]); } } } diff --git a/app/Http/Controllers/Front/BuilderRankApplicationController.php b/app/Http/Controllers/Front/BuilderRankApplicationController.php index 27f885cf1..414c88fbe 100644 --- a/app/Http/Controllers/Front/BuilderRankApplicationController.php +++ b/app/Http/Controllers/Front/BuilderRankApplicationController.php @@ -2,30 +2,30 @@ namespace App\Http\Controllers\Front; +use App\Domains\BuilderRankApplications\Data\ApplicationStatus; use App\Domains\BuilderRankApplications\Data\BuilderRank; use App\Domains\BuilderRankApplications\Exceptions\ApplicationAlreadyInProgressException; use App\Domains\BuilderRankApplications\UseCases\CreateBuildRankApplication; use App\Http\Controllers\WebController; use App\Http\Requests\BuilderRankApplicationRequest; -use App\Models\Account; use App\Models\BuilderRankApplication; use Illuminate\Http\Request; -use Repositories\BuilderRankApplicationRepository; final class BuilderRankApplicationController extends WebController { public function index( Request $request, - BuilderRankApplicationRepository $applicationRepository, ) { $minecraftUsername = $request->user() ?->minecraftAccount?->first() ?->aliases?->first() ?->alias; - $applicationInProgress = $applicationRepository->firstActive( - accountId: $request->user()->getKey(), - ); + $applicationInProgress = BuilderRankApplication::where('status', ApplicationStatus::IN_PROGRESS->value) + ->where('account_id', $request->user()->getKey()) + ->orderBy('created_at', 'DESC') + ->first(); + if ($applicationInProgress !== null) { return redirect() ->route('front.rank-up.status', $applicationInProgress->getKey()); diff --git a/app/Http/Controllers/Panel/BanAppealController.php b/app/Http/Controllers/Panel/BanAppealController.php index 13650c4c6..2ca216f7a 100644 --- a/app/Http/Controllers/Panel/BanAppealController.php +++ b/app/Http/Controllers/Panel/BanAppealController.php @@ -12,13 +12,16 @@ use App\Http\Requests\BanAppealUpdateRequest; use App\Models\BanAppeal; use Illuminate\Validation\ValidationException; -use Repositories\BanAppealRepository; class BanAppealController { - public function index(BanAppealRepository $banAppealRepository) + public function index() { - $banAppeals = $banAppealRepository->allWithPriority(50); + // Get ban appeals paginated in the order: + // Pending appeal (newest first), then all other appeals (newest first) + $banAppeals = BanAppeal::orderByRaw('FIELD(status, '.BanAppealStatus::PENDING->value.') DESC') + ->orderBy('created_at', 'desc') + ->paginate(50); return view('admin.ban-appeal.index')->with([ 'banAppeals' => $banAppeals, diff --git a/app/Http/Controllers/Panel/BuilderRanksController.php b/app/Http/Controllers/Panel/BuilderRanksController.php index ae80f1d40..584e6be36 100644 --- a/app/Http/Controllers/Panel/BuilderRanksController.php +++ b/app/Http/Controllers/Panel/BuilderRanksController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers\Panel; +use App\Domains\BuilderRankApplications\Data\ApplicationStatus; use App\Domains\BuilderRankApplications\UseCases\ApproveBuildRankApplication; use App\Domains\BuilderRankApplications\UseCases\DenyBuildRankApplication; use App\Http\Controllers\WebController; @@ -10,15 +11,15 @@ use Illuminate\Http\Request; use Illuminate\Support\Facades\Validator; use Illuminate\Validation\Rule; -use Repositories\BuilderRankApplicationRepository; class BuilderRanksController extends WebController { public function index( Request $request, - BuilderRankApplicationRepository $applicationRepository, ) { - $applications = $applicationRepository->allWithPriority(perPage: 100); + $applications = BuilderRankApplication::orderbyRaw('FIELD(status, '.ApplicationStatus::IN_PROGRESS->value.') DESC') + ->orderBy('created_at', 'desc') + ->paginate(100); return view('admin.builder-rank.index') ->with(compact('applications')); diff --git a/app/Http/Requests/AccountChangePasswordRequest.php b/app/Http/Requests/AccountChangePasswordRequest.php index 3ca642e2d..c5fbbac62 100644 --- a/app/Http/Requests/AccountChangePasswordRequest.php +++ b/app/Http/Requests/AccountChangePasswordRequest.php @@ -6,7 +6,6 @@ use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Hash; use Illuminate\Validation\Rules\Password; -use Repositories\AccountRepository; class AccountChangePasswordRequest extends FormRequest { diff --git a/app/Http/Requests/AccountSaveNewEmailRequest.php b/app/Http/Requests/AccountSaveNewEmailRequest.php index 3294159bc..e8e7e3116 100644 --- a/app/Http/Requests/AccountSaveNewEmailRequest.php +++ b/app/Http/Requests/AccountSaveNewEmailRequest.php @@ -5,20 +5,9 @@ use App\Models\Account; use Illuminate\Foundation\Http\FormRequest; use Illuminate\Support\Facades\Hash; -use Repositories\AccountRepository; class AccountSaveNewEmailRequest extends FormRequest { - /** - * @var AccountRepository - */ - private $accountRepository; - - public function __construct(AccountRepository $accountRepository) - { - $this->accountRepository = $accountRepository; - } - /** * Get the validation rules that apply to the request. */ diff --git a/app/Http/Requests/SendPasswordEmailRequest.php b/app/Http/Requests/SendPasswordEmailRequest.php index 8f4d849f3..899a40c8d 100644 --- a/app/Http/Requests/SendPasswordEmailRequest.php +++ b/app/Http/Requests/SendPasswordEmailRequest.php @@ -4,7 +4,6 @@ use App\Models\Account; use Illuminate\Foundation\Http\FormRequest; -use Repositories\AccountRepository; final class SendPasswordEmailRequest extends FormRequest { diff --git a/app/Models/MinecraftPlayer.php b/app/Models/MinecraftPlayer.php index efa14ead6..99ab1d9bd 100644 --- a/app/Models/MinecraftPlayer.php +++ b/app/Models/MinecraftPlayer.php @@ -6,7 +6,6 @@ use App\Core\Domains\Auditing\Concerns\LogsActivity; use App\Core\Domains\Auditing\Contracts\LinkableAuditModel; use App\Core\Domains\MinecraftUUID\Data\MinecraftUUID; -use App\Core\Domains\PlayerLookup\Player; use App\Core\Utilities\Traits\HasStaticTable; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Factories\HasFactory; @@ -15,7 +14,7 @@ use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Support\Str; -final class MinecraftPlayer extends Model implements Player, LinkableAuditModel +final class MinecraftPlayer extends Model implements LinkableAuditModel { use HasFactory; use HasStaticTable; @@ -96,6 +95,22 @@ public function touchLastSyncedAt(): bool return $this->save(); } + public static function firstOrCreate(MinecraftUUID $uuid, ?string $alias = null): self + { + $existing = self::whereUuid($uuid)->first(); + if ($existing === null) { + return self::create([ + 'uuid' => $uuid->trimmed(), + 'alias' => $alias, + ]); + } + if ($existing->alias !== $alias) { + $existing->alias = $alias; + $existing->save(); + } + return $existing; + } + public function scopeWhereUuid(Builder $query, MinecraftUUID $uuid) { $query->where('uuid', $uuid->trimmed()); @@ -111,6 +126,7 @@ public function getRawModel(): static return $this; } + /** @deprecated */ public function getLinkedAccount(): ?Account { return $this->account; diff --git a/bootstrap/providers.php b/bootstrap/providers.php index 3dda0ce0d..61f68b067 100644 --- a/bootstrap/providers.php +++ b/bootstrap/providers.php @@ -11,12 +11,10 @@ \App\Core\Domains\SecureTokens\TokensProvider::class, \App\Core\Support\Cashier\CashierServiceProvider::class, - \App\Core\Support\Horizon\HorizonServiceProvider::class, \App\Core\Support\Laravel\LaravelServiceProvider::class, \App\Core\Support\Passport\PassportServiceProvider::class, \App\Domains\Activation\ActivationServiceProvider::class, \App\Domains\BanAppeals\BanAppealServiceProvider::class, - \App\Domains\Donations\DonationsProvider::class, \App\Domains\Panel\PanelServiceProvider::class, ]; diff --git a/repositories/BanAppealRepository.php b/repositories/BanAppealRepository.php deleted file mode 100644 index a5ad1c32d..000000000 --- a/repositories/BanAppealRepository.php +++ /dev/null @@ -1,67 +0,0 @@ - $gamePlayerBanId, - 'is_account_verified' => $isAccountVerified, - 'explanation' => $explanation, - 'email' => $email, - 'status' => BanAppealStatus::PENDING, - ]); - } - - public function updateDecision( - BanAppeal $banAppeal, - string $decisionNote, - int $deciderPlayerMinecraftId, - BanAppealStatus $status, - ): BanAppeal { - $banAppeal->decision_note = $decisionNote; - $banAppeal->decider_player_minecraft_id = $deciderPlayerMinecraftId; - $banAppeal->status = $status; - $banAppeal->decided_at = now(); - $banAppeal->save(); - - activity() - ->on($banAppeal) - ->log(strtolower($status->humanReadable())); - - return $banAppeal; - } - - /** - * Return all ban appeals paginated in the order: - * Pending appeal (newest first), then all other appeals (newest first) - * - * @param int $perPage number per page - * @return mixed - */ - public function allWithPriority(int $perPage) - { - return BanAppeal::orderByRaw('FIELD(status, '.BanAppealStatus::PENDING->value.') DESC') - ->orderBy('created_at', 'desc') - ->paginate($perPage); - } -} diff --git a/repositories/BuilderRankApplicationRepository.php b/repositories/BuilderRankApplicationRepository.php deleted file mode 100644 index b08aeb4bc..000000000 --- a/repositories/BuilderRankApplicationRepository.php +++ /dev/null @@ -1,57 +0,0 @@ - $accountId, - 'minecraft_alias' => $minecraftAlias, - 'current_builder_rank' => $currentBuilderRank->humanReadable(), - 'build_location' => $buildLocation, - 'build_description' => $buildDescription, - 'additional_notes' => $additionalNotes, - 'status' => $status->value, - 'closed_at' => null, - ]); - } - - public function countActive(int $accountId): int - { - return BuilderRankApplication::where('status', ApplicationStatus::IN_PROGRESS->value) - ->where('account_id', $accountId) - ->count(); - } - - public function firstActive(int $accountId): ?BuilderRankApplication - { - return BuilderRankApplication::where('status', ApplicationStatus::IN_PROGRESS->value) - ->where('account_id', $accountId) - ->orderBy('created_at', 'DESC') - ->first(); - } - - public function allWithPriority(int $perPage): LengthAwarePaginator - { - return BuilderRankApplication::orderbyRaw('FIELD(status, '.ApplicationStatus::IN_PROGRESS->value.') DESC') - ->orderBy('created_at', 'desc') - ->paginate($perPage); - } -} diff --git a/repositories/DonationPerkRepository.php b/repositories/DonationPerkRepository.php deleted file mode 100644 index 9d061ebfd..000000000 --- a/repositories/DonationPerkRepository.php +++ /dev/null @@ -1,40 +0,0 @@ -where('donation_tier_id', $donationTierId) - ->where('is_active', true) - ->whereNotNull('expires_at') - ->orderBy('expires_at', 'desc') - ->first(); - } - - public function create( - int $donationId, - int $donationTierId, - int $accountId, - Carbon $expiresAt, - ): DonationPerk { - return DonationPerk::create([ - 'donation_id' => $donationId, - 'donation_tier_id' => $donationTierId, - 'account_id' => $accountId, - 'is_active' => true, - 'expires_at' => $expiresAt, - ]); - } -} diff --git a/repositories/DonationRepository.php b/repositories/DonationRepository.php deleted file mode 100644 index e474ae266..000000000 --- a/repositories/DonationRepository.php +++ /dev/null @@ -1,22 +0,0 @@ - $accountId, - 'amount' => $paidAmount->toDollars(), - ]); - } -} diff --git a/repositories/GameIPBans/GameIPBanEloquentRepository.php b/repositories/GameIPBans/GameIPBanEloquentRepository.php deleted file mode 100644 index a017996e1..000000000 --- a/repositories/GameIPBans/GameIPBanEloquentRepository.php +++ /dev/null @@ -1,43 +0,0 @@ - $bannerPlayerId, - 'ip_address' => $ip, - 'reason' => $reason, - ]); - } - - public function firstActive(string $ip): ?GameIPBan - { - return GameIPBan::where('ip_address', $ip) - ->whereNull('unbanned_at') - ->first(); - } - - public function unban( - GameIPBan $ban, - int $unbannerPlayerId, - UnbanType $unbanType, - ) { - $ban->update([ - 'unbanned_at' => now(), - 'unbanner_player_id' => $unbannerPlayerId, - 'unban_type' => $unbanType->value, - ]); - } -} diff --git a/repositories/GameIPBans/GameIPBanMockRepository.php b/repositories/GameIPBans/GameIPBanMockRepository.php deleted file mode 100644 index 7db5a3331..000000000 --- a/repositories/GameIPBans/GameIPBanMockRepository.php +++ /dev/null @@ -1,38 +0,0 @@ -create; - } - - public function firstActive(string $ip): ?GameIPBan - { - return $this->firstActive; - } - - public function unban( - GameIPBan $ban, - int $unbannerPlayerId, - UnbanType $unbanType, - ) { - $ban->unbanned_at = now(); - $ban->unbanner_player_id = $unbannerPlayerId; - $ban->unban_type = $unbanType; - } -} diff --git a/repositories/GameIPBans/GameIPBanRepository.php b/repositories/GameIPBans/GameIPBanRepository.php deleted file mode 100644 index 42cc31235..000000000 --- a/repositories/GameIPBans/GameIPBanRepository.php +++ /dev/null @@ -1,26 +0,0 @@ - $serverId, - 'banned_player_id' => $bannedPlayerId, - 'banned_alias_at_time' => $bannedPlayerAlias, - 'banner_player_id' => $bannerPlayerId, - 'reason' => $reason, - 'expires_at' => $expiresAt, - ]); - } - - public function find(int $banId): ?GamePlayerBan - { - return GamePlayerBan::find($banId); - } - - public function firstActiveBan(MinecraftPlayer $player): ?GamePlayerBan - { - return GamePlayerBan::where('banned_player_id', $player->getKey()) - ->active() - ->first(); - } - - public function all(MinecraftPlayer $player): Collection - { - return GamePlayerBan::where('banned_player_id', $player->getKey()) - ->orderBy('created_at', 'desc') - ->limit(25) - ->get(); - } - - public function unban( - GamePlayerBan $ban, - ?int $unbannerPlayerId, - UnbanType $unbanType, - ) { - $ban->update([ - 'unbanned_at' => now(), - 'unbanner_player_id' => $unbannerPlayerId, - 'unban_type' => $unbanType->value, - ]); - } -} diff --git a/repositories/MinecraftPlayerAliasRepository.php b/repositories/MinecraftPlayerAliasRepository.php deleted file mode 100644 index 03145181b..000000000 --- a/repositories/MinecraftPlayerAliasRepository.php +++ /dev/null @@ -1,28 +0,0 @@ - $minecraftPlayerId, - 'alias' => $alias, - 'registered_at' => $registeredAt, - ]); - } -} diff --git a/repositories/MinecraftPlayerRepository.php b/repositories/MinecraftPlayerRepository.php deleted file mode 100644 index 54a5f81e2..000000000 --- a/repositories/MinecraftPlayerRepository.php +++ /dev/null @@ -1,32 +0,0 @@ - $uuid->rawValue(), - 'account_id' => $accountId, - ]); - } - - public function getByUUID(MinecraftUUID $uuid): ?MinecraftPlayer - { - return MinecraftPlayer::where('uuid', $uuid->rawValue())->first(); - } - - public function getById(int $id): ?MinecraftPlayer - { - return MinecraftPlayer::where('player_minecraft_id', $id)->first(); - } -} diff --git a/repositories/PaymentRepository.php b/repositories/PaymentRepository.php deleted file mode 100644 index fe17e4ce4..000000000 --- a/repositories/PaymentRepository.php +++ /dev/null @@ -1,30 +0,0 @@ - $accountId, - 'stripe_product' => $productId, - 'stripe_price' => $priceId, - 'amount_paid_in_cents' => $paidAmount->toCents(), - 'quantity' => $quantity, - 'is_subscription_payment' => $isSubscription, - ]); - } -} diff --git a/repositories/PlayerFetchRepository.php b/repositories/PlayerFetchRepository.php deleted file mode 100644 index 9e3a04a4f..000000000 --- a/repositories/PlayerFetchRepository.php +++ /dev/null @@ -1,38 +0,0 @@ - $uuid, - 'account_id' => null, - 'last_synced_at' => now(), - ]); - MinecraftPlayerAlias::create([ - 'player_minecraft_id' => $player->getKey(), - 'alias' => $alias, - 'registered_at' => now(), - ]); - DB::commit(); - } - - public function addAliasForPlayer(int $playerId, string $newAlias) - { - MinecraftPlayerAlias::create([ - 'player_minecraft_id' => $playerId, - 'alias' => $newAlias, - 'registered_at' => now(), - ]); - } -} diff --git a/repositories/PlayerWarnings/PlayerWarningEloquentRepository.php b/repositories/PlayerWarnings/PlayerWarningEloquentRepository.php deleted file mode 100644 index 7d5d7576c..000000000 --- a/repositories/PlayerWarnings/PlayerWarningEloquentRepository.php +++ /dev/null @@ -1,49 +0,0 @@ - $warnedPlayerId, - 'warner_player_id' => $warnerPlayerId, - 'reason' => $reason, - 'weight' => $weight, - 'is_acknowledged' => $isAcknowledged, - ]); - } - - public function all(int $playerId): Collection - { - return PlayerWarning::where('warned_player_id', $playerId) - ->orderBy('created_at', 'desc') - ->get(); - } - - public function find(int $warningId): ?PlayerWarning - { - return PlayerWarning::find($warningId); - } - - public function acknowledge(PlayerWarning $warning): PlayerWarning - { - $warning->is_acknowledged = true; - $warning->acknowledged_at = now(); - $warning->save(); - - return $warning; - } -} diff --git a/repositories/PlayerWarnings/PlayerWarningMockRepository.php b/repositories/PlayerWarnings/PlayerWarningMockRepository.php deleted file mode 100644 index 71f67174d..000000000 --- a/repositories/PlayerWarnings/PlayerWarningMockRepository.php +++ /dev/null @@ -1,44 +0,0 @@ -create; - } - - public function all(int $playerId): Collection - { - return $this->all; - } - - public function find(int $warningId): ?PlayerWarning - { - return $this->find; - } - - public function acknowledge(PlayerWarning $warning): PlayerWarning - { - $warning->is_acknowledged = true; - $warning->acknowledged_at = now(); - - return $warning; - } -} diff --git a/repositories/PlayerWarnings/PlayerWarningRepository.php b/repositories/PlayerWarnings/PlayerWarningRepository.php deleted file mode 100644 index e0d6dc562..000000000 --- a/repositories/PlayerWarnings/PlayerWarningRepository.php +++ /dev/null @@ -1,26 +0,0 @@ -where('price_id', $priceId) - ->first(); - } -} diff --git a/routes/api_v2.php b/routes/api_v2.php index 4778082fd..6fd2b3b66 100644 --- a/routes/api_v2.php +++ b/routes/api_v2.php @@ -5,35 +5,12 @@ use App\Http\Controllers\Api\v1\MinecraftDonationTierController; use App\Http\Controllers\Api\v1\MinecraftShowcaseWarpController; use App\Http\Controllers\Api\v1\MinecraftTelemetryController; -use App\Http\Controllers\Api\v1\PlayerWarningController; -use App\Http\Controllers\Api\v2\GameIPBanController; -use App\Http\Controllers\Api\v2\GamePlayerBanController; use Illuminate\Support\Facades\Route; Route::prefix('v2') ->name('v2.') ->middleware('require-server-token') ->group(function() { - Route::prefix('bans/player')->group(function () { - Route::post('ban', [GamePlayerBanController::class, 'ban']); - Route::post('unban', [GamePlayerBanController::class, 'unban']); - Route::post('convert_to_permanent', [GamePlayerBanController::class, 'convertToPermanent']); - Route::post('status', [GamePlayerBanController::class, 'status']); - Route::post('all', [GamePlayerBanController::class, 'all']); - }); - - Route::prefix('bans/ip')->group(function () { - Route::post('ban', [GameIPBanController::class, 'ban']); - Route::post('unban', [GameIPBanController::class, 'unban']); - Route::get('status', [GameIPBanController::class, 'status']); - }); - - Route::prefix('warnings')->group(function () { - Route::get('/', [PlayerWarningController::class, 'show']); - Route::post('/', [PlayerWarningController::class, 'store']); - Route::post('acknowledge', [PlayerWarningController::class, 'acknowledge']); - }); - Route::prefix('minecraft')->group(function () { Route::prefix('{minecraftUUID}')->group(function () { Route::get('donation-tiers', [MinecraftDonationTierController::class, 'show']); diff --git a/tests/Integration/Api/APIBanAllTest.php b/tests/Integration/Api/APIBanAllTest.php deleted file mode 100644 index da942adba..000000000 --- a/tests/Integration/Api/APIBanAllTest.php +++ /dev/null @@ -1,115 +0,0 @@ -createServerToken(); - } - - private function validData(): array - { - return [ - 'player_type' => PlayerIdentifierType::MINECRAFT_UUID->value, - 'player_id' => 'uuid1', - ]; - } - - public function test_requires_scope() - { - $this->postJson(uri: self::ENDPOINT, data: $this->validData()) - ->assertUnauthorized(); - - $this->withAuthorizationServerToken() - ->postJson(uri: self::ENDPOINT, data: $this->validData()) - ->assertSuccessful(); - } - - public function test_shows_bans_and_unbans() - { - $player1 = MinecraftPlayer::factory()->create(['uuid' => 'uuid1']); - $player2 = MinecraftPlayer::factory()->create(['uuid' => 'uuid2']); - $server = Server::factory()->create(); - - $ban1 = GamePlayerBan::factory() - ->bannedPlayer($player1) - ->bannedBy($player2) - ->server($server) - ->create(['created_at' => now()->subDays(1)]); - - $ban2 = GamePlayerBan::factory() - ->inactive() - ->bannedPlayer($player1) - ->bannedBy($player2) - ->server($server) - ->create(['created_at' => now()->subDays(2)]); // Assertion gets confused without different created_at dates - - $this->withAuthorizationServerToken() - ->postJson(uri: self::ENDPOINT, data: [ - 'player_type' => PlayerIdentifierType::MINECRAFT_UUID->value, - 'player_id' => $player1->uuid, - ]) - ->assertJson([ - 'data' => [ - [ - 'id' => $ban1->getKey(), - 'server_id' => $server->getKey(), - 'banned_player_id' => $player1->getKey(), - 'banner_player_id' => $player2->getKey(), - 'reason' => $ban1->reason, - 'expires_at' => null, - 'created_at' => $ban1->created_at->timestamp, - 'updated_at' => $ban1->updated_at->timestamp, - 'unbanned_at' => null, - 'unbanner_player_id' => null, - 'unban_type' => null, - ], - [ - 'id' => $ban2->getKey(), - 'server_id' => $server->getKey(), - 'banned_player_id' => $player1->getKey(), - 'banner_player_id' => $player2->getKey(), - 'reason' => $ban2->reason, - 'expires_at' => null, - 'created_at' => $ban2->created_at->timestamp, - 'updated_at' => $ban2->updated_at->timestamp, - 'unbanned_at' => $ban2->unbanned_at->timestamp, - 'unbanner_player_id' => null, - 'unban_type' => UnbanType::MANUAL->value, - ], - ], - ]) - ->assertSuccessful(); - } - - public function test_shows_nothing() - { - $player1 = MinecraftPlayer::factory()->create(['uuid' => 'uuid1']); - - $this->withAuthorizationServerToken() - ->postJson(uri: self::ENDPOINT, data: [ - 'player_type' => PlayerIdentifierType::MINECRAFT_UUID->value, - 'player_id' => $player1->uuid, - ]) - ->assertJson([ - 'data' => [], - ]) - ->assertSuccessful(); - } -} diff --git a/tests/Integration/Api/APIBanCreateTest.php b/tests/Integration/Api/APIBanCreateTest.php deleted file mode 100644 index 5e7cad771..000000000 --- a/tests/Integration/Api/APIBanCreateTest.php +++ /dev/null @@ -1,187 +0,0 @@ -createServerToken(); - } - - private function validData(): array - { - return [ - 'banned_player_type' => PlayerIdentifierType::MINECRAFT_UUID->value, - 'banned_player_id' => 'uuid1', - 'banned_player_alias' => 'alias1', - 'banner_player_type' => PlayerIdentifierType::MINECRAFT_UUID->value, - 'banner_player_id' => 'uuid2', - 'banner_player_alias' => 'alias2', - 'reason' => 'reason', - ]; - } - - public function test_requires_scope() - { - $this->postJson(uri: self::ENDPOINT, data: $this->validData()) - ->assertUnauthorized(); - - $this->withAuthorizationServerToken() - ->postJson(uri: self::ENDPOINT, data: $this->validData()) - ->assertSuccessful(); - } - - public function test_creates_permanent_ban() - { - $player1 = MinecraftPlayer::factory()->create(['uuid' => 'uuid1']); - $player2 = MinecraftPlayer::factory()->create(['uuid' => 'uuid2']); - - $this->withAuthorizationServerToken() - ->postJson(uri: self::ENDPOINT, data: [ - 'banned_player_type' => PlayerIdentifierType::MINECRAFT_UUID->value, - 'banned_player_id' => $player1->uuid, - 'banned_player_alias' => 'alias1', - 'banner_player_type' => PlayerIdentifierType::MINECRAFT_UUID->value, - 'banner_player_id' => $player2->uuid, - 'banner_player_alias' => 'alias2', - 'reason' => 'reason', - ]) - ->assertSuccessful(); - - $this->assertDatabaseHas( - table: GamePlayerBan::tableName(), - data: [ - 'server_id' => $this->token->server->getKey(), - 'banned_player_id' => $player1->getKey(), - 'banned_alias_at_time' => 'alias1', - 'banner_player_id' => $player2->getKey(), - 'reason' => 'reason', - 'expires_at' => null, - 'created_at' => $this->now, - 'updated_at' => $this->now, - 'unbanned_at' => null, - 'unbanner_player_id' => null, - 'unban_type' => null, - ], - ); - } - - public function test_creates_temporary_ban() - { - $expiryDate = Carbon::now()->addMonth(); - - $player1 = MinecraftPlayer::factory()->create(['uuid' => 'uuid1']); - $player2 = MinecraftPlayer::factory()->create(['uuid' => 'uuid2']); - - $this->withAuthorizationServerToken() - ->postJson(uri: self::ENDPOINT, data: [ - 'banned_player_type' => PlayerIdentifierType::MINECRAFT_UUID->value, - 'banned_player_id' => $player1->uuid, - 'banned_player_alias' => 'alias1', - 'banner_player_type' => PlayerIdentifierType::MINECRAFT_UUID->value, - 'banner_player_id' => $player2->uuid, - 'banner_player_alias' => 'alias2', - 'reason' => 'reason', - 'expires_at' => $expiryDate->timestamp, - ]) - ->assertSuccessful(); - - $this->assertDatabaseHas( - table: GamePlayerBan::tableName(), - data: [ - 'server_id' => $this->token->server->getKey(), - 'banned_player_id' => $player1->getKey(), - 'banned_alias_at_time' => 'alias1', - 'banner_player_id' => $player2->getKey(), - 'reason' => 'reason', - 'expires_at' => $expiryDate, - 'created_at' => $this->now, - 'updated_at' => $this->now, - 'unbanned_at' => null, - 'unbanner_player_id' => null, - 'unban_type' => null, - ], - ); - } - - public function test_permanent_ban_throws_exception_if_already_permanent_banned() - { - $player1 = MinecraftPlayer::factory()->create(['uuid' => 'uuid1']); - $player2 = MinecraftPlayer::factory()->create(['uuid' => 'uuid2']); - - GamePlayerBan::factory() - ->bannedPlayer($player1) - ->create(); - - $this->assertDatabaseCount(table: GamePlayerBan::tableName(), count: 1); - - $this->withAuthorizationServerToken() - ->postJson(uri: self::ENDPOINT, data: [ - 'banned_player_type' => PlayerIdentifierType::MINECRAFT_UUID->value, - 'banned_player_id' => $player1->uuid, - 'banned_player_alias' => 'alias1', - 'banner_player_type' => PlayerIdentifierType::MINECRAFT_UUID->value, - 'banner_player_id' => $player2->uuid, - 'banner_player_alias' => 'alias2', - 'reason' => 'reason', - ]) - ->assertJson([ - 'error' => [ - 'id' => 'player_already_banned', - 'title' => '', - 'detail' => 'Player is already permanently banned', - 'status' => 400, - ], - ]); - - $this->assertDatabaseCount(table: GamePlayerBan::tableName(), count: 1); - } - - public function test_permanent_ban_throws_exception_if_already_temp_banned() - { - $player1 = MinecraftPlayer::factory()->create(['uuid' => 'uuid1']); - $player2 = MinecraftPlayer::factory()->create(['uuid' => 'uuid2']); - - GamePlayerBan::factory() - ->temporary() - ->bannedPlayer($player1) - ->create(); - - $this->assertDatabaseCount(table: GamePlayerBan::tableName(), count: 1); - - $this->withAuthorizationServerToken() - ->postJson(uri: self::ENDPOINT, data: [ - 'banned_player_type' => PlayerIdentifierType::MINECRAFT_UUID->value, - 'banned_player_id' => $player1->uuid, - 'banned_player_alias' => 'alias1', - 'banner_player_type' => PlayerIdentifierType::MINECRAFT_UUID->value, - 'banner_player_id' => $player2->uuid, - 'banner_player_alias' => 'alias2', - 'reason' => 'reason', - ]) - ->assertJson([ - 'error' => [ - 'id' => 'player_already_temp_banned', - 'title' => '', - 'detail' => 'Player is already banned temporarily', - 'status' => 400, - ], - ]); - - $this->assertDatabaseCount(table: GamePlayerBan::tableName(), count: 1); - } -} diff --git a/tests/Integration/Api/APIBanIPCreateTest.php b/tests/Integration/Api/APIBanIPCreateTest.php deleted file mode 100644 index 56d45e681..000000000 --- a/tests/Integration/Api/APIBanIPCreateTest.php +++ /dev/null @@ -1,103 +0,0 @@ -createServerToken(); - } - - private function validData(): array - { - return [ - 'ip_address' => '192.168.0.1', - 'banner_player_type' => PlayerIdentifierType::MINECRAFT_UUID->value, - 'banner_player_id' => 'uuid', - 'banner_player_alias' => 'alias', - 'reason' => 'reason', - ]; - } - - public function test_requires_scope() - { - $this->postJson(uri: self::ENDPOINT, data: $this->validData()) - ->assertUnauthorized(); - - $this->withAuthorizationServerToken() - ->postJson(uri: self::ENDPOINT, data: $this->validData()) - ->assertSuccessful(); - } - - public function test_creates_ban() - { - $player = MinecraftPlayer::factory()->create(['uuid' => 'uuid']); - - $this->withAuthorizationServerToken() - ->postJson(uri: self::ENDPOINT, data: [ - 'ip_address' => '192.168.0.1', - 'banner_player_type' => PlayerIdentifierType::MINECRAFT_UUID->value, - 'banner_player_id' => $player->uuid, - 'banner_player_alias' => 'alias', - 'reason' => 'reason', - ]) - ->assertSuccessful(); - - $this->assertDatabaseHas( - table: GameIPBan::tableName(), - data: [ - 'ip_address' => '192.168.0.1', - 'banner_player_id' => $player->getKey(), - 'reason' => 'reason', - 'created_at' => $this->now, - 'updated_at' => $this->now, - 'unbanned_at' => null, - 'unbanner_player_id' => null, - 'unban_type' => null, - ], - ); - } - - public function test_throws_exception_if_already_banned() - { - $player = MinecraftPlayer::factory()->create(['uuid' => 'uuid']); - - $ban = GameIPBan::factory() - ->bannedBy($player) - ->create(); - - $this->assertDatabaseCount(table: GameIPBan::tableName(), count: 1); - - $this->withAuthorizationServerToken() - ->postJson(uri: self::ENDPOINT, data: [ - 'ip_address' => $ban->ip_address, - 'banner_player_type' => PlayerIdentifierType::MINECRAFT_UUID->value, - 'banner_player_id' => $player->uuid, - 'banner_player_alias' => 'alias', - 'reason' => 'reason', - ]) - ->assertJson([ - 'error' => [ - 'id' => 'ip_already_banned', - 'title' => '', - 'detail' => 'IP address is already banned', - 'status' => 400, - ], - ]); - - $this->assertDatabaseCount(table: GameIPBan::tableName(), count: 1); - } -} diff --git a/tests/Integration/Api/APIBanIPStatusTest.php b/tests/Integration/Api/APIBanIPStatusTest.php deleted file mode 100644 index 3252c2f17..000000000 --- a/tests/Integration/Api/APIBanIPStatusTest.php +++ /dev/null @@ -1,98 +0,0 @@ -createServerToken(); - } - - private function validData(): array - { - return [ - 'ip_address' => '192.168.0.1', - ]; - } - - public function test_requires_scope() - { - $this->getJson(uri: self::ENDPOINT.'?'.http_build_query($this->validData())) - ->assertUnauthorized(); - - $this->withAuthorizationServerToken() - ->getJson(uri: self::ENDPOINT.'?'.http_build_query($this->validData())) - ->assertSuccessful(); - } - - public function test_returns_ban() - { - $player = MinecraftPlayer::factory()->create(); - - $ban = GameIPBan::factory() - ->bannedBy($player) - ->create(); - - $this->withAuthorizationServerToken() - ->getJson(uri: self::ENDPOINT.'?'.http_build_query([ - 'ip_address' => $ban->ip_address, - ])) - ->assertJson([ - 'data' => [ - 'id' => $ban->getKey(), - 'ip_address' => $ban->ip_address, - 'reason' => $ban->reason, - 'banner_player_id' => $player->getKey(), - 'created_at' => $ban->created_at->timestamp, - 'updated_at' => $ban->updated_at->timestamp, - 'unbanned_at' => null, - 'unbanner_player_id' => null, - 'unban_type' => null, - ], - ]) - ->assertSuccessful(); - } - - public function test_not_banned_when_no_ban() - { - $this->withAuthorizationServerToken() - ->getJson(uri: self::ENDPOINT.'?'.http_build_query([ - 'ip_address' => '192.168.0.1', - ])) - ->assertJson([ - 'data' => [], - ]) - ->assertSuccessful(); - } - - public function test_not_banned_when_unbanned() - { - $player = MinecraftPlayer::factory()->create(); - - $ban = GameIPBan::factory() - ->bannedBy($player) - ->inactive() - ->create(); - - $this->withAuthorizationServerToken() - ->getJson(uri: self::ENDPOINT.'?'.http_build_query([ - 'ip_address' => $ban->ip_address, - ])) - ->assertJson([ - 'data' => [], - ]) - ->assertSuccessful(); - } -} diff --git a/tests/Integration/Api/APIBanStatusTest.php b/tests/Integration/Api/APIBanStatusTest.php deleted file mode 100644 index 29056edf6..000000000 --- a/tests/Integration/Api/APIBanStatusTest.php +++ /dev/null @@ -1,187 +0,0 @@ -createServerToken(); - } - - private function validData(): array - { - return [ - 'player_type' => PlayerIdentifierType::MINECRAFT_UUID->value, - 'player_id' => 'uuid1', - ]; - } - - public function test_requires_scope() - { - $this->postJson(uri: self::ENDPOINT, data: $this->validData()) - ->assertUnauthorized(); - - $this->withAuthorizationServerToken() - ->postJson(uri: self::ENDPOINT, data: $this->validData()) - ->assertSuccessful(); - } - - public function test_permanently_banned() - { - $player1 = MinecraftPlayer::factory()->create(['uuid' => 'uuid1']); - $player2 = MinecraftPlayer::factory()->create(['uuid' => 'uuid2']); - $server = Server::factory()->create(); - - $ban = GamePlayerBan::factory() - ->bannedPlayer($player1) - ->bannedBy($player2) - ->server($server) - ->create(); - - $this->withAuthorizationServerToken() - ->postJson(uri: self::ENDPOINT, data: [ - 'player_type' => PlayerIdentifierType::MINECRAFT_UUID->value, - 'player_id' => $player1->uuid, - ]) - ->assertJson([ - 'data' => [ - 'id' => $ban->getKey(), - 'server_id' => $server->getKey(), - 'banned_player_id' => $player1->getKey(), - 'banner_player_id' => $player2->getKey(), - 'expires_at' => null, - 'unbanned_at' => null, - 'unbanner_player_id' => null, - 'unban_type' => null, - ], - ]) - ->assertSuccessful(); - } - - public function test_temporarily_banned() - { - $player1 = MinecraftPlayer::factory()->create(['uuid' => 'uuid1']); - $player2 = MinecraftPlayer::factory()->create(['uuid' => 'uuid2']); - $server = Server::factory()->create(); - - $ban = GamePlayerBan::factory() - ->bannedPlayer($player1) - ->bannedBy($player2) - ->server($server) - ->temporary() - ->create(); - - $this->withAuthorizationServerToken() - ->postJson(uri: self::ENDPOINT, data: [ - 'player_type' => PlayerIdentifierType::MINECRAFT_UUID->value, - 'player_id' => $player1->uuid, - ]) - ->assertJson([ - 'data' => [ - 'id' => $ban->getKey(), - 'server_id' => $server->getKey(), - 'banned_player_id' => $player1->getKey(), - 'banner_player_id' => $player2->getKey(), - 'expires_at' => $ban->expires_at->timestamp, - 'unbanned_at' => null, - 'unbanner_player_id' => null, - 'unban_type' => null, - ], - ]) - ->assertSuccessful(); - } - - public function test_not_banned_when_no_ban() - { - $player = MinecraftPlayer::factory()->create(); - - $this->withAuthorizationServerToken() - ->postJson(uri: self::ENDPOINT, data: [ - 'player_type' => PlayerIdentifierType::MINECRAFT_UUID->value, - 'player_id' => $player->uuid, - ]) - ->assertJson([ - 'data' => [], - ]) - ->assertSuccessful(); - } - - public function test_not_banned_when_ban_expired() - { - $player = MinecraftPlayer::factory()->create(); - - GamePlayerBan::factory() - ->bannedPlayer($player) - ->bannedBy(MinecraftPlayer::factory()) - ->expired() - ->create(); - - $this->withAuthorizationServerToken() - ->postJson(uri: self::ENDPOINT, data: [ - 'player_type' => PlayerIdentifierType::MINECRAFT_UUID->value, - 'player_id' => $player->uuid, - ]) - ->assertJson([ - 'data' => [], - ]) - ->assertSuccessful(); - } - - public function test_not_banned_when_manually_unbanned() - { - $player = MinecraftPlayer::factory()->create(); - - GamePlayerBan::factory() - ->bannedPlayer($player) - ->bannedBy(MinecraftPlayer::factory()) - ->inactive() - ->create(); - - $this->withAuthorizationServerToken() - ->postJson(uri: self::ENDPOINT, data: [ - 'player_type' => PlayerIdentifierType::MINECRAFT_UUID->value, - 'player_id' => $player->uuid, - ]) - ->assertJson([ - 'data' => [], - ]) - ->assertSuccessful(); - } - - public function test_not_banned_when_ban_expired_but_missing_unban_date() - { - $player = MinecraftPlayer::factory()->create(); - - GamePlayerBan::factory() - ->bannedPlayer($player) - ->bannedBy(MinecraftPlayer::factory()) - ->create([ - 'expires_at' => now()->subDay(), - 'unbanned_at' => null, - ]); - - $this->withAuthorizationServerToken() - ->postJson(uri: self::ENDPOINT, data: [ - 'player_type' => PlayerIdentifierType::MINECRAFT_UUID->value, - 'player_id' => $player->uuid, - ]) - ->assertJson([ - 'data' => [], - ]) - ->assertSuccessful(); - } -} diff --git a/tests/Integration/Api/APIMinecraftAggregateTest.php b/tests/Integration/Api/APIMinecraftAggregateTest.php index 11730a9b8..c698fd7e1 100644 --- a/tests/Integration/Api/APIMinecraftAggregateTest.php +++ b/tests/Integration/Api/APIMinecraftAggregateTest.php @@ -1,7 +1,5 @@ uuid ?? 'invalid'; - - return 'api/v2/minecraft/'.$uuid.'/aggregate'; - } - - protected function setUp(): void - { - parent::setUp(); - - $this->createServerToken(); - } - - public function test_aggregates_all_data() - { - $account = Account::factory()->create(); - $player = MinecraftPlayer::factory() - ->for($account) - ->create(); - - $group = Group::factory()->create(); - $account->groups()->attach($group); - - $server = Server::factory()->create(); - $staffPlayer = MinecraftPlayer::factory()->create(); - $ban = GamePlayerBan::factory() - ->bannedBy($staffPlayer) - ->bannedPlayer($player) - ->server($server) - ->create(); - - $badge = Badge::factory()->create(); - $account->badges()->attach($badge); - - $tier = DonationTier::factory()->create(); - $donation = Donation::factory()->create(); - $perk = DonationPerk::factory() - ->notExpired() - ->create([ - 'account_id' => $account->getKey(), - 'donation_id' => $donation->getKey(), - 'donation_tier_id' => $tier->getKey(), - ]); - - $this->withAuthorizationServerToken() - ->getJson($this->endpoint($player)) - ->assertJson([ - 'data' => [ - 'account' => [ - 'account_id' => $account->getKey(), - 'username' => $account->username, - 'last_login_at' => $account->last_login_at->timestamp, - 'created_at' => $account->created_at->timestamp, - 'updated_at' => $account->updated_at->timestamp, - 'groups' => [ - [ - 'group_id' => $group->getKey(), - 'name' => $group->name, - 'alias' => $group->alias, - 'minecraft_name' => $group->minecraft_name, - 'is_default' => false, - 'is_staff' => false, - 'is_admin' => false, - ], - ], - ], - 'ban' => [ - 'id' => $ban->getKey(), - 'server_id' => $server->getKey(), - 'banned_player_id' => $player->getKey(), - 'banner_player_id' => $staffPlayer->getKey(), - 'reason' => $ban->reason, - 'expires_at' => $ban->expires_at, - 'created_at' => $ban->created_at->timestamp, - 'updated_at' => $ban->updated_at->timestamp, - 'unbanned_at' => null, - 'unbanner_player_id' => null, - 'unban_type' => null, - ], - 'badges' => [ - [ - 'id' => $badge->getKey(), - 'display_name' => $badge->display_name, - 'unicode_icon' => $badge->unicode_icon, - ], - ], - 'donation_tiers' => [ + +it('requires server token', function () { + $this->get('api/v2/minecraft/069a79f444e94726a5befca90e38aaf5/aggregate') + ->assertUnauthorized(); + + $status = $this->withServerToken() + ->get('api/v2/minecraft/069a79f444e94726a5befca90e38aaf5/aggregate') + ->status(); + + expect($status)->not->toEqual(401); +}); + +it('throws exception for invalid Minecraft UUID', function () { + $this->withServerToken() + ->getJson('api/v2/minecraft/invalid/aggregate') + ->assertInvalid(['uuid']); +}); + +it('aggregates all data', function () { + $account = Account::factory()->create(); + $player = MinecraftPlayer::factory() + ->for($account) + ->create(); + + $group = Group::factory()->create(); + $account->groups()->attach($group); + + $server = Server::factory()->create(); + $staffPlayer = MinecraftPlayer::factory()->create(); + $ban = GamePlayerBan::factory() + ->bannedBy($staffPlayer) + ->bannedPlayer($player) + ->server($server) + ->create(); + + $badge = Badge::factory()->create(); + $account->badges()->attach($badge); + + $tier = DonationTier::factory()->create(); + $donation = Donation::factory()->create(); + $perk = DonationPerk::factory() + ->notExpired() + ->create([ + 'account_id' => $account->getKey(), + 'donation_id' => $donation->getKey(), + 'donation_tier_id' => $tier->getKey(), + ]); + + $this->withServerToken() + ->getJson('api/v2/minecraft/'.$player->uuid.'/aggregate') + ->assertJson([ + 'data' => [ + 'account' => [ + 'account_id' => $account->getKey(), + 'username' => $account->username, + 'last_login_at' => $account->last_login_at->timestamp, + 'created_at' => $account->created_at->timestamp, + 'updated_at' => $account->updated_at->timestamp, + 'groups' => [ [ - 'donation_perks_id' => $perk->getKey(), - 'is_active' => true, - 'expires_at' => $perk->expires_at->timestamp, - 'donation_tier' => [ - 'donation_tier_id' => $tier->getKey(), - 'name' => $tier->name, - ], + 'group_id' => $group->getKey(), + 'name' => $group->name, + 'alias' => $group->alias, + 'minecraft_name' => $group->minecraft_name, + 'is_default' => false, + 'is_staff' => false, + 'is_admin' => false, ], ], ], - ]); - } - - public function test_linked_player_with_no_data() - { - $account = Account::factory()->create(); - $player = MinecraftPlayer::factory() - ->for($account) - ->create(); - - $this->withAuthorizationServerToken() - ->getJson($this->endpoint($player)) - ->assertJson([ - 'data' => [ - 'account' => [ - 'account_id' => $account->getKey(), - 'username' => $account->username, - 'last_login_at' => $account->last_login_at->timestamp, - 'created_at' => $account->created_at->timestamp, - 'updated_at' => $account->updated_at->timestamp, - 'groups' => [], + 'ban' => [ + 'id' => $ban->getKey(), + 'server_id' => $server->getKey(), + 'banned_player_id' => $player->getKey(), + 'banner_player_id' => $staffPlayer->getKey(), + 'reason' => $ban->reason, + 'expires_at' => $ban->expires_at, + 'created_at' => $ban->created_at->timestamp, + 'updated_at' => $ban->updated_at->timestamp, + 'unbanned_at' => null, + 'unbanner_player_id' => null, + 'unban_type' => null, + ], + 'badges' => [ + [ + 'id' => $badge->getKey(), + 'display_name' => $badge->display_name, + 'unicode_icon' => $badge->unicode_icon, ], - 'ban' => [], - 'badges' => [], - 'donation_tiers' => [], ], - ]); - } - - public function test_missing_player() - { - $this->withAuthorizationServerToken() - ->getJson($this->endpoint(null)) - ->assertJson([ - 'data' => [ - 'account' => [], - 'ban' => [], - 'badges' => [], - 'donation_tiers' => [], + 'donation_tiers' => [ + [ + 'donation_perks_id' => $perk->getKey(), + 'is_active' => true, + 'expires_at' => $perk->expires_at->timestamp, + 'donation_tier' => [ + 'donation_tier_id' => $tier->getKey(), + 'name' => $tier->name, + ], + ], ], - ]); - } - - public function test_unlinked_account() - { - $player = MinecraftPlayer::factory()->create(); - - $this->withAuthorizationServerToken() - ->getJson($this->endpoint($player)) - ->assertJson([ - 'data' => [ - 'account' => [], - 'ban' => [], - 'badges' => [], - 'donation_tiers' => [], + ], + ]); +}); + +it('shows linked player with no data', function () { + $account = Account::factory()->create(); + $player = MinecraftPlayer::factory() + ->for($account) + ->create(); + + $this->withServerToken() + ->getJson('api/v2/minecraft/'.$player->uuid.'/aggregate') + ->assertJson([ + 'data' => [ + 'account' => [ + 'account_id' => $account->getKey(), + 'username' => $account->username, + 'last_login_at' => $account->last_login_at->timestamp, + 'created_at' => $account->created_at->timestamp, + 'updated_at' => $account->updated_at->timestamp, + 'groups' => [], ], - ]); - } - - public function test_banned_unlinked_account() - { - $player = MinecraftPlayer::factory()->create(); - - $server = Server::factory()->create(); - $staffPlayer = MinecraftPlayer::factory()->create(); - $ban = GamePlayerBan::factory() - ->bannedBy($staffPlayer) - ->bannedPlayer($player) - ->server($server) - ->create(); - - $this->withAuthorizationServerToken() - ->getJson($this->endpoint($player)) - ->assertJson([ - 'data' => [ - 'account' => null, - 'ban' => [ - 'id' => $ban->getKey(), - 'server_id' => $server->getKey(), - 'banned_player_id' => $player->getKey(), - 'banner_player_id' => $staffPlayer->getKey(), - 'reason' => $ban->reason, - 'expires_at' => $ban->expires_at, - 'created_at' => $ban->created_at->timestamp, - 'updated_at' => $ban->updated_at->timestamp, - 'unbanned_at' => null, - 'unbanner_player_id' => null, - 'unban_type' => null, - ], - 'badges' => [], - 'donation_tiers' => [], + 'ban' => [], + 'badges' => [], + 'donation_tiers' => [], + ], + ]); +}); + +it('shows empty data for missing player', function () { + $this->withServerToken() + ->getJson('api/v2/minecraft/069a79f444e94726a5befca90e38aaf5/aggregate') + ->assertJson([ + 'data' => [ + 'account' => [], + 'ban' => [], + 'badges' => [], + 'donation_tiers' => [], + ], + ]); +}); + +it('shows empty data for unlinked account', function () { + $player = MinecraftPlayer::factory()->create(); + + $this->withServerToken() + ->getJson('api/v2/minecraft/'.$player->uuid.'/aggregate') + ->assertJson([ + 'data' => [ + 'account' => [], + 'ban' => [], + 'badges' => [], + 'donation_tiers' => [], + ], + ]); +}); + +it('shows bans for unlinked account', function () { + $player = MinecraftPlayer::factory()->create(); + + $server = Server::factory()->create(); + $staffPlayer = MinecraftPlayer::factory()->create(); + $ban = GamePlayerBan::factory() + ->bannedBy($staffPlayer) + ->bannedPlayer($player) + ->server($server) + ->create(); + + $this->withServerToken() + ->getJson('api/v2/minecraft/'.$player->uuid.'/aggregate') + ->assertJson([ + 'data' => [ + 'account' => null, + 'ban' => [ + 'id' => $ban->getKey(), + 'server_id' => $server->getKey(), + 'banned_player_id' => $player->getKey(), + 'banner_player_id' => $staffPlayer->getKey(), + 'reason' => $ban->reason, + 'expires_at' => $ban->expires_at, + 'created_at' => $ban->created_at->timestamp, + 'updated_at' => $ban->updated_at->timestamp, + 'unbanned_at' => null, + 'unbanner_player_id' => null, + 'unban_type' => null, ], - ]); - } -} + 'badges' => [], + 'donation_tiers' => [], + ], + ]); +}); diff --git a/tests/Integration/Api/APIMinecraftTelemetryTest.php b/tests/Integration/Api/APIMinecraftTelemetryTest.php index 155f1a8b4..9d211831b 100644 --- a/tests/Integration/Api/APIMinecraftTelemetryTest.php +++ b/tests/Integration/Api/APIMinecraftTelemetryTest.php @@ -1,68 +1,130 @@ endpoint = 'api/v2/minecraft/telemetry/seen'; +}); - private const ENDPOINT = 'api/v2/minecraft/telemetry/seen'; +it('requires server token', function () { + $body = ['uuid' => 'uuid', 'alias' => 'alias']; - protected function setUp(): void - { - parent::setUp(); + $this->post($this->endpoint, $body) + ->assertUnauthorized(); - $this->createServerToken(); - } + $status = $this->withServerToken() + ->post($this->endpoint, $body) + ->status(); - public function test_requires_scope() - { - $this->postJson(uri: self::ENDPOINT, data: ['uuid' => 'uuid', 'alias' => 'alias']) - ->assertUnauthorized(); + expect($status)->not->toEqual(401); +}); - $this->withAuthorizationServerToken() - ->postJson(uri: self::ENDPOINT, data: ['uuid' => 'uuid', 'alias' => 'alias']) - ->assertOk(); - } +it('validates input', function () { + $this->withServerToken() + ->post(uri: $this->endpoint, data: []) + ->assertInvalid(['alias', 'uuid']); - public function test_validates_input() - { - $this->withAuthorizationServerToken() - ->postJson(uri: self::ENDPOINT, data: ['alias' => 'alias']) - ->assertStatus(400); + $this->withServerToken() + ->post(uri: $this->endpoint, data: [ + 'uuid' => '069a79f444e94726a5befca90e38aaf5', + 'alias' => 'alias', + ]) + ->assertOk(); +}); - $this->withAuthorizationServerToken() - ->postJson(uri: self::ENDPOINT, data: ['uuid' => 'uuid']) - ->assertStatus(400); +it('updates last seen date', function () { + $this->freezeTime(function (Carbon $time) { + $uuid = '069a79f444e94726a5befca90e38aaf5'; + $oldTime = $time->copy()->subWeek(); + $player = MinecraftPlayer::factory()->create([ + 'uuid' => $uuid, + 'last_seen_at' => $oldTime, + ]); - $this->withAuthorizationServerToken() - ->postJson(uri: self::ENDPOINT, data: ['uuid' => 'uuid', 'alias' => 'alias']) + $this->assertDatabaseHas( + table: MinecraftPlayer::tableName(), + data: [ + 'player_minecraft_id' => $player->getKey(), + 'uuid' => $uuid, + 'last_seen_at' => $oldTime, + ], + ); + + $this->withServerToken() + ->post(uri: $this->endpoint, data: [ + 'uuid' => $uuid, + 'alias' => 'alias', + ]) ->assertOk(); - } - public function test_updates_last_seen_date() - { + $this->assertDatabaseHas( + table: MinecraftPlayer::tableName(), + data: [ + 'player_minecraft_id' => $player->getKey(), + 'uuid' => $uuid, + 'last_seen_at' => $time, + ], + ); + }); +}); + +it('updates alias', function () { + $this->freezeTime(function (Carbon $time) { + $uuid = '069a79f444e94726a5befca90e38aaf5'; $player = MinecraftPlayer::factory()->create([ - 'uuid' => 'uuid', - 'last_seen_at' => $this->now->copy()->subWeek(), + 'uuid' => $uuid, + 'alias' => 'old_alias', ]); - $this->withAuthorizationServerToken() - ->postJson(uri: self::ENDPOINT, data: ['uuid' => 'uuid', 'alias' => 'alias']) + $this->assertDatabaseHas( + table: MinecraftPlayer::tableName(), + data: [ + 'player_minecraft_id' => $player->getKey(), + 'uuid' => $uuid, + 'alias' => 'old_alias', + ], + ); + + $this->withServerToken() + ->post(uri: $this->endpoint, data: [ + 'uuid' => $uuid, + 'alias' => 'new_alias', + ]) ->assertOk(); $this->assertDatabaseHas( table: MinecraftPlayer::tableName(), data: [ 'player_minecraft_id' => $player->getKey(), - 'uuid' => 'uuid', - 'alias' => 'alias', - 'last_seen_at' => $this->now, + 'uuid' => $uuid, + 'alias' => 'new_alias', ], ); - } -} + }); +}); + +it('creates new player for uuid', function () { + $uuid = '069a79f444e94726a5befca90e38aaf5'; + $this->assertDatabaseMissing( + table: MinecraftPlayer::tableName(), + data: [ + 'uuid' => $uuid, + ], + ); + + $this->withServerToken() + ->post(uri: $this->endpoint, data: [ + 'uuid' => $uuid, + 'alias' => 'alias', + ]) + ->assertOk(); + + $this->assertDatabaseHas( + table: MinecraftPlayer::tableName(), + data: [ + 'uuid' => $uuid, + 'alias' => 'alias', + ], + ); +}); diff --git a/tests/Integration/Api/APIUnbanCreateTest.php b/tests/Integration/Api/APIUnbanCreateTest.php deleted file mode 100644 index 2fb01f76d..000000000 --- a/tests/Integration/Api/APIUnbanCreateTest.php +++ /dev/null @@ -1,130 +0,0 @@ -createServerToken(); - } - - private function validData(): array - { - return [ - 'banned_player_type' => PlayerIdentifierType::MINECRAFT_UUID->value, - 'banned_player_id' => 'uuid1', - 'unbanner_player_type' => PlayerIdentifierType::MINECRAFT_UUID->value, - 'unbanner_player_id' => 'uuid2', - ]; - } - - public function test_requires_scope() - { - GamePlayerBan::factory() - ->bannedPlayer(MinecraftPlayer::factory()->create(['uuid' => 'uuid1'])) - ->create(); - - $this->postJson(uri: self::ENDPOINT, data: $this->validData()) - ->assertUnauthorized(); - - $this->withAuthorizationServerToken() - ->postJson(uri: self::ENDPOINT, data: $this->validData()) - ->assertSuccessful(); - } - - public function test_throws_exception_if_not_banned() - { - $player1 = MinecraftPlayer::factory()->create(['uuid' => 'uuid1']); - $player2 = MinecraftPlayer::factory()->create(['uuid' => 'uuid2']); - - $this->withAuthorizationServerToken() - ->postJson(uri: self::ENDPOINT, data: [ - 'banned_player_type' => PlayerIdentifierType::MINECRAFT_UUID->value, - 'banned_player_id' => $player1->uuid, - 'unbanner_player_type' => PlayerIdentifierType::MINECRAFT_UUID->value, - 'unbanner_player_id' => $player2->uuid, - 'reason' => 'reason', - ]) - ->assertJson([ - 'error' => [ - 'id' => 'player_not_banned', - 'title' => '', - 'detail' => 'This player is not currently banned', - 'status' => 400, - ], - ]); - } - - public function test_unbans_permanent_ban() - { - $player1 = MinecraftPlayer::factory()->create(['uuid' => 'uuid1']); - $player2 = MinecraftPlayer::factory()->create(['uuid' => 'uuid2']); - - $ban = GamePlayerBan::factory() - ->bannedPlayer($player1) - ->create(); - - $this->withAuthorizationServerToken() - ->postJson(uri: self::ENDPOINT, data: [ - 'banned_player_type' => PlayerIdentifierType::MINECRAFT_UUID->value, - 'banned_player_id' => $player1->uuid, - 'unbanner_player_type' => PlayerIdentifierType::MINECRAFT_UUID->value, - 'unbanner_player_id' => $player2->uuid, - ]) - ->assertSuccessful(); - - $this->assertDatabaseHas( - table: GamePlayerBan::tableName(), - data: [ - 'id' => $ban->getKey(), - 'unbanned_at' => now(), - 'unbanner_player_id' => $player2->getKey(), - 'unban_type' => UnbanType::MANUAL->value, - ], - ); - } - - public function test_unbans_temporary_ban() - { - $player1 = MinecraftPlayer::factory()->create(['uuid' => 'uuid1']); - $player2 = MinecraftPlayer::factory()->create(['uuid' => 'uuid2']); - - $ban = GamePlayerBan::factory() - ->temporary() - ->bannedPlayer($player1) - ->create(); - - $this->withAuthorizationServerToken() - ->postJson(uri: self::ENDPOINT, data: [ - 'banned_player_type' => PlayerIdentifierType::MINECRAFT_UUID->value, - 'banned_player_id' => $player1->uuid, - 'unbanner_player_type' => PlayerIdentifierType::MINECRAFT_UUID->value, - 'unbanner_player_id' => $player2->uuid, - ]) - ->assertSuccessful(); - - $this->assertDatabaseHas( - table: GamePlayerBan::tableName(), - data: [ - 'id' => $ban->getKey(), - 'unbanned_at' => now(), - 'unbanner_player_id' => $player2->getKey(), - 'unban_type' => UnbanType::MANUAL->value, - ], - ); - } -} diff --git a/tests/Integration/Api/APIUnbanIPCreateTest.php b/tests/Integration/Api/APIUnbanIPCreateTest.php deleted file mode 100644 index bccffbdb0..000000000 --- a/tests/Integration/Api/APIUnbanIPCreateTest.php +++ /dev/null @@ -1,95 +0,0 @@ -createServerToken(); - } - - private function validData(): array - { - return [ - 'ip_address' => '192.168.0.1', - 'unbanner_player_type' => PlayerIdentifierType::MINECRAFT_UUID->value, - 'unbanner_player_id' => 'uuid', - ]; - } - - public function test_requires_scope() - { - GameIPBan::factory() - ->bannedBy(MinecraftPlayer::factory()) - ->create(['ip_address' => '192.168.0.1']); - - $this->postJson(uri: self::ENDPOINT, data: $this->validData()) - ->assertUnauthorized(); - - $this->withAuthorizationServerToken() - ->postJson(uri: self::ENDPOINT, data: $this->validData()) - ->assertSuccessful(); - } - - public function test_throws_exception_if_not_banned() - { - $player = MinecraftPlayer::factory()->create(['uuid' => 'uuid1']); - - $this->withAuthorizationServerToken() - ->postJson(uri: self::ENDPOINT, data: [ - 'ip_address' => '192.168.0.1', - 'unbanner_player_type' => PlayerIdentifierType::MINECRAFT_UUID->value, - 'unbanner_player_id' => $player->uuid, - 'reason' => 'reason', - ]) - ->assertJson([ - 'error' => [ - 'id' => 'ip_not_banned', - 'title' => '', - 'detail' => 'This IP address is not currently banned', - 'status' => 400, - ], - ]); - } - - public function test_unbans_ban() - { - $player = MinecraftPlayer::factory()->create(); - - $ban = GameIPBan::factory() - ->bannedBy($player) - ->create(); - - $this->withAuthorizationServerToken() - ->postJson(uri: self::ENDPOINT, data: [ - 'ip_address' => $ban->ip_address, - 'unbanner_player_type' => PlayerIdentifierType::MINECRAFT_UUID->value, - 'unbanner_player_id' => $player->uuid, - ]) - ->assertSuccessful(); - - $this->assertDatabaseHas( - table: GameIPBan::tableName(), - data: [ - 'id' => $ban->getKey(), - 'unbanned_at' => now(), - 'unbanner_player_id' => $player->getKey(), - 'unban_type' => UnbanType::MANUAL->value, - ], - ); - } -} diff --git a/tests/Integration/Api/APIWarningAcknowledgeTest.php b/tests/Integration/Api/APIWarningAcknowledgeTest.php deleted file mode 100644 index be1b1a5fe..000000000 --- a/tests/Integration/Api/APIWarningAcknowledgeTest.php +++ /dev/null @@ -1,93 +0,0 @@ -createServerToken(); - } - - private function validData(): array - { - $warning = PlayerWarning::factory() - ->for(MinecraftPlayer::factory(), 'warnedPlayer') - ->for(MinecraftPlayer::factory(), 'warnerPlayer') - ->acknowledged(false) - ->create(); - - return ['warning_id' => $warning->getKey()]; - } - - public function test_requires_scope() - { - $this->postJson(uri: self::ENDPOINT, data: $this->validData()) - ->assertUnauthorized(); - - $this->withAuthorizationServerToken() - ->postJson(uri: self::ENDPOINT, data: $this->validData()) - ->assertSuccessful(); - } - - public function test_acknowledges_warning() - { - $player1 = MinecraftPlayer::factory()->create(['uuid' => 'uuid1']); - $player2 = MinecraftPlayer::factory()->create(['uuid' => 'uuid2']); - - $warning = PlayerWarning::factory() - ->for($player1, 'warnedPlayer') - ->for($player2, 'warnerPlayer') - ->acknowledged(false) - ->create(); - - $this->assertDatabaseHas( - table: PlayerWarning::tableName(), - data: [ - 'id' => $warning->getKey(), - 'warned_player_id' => $player1->getKey(), - 'warner_player_id' => $player2->getKey(), - 'reason' => $warning->reason, - 'additional_info' => $warning->additional_info, - 'weight' => $warning->weight, - 'is_acknowledged' => false, - 'created_at' => $warning->created_at, - 'updated_at' => $warning->updated_at, - 'acknowledged_at' => null, - ], - ); - - $this->withAuthorizationServerToken() - ->postJson(uri: self::ENDPOINT, data: [ - 'warning_id' => $warning->getKey(), - ]) - ->assertSuccessful(); - - $this->assertDatabaseHas( - table: PlayerWarning::tableName(), - data: [ - 'id' => $warning->getKey(), - 'warned_player_id' => $player1->getKey(), - 'warner_player_id' => $player2->getKey(), - 'reason' => $warning->reason, - 'additional_info' => $warning->additional_info, - 'weight' => $warning->weight, - 'is_acknowledged' => true, - 'created_at' => $warning->created_at, - 'updated_at' => now(), - 'acknowledged_at' => now(), - ], - ); - } -} diff --git a/tests/Integration/Api/APIWarningAllTest.php b/tests/Integration/Api/APIWarningAllTest.php deleted file mode 100644 index 402e5d1a5..000000000 --- a/tests/Integration/Api/APIWarningAllTest.php +++ /dev/null @@ -1,105 +0,0 @@ -createServerToken(); - } - - private function validData(): array - { - return [ - 'player_type' => PlayerIdentifierType::MINECRAFT_UUID->value, - 'player_id' => 'uuid1', - 'player_alias' => 'alias1', - ]; - } - - public function test_requires_scope() - { - $this->getJson(uri: self::ENDPOINT.'?'.http_build_query($this->validData())) - ->assertUnauthorized(); - - $this->withAuthorizationServerToken() - ->getJson(uri: self::ENDPOINT.'?'.http_build_query($this->validData())) - ->assertSuccessful(); - } - - public function test_shows_warnings() - { - $player = MinecraftPlayer::factory()->create(); - - $warning1 = PlayerWarning::factory() - ->for($player, 'warnedPlayer') - ->for(MinecraftPlayer::factory(), 'warnerPlayer') - ->createdAt(now()) - ->create(); - - $warning2 = PlayerWarning::factory() - ->for($player, 'warnedPlayer') - ->for(MinecraftPlayer::factory(), 'warnerPlayer') - ->createdAt(now()->subDay()) - ->create(); - - $this->withAuthorizationServerToken() - ->getJson(uri: self::ENDPOINT.'?'.http_build_query([ - 'player_type' => PlayerIdentifierType::MINECRAFT_UUID->value, - 'player_id' => $player->uuid, - 'player_alias' => 'alias1', - ])) - ->assertJson([ - 'data' => [ - [ - 'id' => $warning1->getKey(), - 'warned_player_id' => $warning1->warned_player_id, - 'warner_player_id' => $warning1->warner_player_id, - 'reason' => $warning1->reason, - 'weight' => $warning1->weight, - 'is_acknowledged' => $warning1->is_acknowledged, - 'created_at' => $warning1->created_at->timestamp, - 'updated_at' => $warning1->updated_at->timestamp, - ], - [ - 'id' => $warning2->getKey(), - 'warned_player_id' => $warning2->warned_player_id, - 'warner_player_id' => $warning2->warner_player_id, - 'reason' => $warning2->reason, - 'weight' => $warning2->weight, - 'is_acknowledged' => $warning2->is_acknowledged, - 'created_at' => $warning2->created_at->timestamp, - 'updated_at' => $warning2->updated_at->timestamp, - ], - ], - ]) - ->assertSuccessful(); - } - - public function test_shows_no_warnings() - { - $player = MinecraftPlayer::factory()->create(['uuid' => 'uuid1']); - - $this->withAuthorizationServerToken() - ->getJson(uri: self::ENDPOINT.'?'.http_build_query([ - 'player_type' => PlayerIdentifierType::MINECRAFT_UUID->value, - 'player_id' => $player->uuid, - 'player_alias' => 'alias1', - ])) - ->assertJson(['data' => []]) - ->assertSuccessful(); - } -} diff --git a/tests/Integration/Api/APIWarningCreateTest.php b/tests/Integration/Api/APIWarningCreateTest.php deleted file mode 100644 index 5bffb249c..000000000 --- a/tests/Integration/Api/APIWarningCreateTest.php +++ /dev/null @@ -1,78 +0,0 @@ -createServerToken(); - } - - private function validData(): array - { - return [ - 'warned_player_type' => PlayerIdentifierType::MINECRAFT_UUID->value, - 'warned_player_id' => 'uuid1', - 'warned_player_alias' => 'alias1', - 'warner_player_type' => PlayerIdentifierType::MINECRAFT_UUID->value, - 'warner_player_id' => 'uuid2', - 'warner_player_alias' => 'alias2', - 'reason' => 'reason', - 'weight' => 5, - ]; - } - - public function test_requires_scope() - { - $this->postJson(uri: self::ENDPOINT, data: $this->validData()) - ->assertUnauthorized(); - - $this->withAuthorizationServerToken() - ->postJson(uri: self::ENDPOINT, data: $this->validData()) - ->assertSuccessful(); - } - - public function test_creates_warning() - { - $player1 = MinecraftPlayer::factory()->create(['uuid' => 'uuid1']); - $player2 = MinecraftPlayer::factory()->create(['uuid' => 'uuid2']); - - $this->withAuthorizationServerToken() - ->postJson(uri: self::ENDPOINT, data: [ - 'warned_player_type' => PlayerIdentifierType::MINECRAFT_UUID->value, - 'warned_player_id' => $player1->uuid, - 'warned_player_alias' => 'alias1', - 'warner_player_type' => PlayerIdentifierType::MINECRAFT_UUID->value, - 'warner_player_id' => $player2->uuid, - 'warner_player_alias' => 'alias2', - 'reason' => 'reason', - 'weight' => 5, - ]) - ->assertSuccessful(); - - $this->assertDatabaseHas( - table: PlayerWarning::tableName(), - data: [ - 'warned_player_id' => $player1->getKey(), - 'warner_player_id' => $player2->getKey(), - 'reason' => 'reason', - 'weight' => 5, - 'created_at' => $this->now, - 'updated_at' => $this->now, - ], - ); - } -} diff --git a/tests/Integration/Api/v3/MinecraftRegisterCompleteTest.php b/tests/Integration/Api/v3/MinecraftRegisterCompleteTest.php index d884784c2..6484baf5f 100644 --- a/tests/Integration/Api/v3/MinecraftRegisterCompleteTest.php +++ b/tests/Integration/Api/v3/MinecraftRegisterCompleteTest.php @@ -1,12 +1,9 @@ mock(LookupPlayerBan::class, function (MockInterface $mock) use ($username, $ban) { $mock->shouldReceive('execute') @@ -69,31 +67,31 @@ public function test_errors_if_throws_rate_limit() public function test_errors_if_no_active_bans() { $mcPlayer = MinecraftPlayer::factory()->create(); - $ban = GamePlayerBan::factory()->inactive()->for($mcPlayer, 'bannedPlayer')->create(); - $this->mockUseCaseToThrow(NotBannedException::class); + GamePlayerBan::factory()->inactive()->for($mcPlayer, 'bannedPlayer')->create(); + $this->mockUseCaseToReturnBan('Herobrine', null); $this->post(route('front.bans.lookup'), ['username' => 'Herobrine']) ->assertSessionHasErrors(); } public function test_errors_if_no_bans() { - $mcPlayer = MinecraftPlayer::factory()->create(); - $this->mockUseCaseToThrow(NotBannedException::class); + MinecraftPlayer::factory()->create(); + $this->mockUseCaseToReturnBan('Herobrine', null); $this->post(route('front.bans.lookup'), ['username' => 'Herobrine']) ->assertSessionHasErrors(); } public function test_errors_if_not_valid_username() { - $mcPlayer = MinecraftPlayer::factory()->create(); - $this->mockUseCaseToThrow(PlayerNotFoundException::class); + MinecraftPlayer::factory()->create(); + $this->mockUseCaseToReturnBan('Herobrine', null); $this->post(route('front.bans.lookup'), ['username' => 'Herobrine']) ->assertSessionHasErrors(); } public function test_errors_if_player_not_known() { - $this->mockUseCaseToThrow(PlayerNotFoundException::class); + $this->mockUseCaseToReturnBan('Herobrine', null); $this->post(route('front.bans.lookup'), ['username' => 'Herobrine']) ->assertSessionHasErrors(); } diff --git a/tests/IntegrationTestCase.php b/tests/IntegrationTestCase.php index bc131c617..f1d48d125 100644 --- a/tests/IntegrationTestCase.php +++ b/tests/IntegrationTestCase.php @@ -46,6 +46,7 @@ protected function loadJsonFromFile(string $path): array return json_decode($json, associative: true); } + /** @deprecated */ protected function createServerToken(): ServerToken { $server = Server::factory()->create(); @@ -54,6 +55,7 @@ protected function createServerToken(): ServerToken return $this->token; } + /** @deprecated */ protected function withAuthorizationServerToken(): TestCase { return $this->withHeader( diff --git a/tests/Unit/App/Core/Domains/PlayerLookup/ConcretePlayerLookupTest.php b/tests/Unit/App/Core/Domains/PlayerLookup/ConcretePlayerLookupTest.php deleted file mode 100644 index 119c79949..000000000 --- a/tests/Unit/App/Core/Domains/PlayerLookup/ConcretePlayerLookupTest.php +++ /dev/null @@ -1,187 +0,0 @@ -minecraftPlayerRepository = \Mockery::mock(MinecraftPlayerRepository::class); - $this->minecraftPlayerAliasRepository = \Mockery::mock(MinecraftPlayerAliasRepository::class); - - $this->playerLookup = new ConcretePlayerLookup( - minecraftPlayerRepository: $this->minecraftPlayerRepository, - minecraftPlayerAliasRepository: $this->minecraftPlayerAliasRepository, - ); - } - - public function test_find_returns_null_if_no_player() - { - $this->minecraftPlayerRepository - ->shouldReceive('getByUUID') - ->andReturnNull(); - - $player = $this->playerLookup->find( - identifier: PlayerIdentifier::minecraftUUID('uuid'), - ); - - $this->assertNull($player); - } - - public function test_find_returns_minecraft_player_by_uuid() - { - $player = MinecraftPlayer::factory()->create(); - - $this->minecraftPlayerRepository - ->shouldReceive('getByUUID') - ->andReturn($player); - - $actual = $this->playerLookup->find( - identifier: PlayerIdentifier::minecraftUUID('uuid'), - ); - - $this->assertEquals( - expected: $player->getKey(), - actual: $actual->getKey(), - ); - } - - public function test_find_returns_minecraft_player_by_id() - { - $player = MinecraftPlayer::factory()->create(); - - $this->minecraftPlayerRepository - ->shouldReceive('getById') - ->andReturn($player); - - $actual = $this->playerLookup->find( - identifier: PlayerIdentifier::pcbAccountId(1), - ); - - $this->assertEquals( - expected: $player->getKey(), - actual: $actual->getKey(), - ); - } - - public function test_findOrCreate_returns_existing_player_by_uuid() - { - $player = MinecraftPlayer::factory()->create(); - - $this->minecraftPlayerRepository - ->shouldReceive('getByUUID') - ->andReturn($player); - - $actual = $this->playerLookup->findOrCreate( - identifier: PlayerIdentifier::minecraftUUID('uuid'), - ); - - $this->assertEquals( - expected: $player->getKey(), - actual: $actual->getKey(), - ); - } - - public function test_findOrCreate_returns_existing_player_by_id() - { - $player = MinecraftPlayer::factory()->create(); - - $this->minecraftPlayerRepository - ->shouldReceive('getById') - ->andReturn($player); - - $actual = $this->playerLookup->findOrCreate( - identifier: PlayerIdentifier::pcbAccountId(1), - ); - - $this->assertEquals( - expected: $player->getKey(), - actual: $actual->getKey(), - ); - } - - public function test_findOrCreate_exception_if_looking_up_nonexistent_id() - { - $this->minecraftPlayerRepository - ->shouldReceive('getById') - ->andReturnNull(); - - $this->expectException(NonCreatableIdentifierException::class); - - $player = $this->playerLookup->findOrCreate( - identifier: PlayerIdentifier::pcbAccountId(34), - ); - } - - public function test_findOrCreate_creates_new_player() - { - $newPlayer = MinecraftPlayer::factory()->make(); - - $this->minecraftPlayerRepository - ->shouldReceive('getByUUID') - ->andReturnNull(); - - $this->minecraftPlayerRepository - ->shouldReceive('store') - ->andReturn($newPlayer); - - $player = $this->playerLookup->findOrCreate( - identifier: PlayerIdentifier::minecraftUUID('uuid'), - ); - - $this->assertEquals( - expected: $newPlayer->getKey(), - actual: $player->getKey(), - ); - } - - public function test_findOrCreate_creates_new_player_with_alias() - { - $now = Carbon::create(year: 2022, month: 4, day: 19, hour: 10, minute: 9, second: 8); - Carbon::setTestNow($now); - - $newPlayer = MinecraftPlayer::factory()->create(); - $alias = 'alias'; - - $this->minecraftPlayerRepository - ->shouldReceive('getByUUID') - ->andReturnNull(); - - $this->minecraftPlayerRepository - ->shouldReceive('store') - ->andReturn($newPlayer); - - $this->minecraftPlayerAliasRepository - ->shouldReceive('store') - ->andReturn(MinecraftPlayerAlias::factory()->make()); - - $player = $this->playerLookup->findOrCreate( - identifier: PlayerIdentifier::minecraftUUID('uuid'), - playerAlias: $alias, - ); - - $this->assertEquals( - expected: $newPlayer->getKey(), - actual: $player->getKey(), - ); - } -} diff --git a/tests/Unit/Domain/BanAppeals/UseCases/CreateBanAppealTest.php b/tests/Unit/Domain/BanAppeals/UseCases/CreateBanAppealTest.php deleted file mode 100644 index ed0e929ba..000000000 --- a/tests/Unit/Domain/BanAppeals/UseCases/CreateBanAppealTest.php +++ /dev/null @@ -1,132 +0,0 @@ -banAppealRepository = \Mockery::mock(BanAppealRepository::class); - $this->useCase = new CreateBanAppeal( - banAppealRepository: $this->banAppealRepository - ); - $this->gamePlayerBan = GamePlayerBan::factory()->for(MinecraftPlayer::factory(), 'bannedPlayer')->create(); - - $this->banAppeal = \Mockery::mock(BanAppeal::class); - $this->banAppeal->makePartial() - ->allows([ - 'showLink' => 'https://example.org', - ]); - } - - public function test_creates_appeal() - { - $this->banAppealRepository - ->shouldReceive('create') - ->with($this->gamePlayerBan->getKey(), false, 'Explanation', 'test@example.org') - ->andReturn($this->banAppeal); - - $this->useCase->execute($this->gamePlayerBan, 'Explanation', loggedInAccount: null, email: 'test@example.org'); - - // Skip risky warning - $this->assertTrue(true); - } - - public function test_requires_email_with_no_logged_in_account() - { - $this->expectException(EmailRequiredException::class); - $this->useCase->execute($this->gamePlayerBan, 'Explanation', loggedInAccount: null, email: null); - } - - public function test_requires_email_if_accounts_not_matching() - { - $this->expectException(EmailRequiredException::class); - $this->gamePlayerBan->bannedPlayer->account()->associate(Account::factory()->create()); - $this->useCase->execute($this->gamePlayerBan, 'Explanation', loggedInAccount: Account::factory()->create(), email: null); - } - - public function test_email_not_required_if_account_matches() - { - $account = Account::factory()->create(); - $this->gamePlayerBan->bannedPlayer->account()->associate($account); - $this->banAppealRepository - ->shouldReceive('create') - ->with($this->gamePlayerBan->getKey(), true, 'Explanation', null) - ->andReturn($this->banAppeal); - - $this->useCase->execute($this->gamePlayerBan, 'Explanation', loggedInAccount: $account, email: null); - - // Skip risky warning - $this->assertTrue(true); - } - - public function test_sends_email_to_to_appeal_notifiable() - { - Notification::assertNothingSent(); - $this->banAppealRepository - ->allows('create') - ->withAnyArgs() - ->andReturn($this->banAppeal); - $banAppeal = $this->useCase->execute($this->gamePlayerBan, 'Explanation', loggedInAccount: null, email: 'test@example.org'); - Notification::assertSentTo([$banAppeal], BanAppealConfirmationNotification::class); - } - - public function test_sets_verified_if_account_matches_player_owner() - { - $account = Account::factory()->create(); - $this->gamePlayerBan->bannedPlayer->account()->associate($account); - $this->banAppealRepository - ->shouldReceive('create') - ->with($this->gamePlayerBan->getKey(), true, 'Explanation', null) - ->andReturn($this->banAppeal); - $this->useCase->execute($this->gamePlayerBan, 'Explanation', loggedInAccount: $account, email: null); - - // Skip risky warning - $this->assertTrue(true); - } - - public function test_sets_not_verified_if_no_account_specified() - { - $this->gamePlayerBan->bannedPlayer->account()->associate(Account::factory()->create()); - $this->banAppealRepository - ->shouldReceive('create') - ->with($this->gamePlayerBan->getKey(), false, 'Explanation', 'test@example.org') - ->andReturn($this->banAppeal); - $this->useCase->execute($this->gamePlayerBan, 'Explanation', loggedInAccount: null, email: 'test@example.org'); - - // Skip risky warning - $this->assertTrue(true); - } - - public function test_sets_not_verified_if_different_account_used() - { - $this->gamePlayerBan->bannedPlayer->account()->associate(Account::factory()->create()); - $this->banAppealRepository - ->shouldReceive('create') - ->with($this->gamePlayerBan->getKey(), false, 'Explanation', 'test@example.org') - ->andReturn($this->banAppeal); - $this->useCase->execute($this->gamePlayerBan, 'Explanation', loggedInAccount: Account::factory()->create(), email: 'test@example.org'); - - // Skip risky warning - $this->assertTrue(true); - } -} diff --git a/tests/Unit/Domain/BanAppeals/UseCases/UpdateBanAppealTest.php b/tests/Unit/Domain/BanAppeals/UseCases/UpdateBanAppealTest.php deleted file mode 100644 index ee084fa51..000000000 --- a/tests/Unit/Domain/BanAppeals/UseCases/UpdateBanAppealTest.php +++ /dev/null @@ -1,147 +0,0 @@ -banAppealRepository = \Mockery::mock(BanAppealRepository::class); - $this->unbanUseCase = \Mockery::mock(CreatePlayerUnban::class); - $this->useCase = new UpdateBanAppeal( - banAppealRepository: $this->banAppealRepository, - unbanUseCase: $this->unbanUseCase - ); - - $this->decidingAccount = Account::factory()->create(); - $this->decidingPlayer = MinecraftPlayer::factory()->for($this->decidingAccount)->create(); - $this->bannedPlayer = MinecraftPlayer::factory()->create(); - $this->gamePlayerBan = GamePlayerBan::factory()->bannedPlayer($this->bannedPlayer)->create(); - $this->banAppeal = BanAppeal::factory()->for($this->gamePlayerBan)->create(); - } - - public function test_can_unban() - { - $this->banAppealRepository->expects('updateDecision') - ->once() - ->with($this->banAppeal, $this->decisionNote, $this->decidingPlayer->getKey(), BanAppealStatus::ACCEPTED_UNBAN); - - $this->unbanUseCase->expects('execute') - ->once() - ->with( - \Mockery::on(function ($arg) { - return $arg->key == $this->bannedPlayer->getkey(); - }), - \Mockery::on(function ($arg) { - return $arg->key == $this->decidingPlayer->getKey(); - }), - UnbanType::APPEALED, - )->andReturn($this->gamePlayerBan); - - $this->useCase->execute( - banAppeal: $this->banAppeal, - decidingAccount: $this->decidingAccount, - decisionNote: $this->decisionNote, - status: BanAppealStatus::ACCEPTED_UNBAN - ); - } - - public function test_can_deny() - { - $this->banAppealRepository->expects('updateDecision') - ->once() - ->with($this->banAppeal, $this->decisionNote, $this->decidingPlayer->getKey(), BanAppealStatus::DENIED); - - $this->unbanUseCase->expects('execute')->never(); - - $this->useCase->execute( - banAppeal: $this->banAppeal, - decidingAccount: $this->decidingAccount, - decisionNote: $this->decisionNote, - status: BanAppealStatus::DENIED - ); - } - - /** - * TODO: implement once tempbans are sorted - */ - public function test_rejects_tempban() - { - $this->expectException(NotImplementedException::class); - $this->useCase->execute( - banAppeal: $this->banAppeal, - decidingAccount: $this->decidingAccount, - decisionNote: $this->decisionNote, - status: BanAppealStatus::ACCEPTED_TEMPBAN - ); - } - - public function test_throws_exception_if_appeal_decided() - { - $decidedAppeal = BanAppeal::factory()->unbanned()->for($this->gamePlayerBan)->create(); - $this->expectException(AppealAlreadyDecidedException::class); - $this->useCase->execute( - banAppeal: $decidedAppeal, - decidingAccount: $this->decidingAccount, - decisionNote: $this->decisionNote, - status: BanAppealStatus::ACCEPTED_UNBAN, - ); - } - - public function test_throws_exception_if_no_player_for_action() - { - $accountWithNoPlayer = Account::factory()->create(); - $this->expectException(NoPlayerForActionException::class); - $this->useCase->execute( - banAppeal: $this->banAppeal, - decidingAccount: $accountWithNoPlayer, - decisionNote: $this->decisionNote, - status: BanAppealStatus::ACCEPTED_UNBAN, - ); - } - - public function test_throws_exception_if_unbanned_manually() - { - $this->banAppealRepository->expects('updateDecision') - ->once(); - - $this->unbanUseCase->expects('execute') - ->once() - ->andThrows(NotBannedException::class); - - $this->expectException(NotBannedException::class); - $this->useCase->execute( - banAppeal: $this->banAppeal, - decidingAccount: $this->decidingAccount, - decisionNote: $this->decisionNote, - status: BanAppealStatus::ACCEPTED_UNBAN, - ); - } -} diff --git a/tests/Unit/Domain/Bans/UseCases/CreateBanTest.php b/tests/Unit/Domain/Bans/UseCases/CreateBanTest.php deleted file mode 100644 index 9007787c0..000000000 --- a/tests/Unit/Domain/Bans/UseCases/CreateBanTest.php +++ /dev/null @@ -1,93 +0,0 @@ -gamePlayerBanRepository = \Mockery::mock(GamePlayerBanRepository::class); - $this->playerLookup = \Mockery::mock(ConcretePlayerLookup::class); - - $this->useCase = new CreatePlayerBan( - gamePlayerBanRepository: $this->gamePlayerBanRepository, - playerLookup: $this->playerLookup, - ); - } - - public function test_throws_exception_if_already_banned() - { - $this->playerLookup - ->shouldReceive('findOrCreate') - ->andReturn(MinecraftPlayer::factory()->make()); - - $this->gamePlayerBanRepository - ->shouldReceive('firstActiveBan') - ->andReturn(GamePlayerBan::factory()->make()); - - $this->expectException(AlreadyPermBannedException::class); - - $this->useCase->execute( - serverId: 1, - bannedPlayerIdentifier: PlayerIdentifier::minecraftUUID('uuid1'), - bannedPlayerAlias: 'Herobrine', - bannerPlayerIdentifier: PlayerIdentifier::minecraftUUID('uuid2'), - bannerPlayerAlias: 'Notch', - banReason: 'test', - expiresAt: null, - ); - } - - public function test_creates_ban() - { - $bannedPlayer = MinecraftPlayer::factory()->create(); - $bannerPlayer = MinecraftPlayer::factory()->create(); - $ban = GamePlayerBan::factory()->make(); - - $this->playerLookup - ->shouldReceive('findOrCreate') - ->andReturn($bannedPlayer); - - $this->playerLookup - ->shouldReceive('findOrCreate') - ->andReturn($bannerPlayer); - - $this->gamePlayerBanRepository - ->shouldReceive('firstActiveBan') - ->andReturn(null); - - $this->gamePlayerBanRepository - ->shouldReceive('create') - ->andReturn($ban); - - $this->gamePlayerBanRepository - ->shouldReceive('deactivateAllTemporaryBans'); - - $returnedBan = $this->useCase->execute( - serverId: 1, - bannedPlayerIdentifier: PlayerIdentifier::minecraftUUID('uuid1'), - bannedPlayerAlias: 'Herobrine', - bannerPlayerIdentifier: PlayerIdentifier::minecraftUUID('uuid2'), - bannerPlayerAlias: 'Notch', - banReason: 'test', - expiresAt: null, - ); - - $this->assertEquals(expected: $ban, actual: $returnedBan); - } -} diff --git a/tests/Unit/Domain/Bans/UseCases/LookupBanTest.php b/tests/Unit/Domain/Bans/UseCases/LookupBanTest.php deleted file mode 100644 index 5b42e272c..000000000 --- a/tests/Unit/Domain/Bans/UseCases/LookupBanTest.php +++ /dev/null @@ -1,118 +0,0 @@ -mojangPlayerApi = \Mockery::mock(MojangPlayerApi::class); - $this->gamePlayerBanRepository = \Mockery::mock(GamePlayerBanRepository::class); - $this->minecraftPlayerRepository = \Mockery::mock(MinecraftPlayerRepository::class); - - $this->useCase = new LookupPlayerBan( - mojangPlayerApi: $this->mojangPlayerApi, - gamePlayerBanRepository: $this->gamePlayerBanRepository, - minecraftPlayerRepository: $this->minecraftPlayerRepository - ); - } - - private function mockMojangApiToReturn($username, $uuid) - { - $this->mojangPlayerApi - ->shouldReceive('getUuidOf') - ->once() - ->with($username) - ->once()->andReturn( - new MojangPlayer($uuid, $username) - ); - } - - private function mockPlayerRepositoryToReturn($uuid, $player) - { - $this->minecraftPlayerRepository - ->shouldReceive('getByUUID') - ->once() - ->with(\Mockery::on(function ($arg) use ($uuid) { - return $arg->rawValue() == $uuid; - })) - ->andReturn($player); - } - - public function mockgamePlayerBanRepositoryToReturn($playerId, $bans) - { - $this->gamePlayerBanRepository - ->shouldReceive('firstActiveBan') - ->once() - ->with( - \Mockery::on(function ($arg) use ($playerId) { - return $arg->getKey() == $playerId; - }), - ) - ->andReturn($bans); - } - - public function test_throws_exception_if_player_doesnt_exist() - { - $this->mojangPlayerApi - ->shouldReceive('getUuidOf') - ->once() - ->with('Herobrine') - ->andReturn(null); - $this->expectException(PlayerNotFoundException::class); - - $this->useCase->execute('Herobrine'); - } - - public function test_throws_exception_if_player_not_known() - { - $this->mockMojangApiToReturn('Herobrine', 'abc123'); - $this->mockPlayerRepositoryToReturn('abc123', null); - $this->expectException(NotBannedException::class); - $this->useCase->execute('Herobrine'); - } - - public function test_throws_exception_if_no_active_bans() - { - $mcPlayer = MinecraftPlayer::factory()->create(['uuid' => 'abc123']); - $this->mockMojangApiToReturn('Herobrine', 'abc123'); - $this->mockPlayerRepositoryToReturn('abc123', $mcPlayer); - $this->mockgamePlayerBanRepositoryToReturn($mcPlayer->getKey(), null); - - $this->expectException(NotBannedException::class); - - $this->useCase->execute('Herobrine'); - } - - public function test_returns_active_ban_if_exists() - { - $mcPlayer = MinecraftPlayer::factory()->create(['uuid' => 'abc123']); - $this->mockMojangApiToReturn('Herobrine', 'abc123'); - $this->mockPlayerRepositoryToReturn('abc123', $mcPlayer); - $gamePlayerBanInst = GamePlayerBan::factory()->make(); - $this->mockgamePlayerBanRepositoryToReturn($mcPlayer->getKey(), $gamePlayerBanInst); - - $this->assertEquals( - $gamePlayerBanInst, - $this->useCase->execute('Herobrine') - ); - } -} diff --git a/tests/Unit/Domain/MinecraftTelemetry/UseCases/UpdateSeenMinecraftPlayerTest.php b/tests/Unit/Domain/MinecraftTelemetry/UseCases/UpdateSeenMinecraftPlayerTest.php deleted file mode 100644 index 5197540df..000000000 --- a/tests/Unit/Domain/MinecraftTelemetry/UseCases/UpdateSeenMinecraftPlayerTest.php +++ /dev/null @@ -1,84 +0,0 @@ -playerLookup = \Mockery::mock(ConcretePlayerLookup::class); - - $this->useCase = new UpdateSeenMinecraftPlayer( - playerLookup: $this->playerLookup, - ); - } - - public function test_updates_last_seen_date() - { - $now = $this->setTestNow(); - $before = $now->copy()->subWeek(); - - $player = MinecraftPlayer::factory()->create([ - 'uuid' => 'uuid', - 'alias' => 'alias', - 'last_seen_at' => $before, - ]); - - $this->playerLookup - ->shouldReceive('findOrCreate') - ->andReturn($player); - - $this->assertEquals( - expected: $before, - actual: $player->last_seen_at, - ); - - $this->useCase->execute(uuid: 'uuid', alias: 'alias'); - - $this->assertEquals( - expected: $now, - actual: $player->last_seen_at, - ); - } - - public function test_updates_alias() - { - $now = $this->setTestNow(); - - $player = MinecraftPlayer::factory()->create([ - 'uuid' => 'uuid', - 'alias' => 'old_alias', - 'last_synced_at' => $now->copy()->subWeek(), - ]); - - $this->assertDatabaseHas('players_minecraft', [ - 'uuid' => 'uuid', - 'alias' => 'old_alias', - ]); - - $this->playerLookup - ->shouldReceive('findOrCreate') - ->andReturn($player); - - $this->useCase->execute(uuid: 'uuid', alias: 'new_alias'); - - $this->assertDatabaseHas('players_minecraft', [ - 'uuid' => 'uuid', - 'alias' => 'new_alias', - ]); - } -} diff --git a/tests/Unit/Domain/Warnings/UseCases/AcknowledgeWarningTest.php b/tests/Unit/Domain/Warnings/UseCases/AcknowledgeWarningTest.php deleted file mode 100644 index 0a47c1d00..000000000 --- a/tests/Unit/Domain/Warnings/UseCases/AcknowledgeWarningTest.php +++ /dev/null @@ -1,102 +0,0 @@ -playerWarningRepository = new PlayerWarningMockRepository(); - - $this->useCase = new AcknowledgeWarning( - playerWarningRepository: $this->playerWarningRepository, - ); - } - - public function test_throws_404_if_warning_not_found() - { - $this->playerWarningRepository->find = null; - $this->expectException(NotFoundHttpException::class); - $this->useCase->execute(warningId: 1); - } - - public function test_throws_403_if_warned_player_is_different() - { - $warning = PlayerWarning::factory() - ->id() - ->warnedPlayer( - MinecraftPlayer::factory()->id()->for(Account::factory(['account_id' => 1])) - ) - ->warnedBy(MinecraftPlayer::factory()) - ->make(); - - $this->playerWarningRepository->find = $warning; - - try { - $this->useCase->execute( - warningId: $warning->getKey(), - accountId: 2, - ); - } catch (HttpException $e) { - } - - $this->assertEquals( - expected: new HttpException(403), - actual: $e, - ); - } - - public function test_throws_410_if_warning_already_acknowledged() - { - $warning = PlayerWarning::factory() - ->id() - ->withPlayers() - ->acknowledged() - ->make(); - - $this->playerWarningRepository->find = $warning; - - try { - $this->useCase->execute(warningId: $warning->getKey()); - } catch (HttpException $e) { - } - - $this->assertEquals( - expected: new HttpException(410), - actual: $e, - ); - } - - public function test_acknowledges_warning() - { - $this->setTestNow(); - - $warning = PlayerWarning::factory() - ->id() - ->acknowledged(false) - ->withPlayers() - ->make(); - - $this->playerWarningRepository->find = $warning; - - $this->useCase->execute(warningId: $warning->getKey()); - - $this->assertTrue($warning->is_acknowledged); - $this->assertEquals($warning->acknowledged_at, now()); - } -} diff --git a/tests/Unit/Domain/Warnings/UseCases/CreateWarningTest.php b/tests/Unit/Domain/Warnings/UseCases/CreateWarningTest.php deleted file mode 100644 index d1b392b58..000000000 --- a/tests/Unit/Domain/Warnings/UseCases/CreateWarningTest.php +++ /dev/null @@ -1,52 +0,0 @@ -playerWarningRepository = new PlayerWarningMockRepository(); - $this->playerLookup = new PlayerLookupMock(); - - $this->useCase = new CreateWarning( - playerLookup: $this->playerLookup, - playerWarningRepository: $this->playerWarningRepository, - ); - } - - public function test_creates_warning() - { - $createdWarning = PlayerWarning::factory()->id()->withPlayers()->make(); - $this->playerWarningRepository->create = $createdWarning; - $this->playerLookup->findOrCreate = MinecraftPlayer::factory()->id()->make(); - - $warning = $this->useCase->execute( - warnedPlayerIdentifier: PlayerIdentifier::minecraftUUID('uuid1'), - warnedPlayerAlias: 'alias1', - warnerPlayerIdentifier: PlayerIdentifier::minecraftUUID('uuid2'), - warnerPlayerAlias: 'alias2', - reason: 'reason', - weight: 5, - isAcknowledged: false, - ); - - $this->assertEquals(expected: $createdWarning, actual: $warning); - } -} diff --git a/tests/Unit/Domain/Warnings/UseCases/GetWarningsTest.php b/tests/Unit/Domain/Warnings/UseCases/GetWarningsTest.php deleted file mode 100644 index 5784d24b4..000000000 --- a/tests/Unit/Domain/Warnings/UseCases/GetWarningsTest.php +++ /dev/null @@ -1,75 +0,0 @@ -playerWarningRepository = new PlayerWarningMockRepository(); - $this->playerLookup = new PlayerLookupMock(); - - $this->useCase = new GetWarnings( - playerLookup: $this->playerLookup, - playerWarningRepository: $this->playerWarningRepository, - ); - } - - public function test_returns_all_warnings() - { - $expectedWarnings = collect([ - PlayerWarning::factory()->withPlayers()->make(), - PlayerWarning::factory()->withPlayers()->make(), - ]); - $this->playerWarningRepository->all = $expectedWarnings; - $this->playerLookup->find = MinecraftPlayer::factory()->id()->make(); - - $warnings = $this->useCase->execute( - playerIdentifier: PlayerIdentifier::minecraftUUID('test'), - playerAlias: 'alias', - ); - - $this->assertEquals(expected: $expectedWarnings, actual: $warnings); - } - - public function test_returns_empty_collection_if_no_warnings() - { - $this->playerWarningRepository->all = collect(); - $this->playerLookup->find = MinecraftPlayer::factory()->id()->make(); - - $warnings = $this->useCase->execute( - playerIdentifier: PlayerIdentifier::minecraftUUID('test'), - playerAlias: 'alias', - ); - - $this->assertEquals(expected: collect(), actual: $warnings); - } - - public function test_returns_empty_collection_if_player_not_found() - { - $this->playerLookup->find = null; - - $warnings = $this->useCase->execute( - playerIdentifier: PlayerIdentifier::minecraftUUID('test'), - playerAlias: 'alias', - ); - - $this->assertEquals(expected: collect(), actual: $warnings); - } -}