mirror of
https://github.com/AnimeThemes/animethemes-server.git
synced 2026-07-26 08:44:30 +02:00
32 lines
850 B
PHP
32 lines
850 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Middleware\Models\List;
|
|
|
|
use App\Constants\Config\PlaylistConstants;
|
|
use App\Enums\Auth\SpecialPermission;
|
|
use App\Models\Auth\User;
|
|
use Closure;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Config;
|
|
|
|
class UserExceedsPlaylistLimit
|
|
{
|
|
/**
|
|
* @param Closure(Request): mixed $next
|
|
*/
|
|
public function handle(Request $request, Closure $next): mixed
|
|
{
|
|
$playlistLimit = intval(Config::get(PlaylistConstants::MAX_PLAYLISTS_QUALIFIED));
|
|
|
|
/** @var User|null $user */
|
|
$user = $request->user();
|
|
|
|
abort_if(intval($user?->playlists()?->count()) >= $playlistLimit
|
|
&& $user?->cannot(SpecialPermission::BYPASS_FEATURE_FLAGS->value), 403, "User cannot have more than '$playlistLimit' playlists.");
|
|
|
|
return $next($request);
|
|
}
|
|
}
|