Skip to content

Commit

Permalink
feat: create reviews panel (#854)
Browse files Browse the repository at this point in the history
  • Loading branch information
andyksaw authored Jan 11, 2025
1 parent f2bf3a0 commit 3ae0bfd
Show file tree
Hide file tree
Showing 86 changed files with 1,535 additions and 526 deletions.
8 changes: 8 additions & 0 deletions app/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Illuminate\Http\Request;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\Facades\RateLimiter;
use Illuminate\Support\ServiceProvider;
use Illuminate\Validation\Rules\Password;
Expand Down Expand Up @@ -65,6 +66,13 @@ public function boot()
? Password::min(12)->letters()->numbers()
: Password::min(8);
});

Gate::define('access-manage', function (Account $account) {
return $account->isAdmin() || $account->isStaff();
});
Gate::define('access-review', function (Account $account) {
return $account->isAdmin() || $account->isStaff() || $account->isArchitect();
});
}

private function enforceMorphMap(): void
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace App\Domains\BanAppeals\Entities;
namespace App\Domains\BanAppeals\Data;

use Illuminate\Support\Str;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace App\Domains\Manage\Exceptions;
namespace App\Domains\BanAppeals\Exceptions;

use Exception;

Expand Down
2 changes: 1 addition & 1 deletion app/Domains/BanAppeals/UseCases/CreateBanAppeal.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Domains\BanAppeals\UseCases;

use App\Domains\BanAppeals\Entities\BanAppealStatus;
use App\Domains\BanAppeals\Data\BanAppealStatus;
use App\Domains\BanAppeals\Exceptions\EmailRequiredException;
use App\Domains\BanAppeals\Notifications\BanAppealConfirmationNotification;
use App\Models\Account;
Expand Down
4 changes: 2 additions & 2 deletions app/Domains/BanAppeals/UseCases/UpdateBanAppeal.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

use App\Core\Data\Exceptions\NotImplementedException;
use App\Core\Domains\MinecraftUUID\Data\MinecraftUUID;
use App\Domains\BanAppeals\Entities\BanAppealStatus;
use App\Domains\BanAppeals\Data\BanAppealStatus;
use App\Domains\BanAppeals\Exceptions\AppealAlreadyDecidedException;
use App\Domains\BanAppeals\Exceptions\NoPlayerForActionException;
use App\Domains\Bans\Data\UnbanType;
use App\Domains\Bans\Exceptions\NotBannedException;
use App\Domains\Bans\UseCases\CreatePlayerUnban;
use App\Domains\Manage\Exceptions\NoPlayerForActionException;
use App\Models\Account;
use App\Models\BanAppeal;
use Exception;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

