1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-12 11:14:04 +00:00

Pull 3.x changes into master (#922)

* exclude master from CI

* Add space after 'up' in 'docker-compose up-d' (#900)

* Fix ArgumentCountError on the TenantAssetsController (#894)

* Fix ArgumentCount exception on the TenantAssetsController when no `$path` is provided

* CS

* CS

* Handle null case explicitly

* code style

Co-authored-by: Bram Wubs <bram@sibi.nl>
Co-authored-by: Samuel Štancl <samuel@archte.ch>

* Add support for nested tenant config override (#920)

* feat: add support for nested tenant config override

* test: ensure nested tenant values are mapped

* Update TenantConfigTest.php

Co-authored-by: lukinovec <lukinovec@gmail.com>
Co-authored-by: Bram Wubs <megawubs@users.noreply.github.com>
Co-authored-by: Bram Wubs <bram@sibi.nl>
Co-authored-by: George Bishop <email.georgebishop@gmail.com>
Co-authored-by: Abrar Ahmad <abrar.dev99@gmail.com>
This commit is contained in:
Samuel Štancl 2022-08-22 17:59:43 +02:00 committed by GitHub
parent fce95aa862
commit 931c76d697
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 41 additions and 3 deletions

View file

@ -5,6 +5,7 @@ declare(strict_types=1);
namespace Stancl\Tenancy\Controllers; namespace Stancl\Tenancy\Controllers;
use Illuminate\Routing\Controller; use Illuminate\Routing\Controller;
use Throwable;
class TenantAssetsController extends Controller class TenantAssetsController extends Controller
{ {
@ -15,11 +16,13 @@ class TenantAssetsController extends Controller
$this->middleware(static::$tenancyMiddleware); $this->middleware(static::$tenancyMiddleware);
} }
public function asset($path) public function asset($path = null)
{ {
abort_if($path === null, 404);
try { try {
return response()->file(storage_path("app/public/$path")); return response()->file(storage_path("app/public/$path"));
} catch (\Throwable $th) { } catch (Throwable $th) {
abort(404); abort(404);
} }
} }

View file

@ -6,6 +6,7 @@ namespace Stancl\Tenancy\Features;
use Illuminate\Contracts\Config\Repository; use Illuminate\Contracts\Config\Repository;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Event; use Illuminate\Support\Facades\Event;
use Stancl\Tenancy\Contracts\Feature; use Stancl\Tenancy\Contracts\Feature;
use Stancl\Tenancy\Contracts\Tenant; use Stancl\Tenancy\Contracts\Tenant;
@ -45,7 +46,7 @@ class TenantConfig implements Feature
{ {
/** @var Tenant|Model $tenant */ /** @var Tenant|Model $tenant */
foreach (static::$storageToConfigMap as $storageKey => $configKey) { foreach (static::$storageToConfigMap as $storageKey => $configKey) {
$override = $tenant->getAttribute($storageKey); $override = Arr::get($tenant, $storageKey);
if (! is_null($override)) { if (! is_null($override)) {
if (is_array($configKey)) { if (is_array($configKey)) {

View file

@ -14,6 +14,28 @@ afterEach(function () {
TenantConfig::$storageToConfigMap = []; TenantConfig::$storageToConfigMap = [];
}); });
test('nested tenant values are merged', function () {
expect(config('whitelabel.theme'))->toBeNull();
config([
'tenancy.features' => [TenantConfig::class],
'tenancy.bootstrappers' => [],
]);
Event::listen(TenancyInitialized::class, BootstrapTenancy::class);
Event::listen(TenancyEnded::class, RevertToCentralContext::class);
TenantConfig::$storageToConfigMap = [
'whitelabel.config.theme' => 'whitelabel.theme',
];
$tenant = Tenant::create([
'whitelabel' => ['config' => ['theme' => 'dark']],
]);
tenancy()->initialize($tenant);
expect(config('whitelabel.theme'))->toBe('dark');
tenancy()->end();
});
test('config is merged and removed', function () { test('config is merged and removed', function () {
expect(config('services.paypal'))->toBe(null); expect(config('services.paypal'))->toBe(null);
config([ config([

View file

@ -94,6 +94,18 @@ test('asset helper tenancy can be disabled', function () {
expect(asset('foo'))->toBe($original); expect(asset('foo'))->toBe($original);
}); });
test('test asset controller returns a 404 when no path is provided', function () {
TenantAssetsController::$tenancyMiddleware = InitializeTenancyByRequestData::class;
$tenant = Tenant::create();
tenancy()->initialize($tenant);
pest()->get(tenant_asset(null), [
'X-Tenant' => $tenant->id,
])->assertNotFound();
});
function getEnvironmentSetUp($app) function getEnvironmentSetUp($app)
{ {
$app->booted(function () { $app->booted(function () {