Skip to content

Commit 6de839b

Browse files
committed
Badge create Gate prioritize if the event is open over remainingBadges.
Welcome Page only offers BadgeCreation if User is allowed
1 parent 9628d8a commit 6de839b

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

app/Http/Controllers/WelcomeController.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
namespace App\Http\Controllers;
44

5+
use App\Models\Badge\Badge;
56
use Illuminate\Support\Facades\Auth;
7+
use Illuminate\Support\Facades\Gate;
68
use Inertia\Inertia;
79

810
class WelcomeController extends Controller
@@ -14,7 +16,7 @@ public function __invoke()
1416
$event = \App\Models\Event::getActiveEvent();
1517

1618
$prepaidBadgesLeft = 0;
17-
if ($event && Auth::check()) {
19+
if ($event && Auth::check() && Gate::allows('create', Badge::class)) {
1820
$user = Auth::user();
1921
$prepaidBadgesLeft = $user->getPrepaidBadgesLeft($event->id);
2022
}

app/Policies/BadgePolicy.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ public function create(User $user): bool
3838
return false;
3939
}
4040

41+
// Allow badge creation only if event allows orders (for paid badges)
42+
if (! $event->allowsOrders()) {
43+
return false;
44+
}
45+
4146
// Check if user has prepaid badges left
4247
$eventUser = $user->eventUser($event->id);
4348
if ($eventUser) {
@@ -55,11 +60,6 @@ public function create(User $user): bool
5560
}
5661
}
5762

58-
// Allow badge creation only if event allows orders (for paid badges)
59-
if (! $event->allowsOrders()) {
60-
return false;
61-
}
62-
6363
return true;
6464
}
6565

0 commit comments

Comments
 (0)