mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 12:44:02 +00:00
Stop bypassing tenancy initializition when domain is central in domain ID MW (#24)
* Stop bypassing tenancy initialization when host is central domain in domain ID MW * Delete dataset for testing global domain ID MW + route-level prevent access MW * Provide ID MW statically in TenantAssetController * Fix code style (php-cs-fixer) --------- Co-authored-by: PHP CS Fixer <phpcsfixer@example.com>
This commit is contained in:
parent
00a00a2aff
commit
df9324b92f
7 changed files with 12 additions and 24 deletions
|
|
@ -8,7 +8,6 @@ use Stancl\Tenancy\Controllers\TenantAssetController;
|
||||||
|
|
||||||
Route::get('/tenancy/assets/{path?}', TenantAssetController::class)
|
Route::get('/tenancy/assets/{path?}', TenantAssetController::class)
|
||||||
->where('path', '(.*)')
|
->where('path', '(.*)')
|
||||||
->middleware(config('tenancy.identification.default_middleware')) // todo@features Use tenancy()->defaultMiddleware() after merging #1021
|
|
||||||
->name('stancl.tenancy.asset');
|
->name('stancl.tenancy.asset');
|
||||||
|
|
||||||
Route::prefix('/{' . PathIdentificationManager::getTenantParameterName() . '}/')->get('/tenancy/assets/{path?}', TenantAssetController::class)
|
Route::prefix('/{' . PathIdentificationManager::getTenantParameterName() . '}/')->get('/tenancy/assets/{path?}', TenantAssetController::class)
|
||||||
|
|
|
||||||
|
|
@ -4,12 +4,20 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Stancl\Tenancy\Controllers;
|
namespace Stancl\Tenancy\Controllers;
|
||||||
|
|
||||||
use Illuminate\Routing\Controller;
|
use Illuminate\Routing\Controllers\HasMiddleware;
|
||||||
|
use Illuminate\Routing\Controllers\Middleware;
|
||||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||||
use Throwable;
|
use Throwable;
|
||||||
|
|
||||||
class TenantAssetController extends Controller // todo@docs this was renamed from TenantAssetsController
|
class TenantAssetController implements HasMiddleware // todo@docs this was renamed from TenantAssetsController
|
||||||
{
|
{
|
||||||
|
public static function middleware()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
new Middleware(tenancy()->defaultMiddleware()),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
|
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -31,11 +31,6 @@ class InitializeTenancyByDomain extends IdentificationMiddleware implements Usab
|
||||||
return $next($request);
|
return $next($request);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (in_array($request->getHost(), config('tenancy.central_domains', []), true)) {
|
|
||||||
// Always bypass tenancy initialization when host is in central domains
|
|
||||||
return $next($request);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->initializeTenancy(
|
return $this->initializeTenancy(
|
||||||
$request,
|
$request,
|
||||||
$next,
|
$next,
|
||||||
|
|
|
||||||
|
|
@ -15,18 +15,13 @@ class InitializeTenancyByDomainOrSubdomain extends InitializeTenancyBySubdomain
|
||||||
{
|
{
|
||||||
use UsableWithEarlyIdentification;
|
use UsableWithEarlyIdentification;
|
||||||
|
|
||||||
/** @return \Illuminate\Http\Response|mixed */
|
/** @return Response|mixed */
|
||||||
public function handle(Request $request, Closure $next): mixed
|
public function handle(Request $request, Closure $next): mixed
|
||||||
{
|
{
|
||||||
if ($this->shouldBeSkipped(tenancy()->getRoute($request))) {
|
if ($this->shouldBeSkipped(tenancy()->getRoute($request))) {
|
||||||
return $next($request);
|
return $next($request);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (in_array($request->getHost(), config('tenancy.central_domains', []), true)) {
|
|
||||||
// Always bypass tenancy initialization when host is in central domains
|
|
||||||
return $next($request);
|
|
||||||
}
|
|
||||||
|
|
||||||
$domain = $request->getHost();
|
$domain = $request->getHost();
|
||||||
|
|
||||||
if ($this->isSubdomain($domain)) {
|
if ($this->isSubdomain($domain)) {
|
||||||
|
|
|
||||||
|
|
@ -35,11 +35,6 @@ class InitializeTenancyBySubdomain extends InitializeTenancyByDomain
|
||||||
return $next($request);
|
return $next($request);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (in_array($request->getHost(), config('tenancy.central_domains', []), true)) {
|
|
||||||
// Always bypass tenancy initialization when host is in central domains
|
|
||||||
return $next($request);
|
|
||||||
}
|
|
||||||
|
|
||||||
$subdomain = $this->makeSubdomain($request->getHost());
|
$subdomain = $this->makeSubdomain($request->getHost());
|
||||||
|
|
||||||
if (is_object($subdomain) && $subdomain instanceof Exception) {
|
if (is_object($subdomain) && $subdomain instanceof Exception) {
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,7 @@ if (! function_exists('global_cache')) {
|
||||||
* @param dynamic key|key,default|data,expiration|null
|
* @param dynamic key|key,default|data,expiration|null
|
||||||
* @return mixed|\Illuminate\Cache\CacheManager
|
* @return mixed|\Illuminate\Cache\CacheManager
|
||||||
*
|
*
|
||||||
* @throws \InvalidArgumentException
|
* @throws InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
function global_cache(): mixed
|
function global_cache(): mixed
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -212,10 +212,6 @@ test('placement of domain identification and access prevention middleware can ge
|
||||||
pest()->get("http://localhost/central-route")->assertOk();
|
pest()->get("http://localhost/central-route")->assertOk();
|
||||||
expect(tenancy()->initialized)->toBeFalse();
|
expect(tenancy()->initialized)->toBeFalse();
|
||||||
})->with([
|
})->with([
|
||||||
'kernel identification, route-level access prevention' => [
|
|
||||||
'global_middleware' => [InitializeTenancyBySubdomain::class],
|
|
||||||
'route_middleware' => [PreventAccessFromUnwantedDomains::class],
|
|
||||||
],
|
|
||||||
'route-level identification, kernel access prevention' => [
|
'route-level identification, kernel access prevention' => [
|
||||||
'global_middleware' => [PreventAccessFromUnwantedDomains::class],
|
'global_middleware' => [PreventAccessFromUnwantedDomains::class],
|
||||||
'route_middleware' => [InitializeTenancyBySubdomain::class],
|
'route_middleware' => [InitializeTenancyBySubdomain::class],
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue