Files
paranarimasu 1d93000c6f feat(admin): migrate db dumps from github to platform (#463)
* feat(admin): migrate db dumps from github to platform

* style: fix StyleCI findings
2022-09-18 22:31:29 -05:00

45 lines
1.0 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Http\Middleware\Auth;
use App\Models\Auth\Invitation;
use Closure;
use Illuminate\Http\Request;
use RuntimeException;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
* Class HasOpenInvitation.
*/
class HasOpenInvitation
{
/**
* Handle an incoming request.
*
* @param Request $request
* @param Closure(Request): mixed $next
* @return mixed
*
* @throws HttpException
* @throws NotFoundHttpException
* @throws RuntimeException
*/
public function handle(Request $request, Closure $next): mixed
{
$invitation = $request->route('invitation');
if (! $invitation instanceof Invitation) {
throw new RuntimeException('has_open_invitation should only be configured for invitations');
}
if (! $invitation->isOpen()) {
abort(403, 'Closed Invitation');
}
return $next($request);
}
}