enum ApplicationStatus: int
{
case IN_PROGRESS = 1;
case PENDING = 1;
case APPROVED = 2;
case DENIED = 3;

public function humanReadable(): string
{
return match ($this) {
self::IN_PROGRESS => 'In progress',
self::PENDING => 'Pending',
self::APPROVED => 'Approved',
self::DENIED => 'Denied',
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,34 @@
use App\Domains\BuilderRankApplications\Notifications\BuilderRankAppApprovedNotification;
use App\Models\BuilderRankApplication;
use App\Models\Group;
use Illuminate\Support\Facades\DB;

class ApproveBuildRankApplication
{
public function execute(
int $applicationId,
int $promoteGroupId,
): BuilderRankApplication {
$application = BuilderRankApplication::find($applicationId);
$promoteGroup = Group::find($promoteGroupId);

$application = BuilderRankApplication::find($applicationId);
$application->status = ApplicationStatus::APPROVED->value;
$application->closed_at = now();
$application->save();
abort_if($application->isReviewed(), 409);

DB::transaction(function () use ($application, $promoteGroup) {
$application->status = ApplicationStatus::APPROVED->value;
$application->closed_at = now();
$application->save();

$updatedGroupIds = $application
->account
->groups()
->where('group_type', '!=', 'build')
->get()
->map(fn ($it) => $it->getKey())
->push($promoteGroup->getKey());

$application->account->groups()->attach($promoteGroup->getKey());
$application->account->groups()->sync($updatedGroupIds);
});

$application->account->notify(
new BuilderRankAppApprovedNotification(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function execute(
string $buildDescription,
?string $additionalNotes,
): BuilderRankApplication {
$existingApplication = BuilderRankApplication::where('status', ApplicationStatus::IN_PROGRESS->value)
$existingApplication = BuilderRankApplication::where('status', ApplicationStatus::PENDING->value)
->where('account_id', $account->getKey())
->count();

Expand All @@ -37,7 +37,7 @@ public function execute(
'build_location' => $buildLocation,
'build_description' => $buildDescription,
'additional_notes' => $additionalNotes,
'status' => ApplicationStatus::IN_PROGRESS->value,
'status' => ApplicationStatus::PENDING->value,
'closed_at' => null,
]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ public function execute(
string $denyReason,
): BuilderRankApplication {
$application = BuilderRankApplication::find($applicationId);

abort_if($application->isReviewed(), 409);

$application->status = ApplicationStatus::DENIED->value;
$application->denied_reason = $denyReason;
$application->closed_at = now();
Expand Down
25 changes: 0 additions & 25 deletions app/Domains/Manage/Components/ManageSideBarComponent.php

This file was deleted.

26 changes: 0 additions & 26 deletions app/Domains/Manage/ManageServiceProvider.php

This file was deleted.

17 changes: 17 additions & 0 deletions app/Domains/Manage/RendersManageApp.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace App\Domains\Manage;

use Illuminate\Contracts\Support\Arrayable;
use Inertia\Inertia;
use Inertia\Response;

trait RendersManageApp
{
public function inertiaRender(string $component, array|Arrayable $props = []): Response
{
Inertia::setRootView('manage.app');

return Inertia::render($component, $props);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ public function execute(MinecraftUUID $uuid, string $alias): void
uuid: $uuid,
alias: $alias,
);
$minecraftPlayer = $player->getRawModel();
$minecraftPlayer->last_seen_at = now();
$minecraftPlayer->save();
$player->last_seen_at = now();
$player->save();
}
}
17 changes: 17 additions & 0 deletions app/Domains/Review/RendersReviewApp.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace App\Domains\Review;

use Illuminate\Contracts\Support\Arrayable;
use Inertia\Inertia;
use Inertia\Response;

trait RendersReviewApp
{
public function inertiaRender(string $component, array|Arrayable $props = []): Response
{
Inertia::setRootView('review.app');

return Inertia::render($component, $props);
}
}
44 changes: 22 additions & 22 deletions app/Http/Controllers/Front/BuilderRankApplicationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,58 +14,58 @@

final class BuilderRankApplicationController extends WebController
{
public function index(
public function show(
Request $request,
BuilderRankApplication $application,
) {
Gate::authorize('view', $application);

return view('front.pages.builder-rank.builder-rank-status')
->with(compact('application'));
}

public function create(
Request $request,
) {
Gate::authorize('create', BuilderRankApplication::class);

$minecraftUsername = $request->user()
?->minecraftAccount
?->first()
?->alias;

$applicationInProgress = BuilderRankApplication::where('status', ApplicationStatus::IN_PROGRESS->value)
$applicationInProgress = BuilderRankApplication::where('status', ApplicationStatus::PENDING->value)
->where('account_id', $request->user()->getKey())
->orderBy('created_at', 'DESC')
->first();

if ($applicationInProgress !== null) {
return redirect()
->route('front.rank-up.status', $applicationInProgress->getKey());
return to_route('front.rank-up.status', $applicationInProgress->getKey());
}

return view('front.pages.builder-rank.builder-rank-form')
->with(compact('minecraftUsername'));
}

public function show(
Request $request,
BuilderRankApplication $application,
) {
Gate::authorize('view', $application);

return view('front.pages.builder-rank.builder-rank-status')
->with(compact('application'));
}

public function store(
BuilderRankApplicationRequest $request,
CreateBuildRankApplication $createBuildRankApplication,
) {
Gate::authorize('create', BuilderRankApplication::class);

$input = $request->validated();
$validated = $request->validated();
$account = $request->user();

try {
$application = $createBuildRankApplication->execute(
account: $account,
minecraftAlias: $input['minecraft_username'],
currentBuilderRank: BuilderRank::from($input['current_builder_rank']),
buildLocation: $input['build_location'],
buildDescription: $input['build_description'],
additionalNotes: $request->get('additional_notes'),
minecraftAlias: $validated['minecraft_username'],
currentBuilderRank: BuilderRank::from($validated['current_builder_rank']),
buildLocation: $validated['build_location'],
buildDescription: $validated['build_description'],
additionalNotes: $validated['additional_notes'],
);
return redirect()
->route('front.rank-up.status', $application->getKey());
return to_route('front.rank-up.status', $application->getKey());

} catch (ApplicationAlreadyInProgressException) {
return redirect()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,25 @@

namespace App\Http\Controllers\Manage\Accounts;

use App\Domains\Manage\RendersManageApp;
use App\Domains\MinecraftEventBus\Events\MinecraftPlayerUpdated;
use App\Models\Account;
use App\Models\Badge;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Gate;
use Inertia\Inertia;

class AccountBadgeController
{
use RendersManageApp;

public function index(Request $request, Account $account)
{
Gate::authorize('viewAny', Account::class);

$badges = Badge::get();
$accountBadgeIds = $account->badges->pluck(Badge::primaryKey());

return Inertia::render('Accounts/AccountBadgeSelect', [
return $this->inertiaRender('Accounts/AccountBadgeSelect', [
'badges' => $badges,
'account_badge_ids' => $accountBadgeIds ?? [],
'account_id' => $account->getKey(),
Expand Down
Loading

0 comments on commit 3ae0bfd

Please sign in to comment.