1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-12 17:24:03 +00:00

Merge branch 'master' of github.com:archtechx/tenancy

This commit is contained in:
Samuel Štancl 2022-07-28 15:30:19 +02:00
commit d0baabbc9d
4 changed files with 23 additions and 1 deletions

View file

@ -23,11 +23,17 @@ class UniversalRoutes implements Feature
public function bootstrap(Tenancy $tenancy): void public function bootstrap(Tenancy $tenancy): void
{ {
foreach (static::$identificationMiddlewares as $middleware) { foreach (static::$identificationMiddlewares as $middleware) {
$middleware::$onFail = function ($exception, $request, $next) { $originalOnFail = $middleware::$onFail;
$middleware::$onFail = function ($exception, $request, $next) use ($originalOnFail) {
if (static::routeHasMiddleware($request->route(), static::$middlewareGroup)) { if (static::routeHasMiddleware($request->route(), static::$middlewareGroup)) {
return $next($request); return $next($request);
} }
if ($originalOnFail) {
return $originalOnFail($exception, $request, $next);
}
throw $exception; throw $exception;
}; };
} }

View file

@ -23,6 +23,8 @@ use Stancl\Tenancy\Bootstrappers\DatabaseTenancyBootstrapper;
use Stancl\Tenancy\Bootstrappers\FilesystemTenancyBootstrapper; use Stancl\Tenancy\Bootstrappers\FilesystemTenancyBootstrapper;
beforeEach(function () { beforeEach(function () {
$this->mockConsoleOutput = false;
Event::listen( Event::listen(
TenantCreated::class, TenantCreated::class,
JobPipeline::make([CreateDatabase::class])->send(function (TenantCreated $event) { JobPipeline::make([CreateDatabase::class])->send(function (TenantCreated $event) {

View file

@ -8,6 +8,7 @@ use Stancl\Tenancy\Database\Models;
use Stancl\Tenancy\Database\Models\Domain; use Stancl\Tenancy\Database\Models\Domain;
use Stancl\Tenancy\Exceptions\DomainOccupiedByOtherTenantException; use Stancl\Tenancy\Exceptions\DomainOccupiedByOtherTenantException;
use Stancl\Tenancy\Exceptions\TenantCouldNotBeIdentifiedOnDomainException; use Stancl\Tenancy\Exceptions\TenantCouldNotBeIdentifiedOnDomainException;
use Stancl\Tenancy\Features\UniversalRoutes;
use Stancl\Tenancy\Middleware\InitializeTenancyByDomain; use Stancl\Tenancy\Middleware\InitializeTenancyByDomain;
use Stancl\Tenancy\Resolvers\DomainTenantResolver; use Stancl\Tenancy\Resolvers\DomainTenantResolver;
@ -88,6 +89,17 @@ test('onfail logic can be customized', function () {
->assertSee('foo'); ->assertSee('foo');
}); });
test('throw correct exception when onFail is null and universal routes are enabled', function () {
// un-define onFail logic
InitializeTenancyByDomain::$onFail = null;
// Enable UniversalRoute feature
Route::middlewareGroup('universal', []);
config(['tenancy.features' => [UniversalRoutes::class]]);
$this->withoutExceptionHandling()->get('http://foo.localhost/foo/abc/xyz');
})->throws(TenantCouldNotBeIdentifiedOnDomainException::class);;
test('domains are always lowercase', function () { test('domains are always lowercase', function () {
$tenant = DomainTenant::create(); $tenant = DomainTenant::create();

View file

@ -27,6 +27,8 @@ use Stancl\Tenancy\Bootstrappers\QueueTenancyBootstrapper;
use Stancl\Tenancy\Bootstrappers\DatabaseTenancyBootstrapper; use Stancl\Tenancy\Bootstrappers\DatabaseTenancyBootstrapper;
beforeEach(function () { beforeEach(function () {
$this->mockConsoleOutput = false;
config([ config([
'tenancy.bootstrappers' => [ 'tenancy.bootstrappers' => [
QueueTenancyBootstrapper::class, QueueTenancyBootstrapper::class,