Add hasConfig middleware and use it in GroupController

This commit is contained in:
Charlie McMackin 2024-09-07 14:17:13 -05:00
parent 4248abde7c
commit a526877dd9
3 changed files with 24 additions and 1 deletions

View file

@ -27,7 +27,7 @@ class GroupController extends GroupFederationController
public function __construct() public function __construct()
{ {
$this->middleware('auth'); $this->middleware('auth');
abort_unless(config('groups.enabled'), 404); $this->middleware('hasConfig:groups.enabled');
} }
public function index(Request $request) public function index(Request $request)

View file

@ -71,6 +71,7 @@ class Kernel extends HttpKernel
'interstitial' => \App\Http\Middleware\AccountInterstitial::class, 'interstitial' => \App\Http\Middleware\AccountInterstitial::class,
'scopes' => \Laravel\Passport\Http\Middleware\CheckScopes::class, 'scopes' => \Laravel\Passport\Http\Middleware\CheckScopes::class,
'scope' => \Laravel\Passport\Http\Middleware\CheckForAnyScope::class, 'scope' => \Laravel\Passport\Http\Middleware\CheckForAnyScope::class,
'hasConfig' => \App\Http\Middleware\HasConfig::class,
// 'restricted' => \App\Http\Middleware\RestrictedAccess::class, // 'restricted' => \App\Http\Middleware\RestrictedAccess::class,
]; ];
} }

View file

@ -0,0 +1,22 @@
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
class HasConfig
{
/**
* Handle an incoming request.
*
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
*/
public function handle(Request $request, Closure $next, string $config): Response
{
abort_unless(config($config), 404);
return $next($request);
}
}