fix: handle tenant branding and Inertia selection redirects
This commit is contained in:
3 files changed
+39
-3
No files matched your search
+3
-2
@@ -2,7 +2,7 @@
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
## [1.1.1] - 2026-09-09
|
||||
## [1.1.2] - 2026-09-09
|
||||
|
||||
### Changed
|
||||
|
||||
@@ -13,6 +13,7 @@ All notable changes to this project will be documented in this file.
|
||||
|
||||
- Keep selected tenant branding on Nova's primary color in dark mode.
|
||||
- Show successful tenant logos without decorative framing while retaining the framed initial fallback.
|
||||
- Redirect tenant-less Inertia page visits to the selector instead of showing Nova's unrecoverable-error modal.
|
||||
|
||||
## [1.1.0] - 2026-09-09
|
||||
|
||||
@@ -52,7 +53,7 @@ All notable changes to this project will be documented in this file.
|
||||
- Optional tenant-aware Nova resource base and reusable context helpers.
|
||||
- English and Persian translations.
|
||||
|
||||
[1.1.1]: https://github.com/MeghdadFadaee/nova-tenancy/releases/tag/v1.1.1
|
||||
[1.1.2]: https://github.com/MeghdadFadaee/nova-tenancy/releases/tag/v1.1.2
|
||||
[1.1.0]: https://github.com/MeghdadFadaee/nova-tenancy/releases/tag/v1.1.0
|
||||
[1.0.2]: https://github.com/MeghdadFadaee/nova-tenancy/releases/tag/v1.0.2
|
||||
[1.0.1]: https://github.com/MeghdadFadaee/nova-tenancy/releases/tag/v1.0.1
|
||||
|
||||
@@ -17,6 +17,12 @@ class TenantNotSelected extends RuntimeException implements Responsable
|
||||
|
||||
public function toResponse($request): Response
|
||||
{
|
||||
$destination = $this->selectorUrl();
|
||||
|
||||
if ($request instanceof Request && $request->header('X-Inertia') === 'true') {
|
||||
return redirect()->to($destination);
|
||||
}
|
||||
|
||||
if ($request instanceof Request && $request->expectsJson()) {
|
||||
return response()->json([
|
||||
'message' => $this->getMessage(),
|
||||
@@ -24,9 +30,14 @@ class TenantNotSelected extends RuntimeException implements Responsable
|
||||
], 409);
|
||||
}
|
||||
|
||||
return redirect()->to($destination);
|
||||
}
|
||||
|
||||
protected function selectorUrl(): string
|
||||
{
|
||||
$novaPath = '/'.trim(Nova::path(), '/');
|
||||
$toolPath = trim((string) config('nova-tenancy.routes.uri', 'nova-tenancy'), '/');
|
||||
|
||||
return redirect()->to("{$novaPath}/{$toolPath}");
|
||||
return "{$novaPath}/{$toolPath}";
|
||||
}
|
||||
}
|
||||
@@ -46,6 +46,30 @@ it('provides scoped string bindings and strict accessors', function (): void {
|
||||
->toThrow(TenantNotSelected::class);
|
||||
});
|
||||
|
||||
it('redirects an inertia page request to tenant selection', function (): void {
|
||||
$request = Request::create('/nova/dashboards/home', server: [
|
||||
'HTTP_ACCEPT' => 'text/html, application/xhtml+xml',
|
||||
'HTTP_X_INERTIA' => 'true',
|
||||
'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest',
|
||||
]);
|
||||
|
||||
$response = (new TenantNotSelected)->toResponse($request);
|
||||
|
||||
expect($response->getStatusCode())->toBe(302)
|
||||
->and($response->headers->get('Location'))->toEndWith('/nova/nova-tenancy');
|
||||
});
|
||||
|
||||
it('returns a conflict response for a json api request', function (): void {
|
||||
$request = Request::create('/nova-api/resources', server: [
|
||||
'HTTP_ACCEPT' => 'application/json',
|
||||
]);
|
||||
|
||||
$response = (new TenantNotSelected)->toResponse($request);
|
||||
|
||||
expect($response->getStatusCode())->toBe(409)
|
||||
->and($response->getContent())->toContain('tenant_selection_required');
|
||||
});
|
||||
|
||||
it('temporarily activates a tenant and restores the previous context', function (): void {
|
||||
$user = User::query()->create(['name' => 'Ada']);
|
||||
$first = Tenant::query()->create(['user_id' => $user->id, 'title' => 'First']);
|
||||
|
||||
Reference in new issue
Block a user