mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 09:34:04 +00:00
Final filesystem-related changes (#25)
* Change %tenant_id% to %tenant% * ID -> key --------- Co-authored-by: Samuel Štancl <samuel.stancl@gmail.com>
This commit is contained in:
parent
6784685054
commit
222bbe4c02
6 changed files with 14 additions and 15 deletions
|
|
@ -248,20 +248,19 @@ return [
|
|||
|
||||
/*
|
||||
* Tenant-aware Storage::disk()->url() can be enabled for specific local disks here
|
||||
* by mapping the disk's name to a name with '%tenant_id%' (this will be used as the public name of the disk).
|
||||
* by mapping the disk's name to a name with '%tenant%' (this will be used as the public name of the disk).
|
||||
* Doing that will override the disk's default URL with a URL containing the current tenant's key.
|
||||
*
|
||||
* For example, Storage::disk('public')->url('') will return https://your-app.test/storage/ by default.
|
||||
* After adding 'public' => 'public-%tenant_id%' to 'url_override',
|
||||
* the returned URL will be https://your-app.test/public-1/ (%tenant_id% gets substitued by the current tenant's ID).
|
||||
* After adding 'public' => 'public-%tenant%' to 'url_override',
|
||||
* the returned URL will be https://your-app.test/public-1/ (%tenant% gets substitued by the current tenant's key).
|
||||
*
|
||||
* Use `php artisan tenants:link` to create a symbolic link from the tenant's storage to its public directory.
|
||||
*/
|
||||
'url_override' => [
|
||||
// Note that the local disk you add must exist in the tenancy.filesystem.root_override config
|
||||
// todo@v4 Rename %tenant_id% to %tenant_key%
|
||||
// todo@v4 Rename url_override to something that describes the config key better
|
||||
'public' => 'public-%tenant_id%',
|
||||
'public' => 'public-%tenant%',
|
||||
],
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ class FilesystemTenancyBootstrapper implements TenancyBootstrapper
|
|||
$this->originalPaths['disks']['url'][$disk] = $diskConfig['url'] ?? null;
|
||||
|
||||
if ($url = str_replace(
|
||||
'%tenant_id%',
|
||||
'%tenant%',
|
||||
(string) $tenant->getTenantKey(),
|
||||
$this->app['config']["tenancy.filesystem.url_override.{$disk}"] ?? ''
|
||||
)) {
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ trait DealsWithTenantSymlinks
|
|||
|
||||
foreach ($diskUrls as $disk => $publicPath) {
|
||||
$storagePath = str_replace('%storage_path%', $suffixBase . $tenantKey, $disks[$disk]);
|
||||
$publicPath = str_replace('%tenant_id%', (string) $tenantKey, $publicPath);
|
||||
$publicPath = str_replace('%tenant%', (string) $tenantKey, $publicPath);
|
||||
|
||||
tenancy()->central(function () use ($symlinks, $publicPath, $storagePath) {
|
||||
$symlinks->push([public_path($publicPath) => storage_path($storagePath)]);
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ test('create storage symlinks action works', function() {
|
|||
],
|
||||
'tenancy.filesystem.suffix_base' => 'tenant-',
|
||||
'tenancy.filesystem.root_override.public' => '%storage_path%/app/public/',
|
||||
'tenancy.filesystem.url_override.public' => 'public-%tenant_id%'
|
||||
'tenancy.filesystem.url_override.public' => 'public-%tenant%'
|
||||
]);
|
||||
|
||||
/** @var Tenant $tenant */
|
||||
|
|
@ -50,7 +50,7 @@ test('remove storage symlinks action works', function() {
|
|||
],
|
||||
'tenancy.filesystem.suffix_base' => 'tenant-',
|
||||
'tenancy.filesystem.root_override.public' => '%storage_path%/app/public/',
|
||||
'tenancy.filesystem.url_override.public' => 'public-%tenant_id%'
|
||||
'tenancy.filesystem.url_override.public' => 'public-%tenant%'
|
||||
]);
|
||||
|
||||
/** @var Tenant $tenant */
|
||||
|
|
|
|||
|
|
@ -233,7 +233,7 @@ test('tenant storage can get deleted after the tenant when DeletingTenant listen
|
|||
FilesystemTenancyBootstrapper::class,
|
||||
],
|
||||
'tenancy.filesystem.root_override.public' => '%storage_path%/app/public/',
|
||||
'tenancy.filesystem.url_override.public' => 'public-%tenant_id%'
|
||||
'tenancy.filesystem.url_override.public' => 'public-%tenant%'
|
||||
]);
|
||||
|
||||
$tenant1 = Tenant::create();
|
||||
|
|
@ -276,7 +276,7 @@ test('files can get fetched using the storage url', function() {
|
|||
FilesystemTenancyBootstrapper::class,
|
||||
],
|
||||
'tenancy.filesystem.root_override.public' => '%storage_path%/app/public/',
|
||||
'tenancy.filesystem.url_override.public' => 'public-%tenant_id%'
|
||||
'tenancy.filesystem.url_override.public' => 'public-%tenant%'
|
||||
]);
|
||||
|
||||
$tenant1 = Tenant::create();
|
||||
|
|
@ -289,7 +289,7 @@ test('files can get fetched using the storage url', function() {
|
|||
Storage::disk('public')->put($tenantFileName = 'tenant1.txt', $tenantKey = $tenant1->getTenantKey());
|
||||
|
||||
$url = Storage::disk('public')->url($tenantFileName);
|
||||
$tenantDiskName = Str::of(config('tenancy.filesystem.url_override.public'))->replace('%tenant_id%', $tenantKey);
|
||||
$tenantDiskName = Str::of(config('tenancy.filesystem.url_override.public'))->replace('%tenant%', $tenantKey);
|
||||
$hostname = Str::of($url)->before($tenantDiskName);
|
||||
$parsedUrl = Str::of($url)->after($hostname);
|
||||
|
||||
|
|
@ -300,7 +300,7 @@ test('files can get fetched using the storage url', function() {
|
|||
Storage::disk('public')->put($tenantFileName = 'tenant2.txt', $tenantKey = $tenant2->getTenantKey());
|
||||
|
||||
$url = Storage::disk('public')->url($tenantFileName);
|
||||
$tenantDiskName = Str::of(config('tenancy.filesystem.url_override.public'))->replace('%tenant_id%', $tenantKey);
|
||||
$tenantDiskName = Str::of(config('tenancy.filesystem.url_override.public'))->replace('%tenant%', $tenantKey);
|
||||
$hostname = Str::of($url)->before($tenantDiskName);
|
||||
$parsedUrl = Str::of($url)->after($hostname);
|
||||
|
||||
|
|
@ -337,7 +337,7 @@ test('create and delete storage symlinks jobs work', function() {
|
|||
],
|
||||
'tenancy.filesystem.suffix_base' => 'tenant-',
|
||||
'tenancy.filesystem.root_override.public' => '%storage_path%/app/public/',
|
||||
'tenancy.filesystem.url_override.public' => 'public-%tenant_id%'
|
||||
'tenancy.filesystem.url_override.public' => 'public-%tenant%'
|
||||
]);
|
||||
|
||||
/** @var Tenant $tenant */
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ beforeEach(function () {
|
|||
],
|
||||
'tenancy.filesystem.suffix_base' => 'tenant-',
|
||||
'tenancy.filesystem.root_override.public' => '%storage_path%/app/public/',
|
||||
'tenancy.filesystem.url_override.public' => 'public-%tenant_id%'
|
||||
'tenancy.filesystem.url_override.public' => 'public-%tenant%'
|
||||
]);
|
||||
|
||||
Event::listen(TenancyInitialized::class, BootstrapTenancy::class);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue