Skip to content

Commit

Permalink
Pull 3.x changes into master (#922)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
6 people authored Aug 22, 2022
1 parent fce95aa commit 931c76d
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/Controllers/TenantAssetsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Stancl\Tenancy\Controllers;

use Illuminate\Routing\Controller;
use Throwable;

class TenantAssetsController extends Controller
{
Expand All @@ -15,11 +16,13 @@ public function __construct()
$this->middleware(static::$tenancyMiddleware);
}

public function asset($path)
public function asset($path = null)
{
abort_if($path === null, 404);

try {
return response()->file(storage_path("app/public/$path"));
} catch (\Throwable $th) {
} catch (Throwable $th) {
abort(404);
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/Features/TenantConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Illuminate\Contracts\Config\Repository;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Event;
use Stancl\Tenancy\Contracts\Feature;
use Stancl\Tenancy\Contracts\Tenant;
Expand Down Expand Up @@ -45,7 +46,7 @@ public function setTenantConfig(Tenant $tenant): void
{
/** @var Tenant|Model $tenant */
foreach (static::$storageToConfigMap as $storageKey => $configKey) {
$override = $tenant->getAttribute($storageKey);
$override = Arr::get($tenant, $storageKey);

if (! is_null($override)) {
if (is_array($configKey)) {
Expand Down
22 changes: 22 additions & 0 deletions tests/Features/TenantConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,28 @@
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 () {
expect(config('services.paypal'))->toBe(null);
config([
Expand Down
12 changes: 12 additions & 0 deletions tests/TenantAssetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,18 @@
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)
{
$app->booted(function () {
Expand Down

0 comments on commit 931c76d

Please sign in to comment.