fix(storage): guard volume names and authorize source removal

This commit is contained in:
Andras Bacsai 2026-08-19 13:15:15 +02:00
parent 1d37968f5d
commit 937892b3ea
3 changed files with 12 additions and 4 deletions

View file

@ -374,10 +374,9 @@ public function fileStorageHostPath(): string
private function generateDefaultVolumeName(): string
{
return str($this->resource->name ?? 'volume')
->slug()
->append('-data')
->value();
$name = str($this->resource->name)->slug()->value();
return ($name ?: 'volume').'-data';
}
public function fileStoragePreviewPath(): string

View file

@ -160,6 +160,7 @@ class="volumes-col-actions volumes-cell-actions flex flex-wrap items-center just
<x-forms.input id="forms.{{ $id }}.hostPath" />
</div>
<x-modal-confirmation title="Remove Source Path?" isErrorButton
canGate="update" :canResource="$resource"
buttonTitle="Remove" submitAction="clearHostPath({{ $id }})"
:actions="[
'Are you sure you want to remove the source path?',

View file

@ -215,6 +215,7 @@ function createApplicationWithVolume(array $applicationAttributes = [], array $v
->not->toContain('id="host_path"')
->not->toContain('Swarm Mode detected')
->and($volumesView)
->toMatch('/<x-modal-confirmation title="Remove Source Path\?"[^>]*canGate="update"[^>]*:canResource="\$resource"/')
->toContain('The next deployment will use a named Docker volume instead.')
->toContain('Data from the existing host directory will not be copied to the named volume.');
});
@ -242,6 +243,13 @@ function createApplicationWithVolume(array $applicationAttributes = [], array $v
->assertSet('name', 'storage-app-data');
});
it('uses a valid fallback default volume name when the resource name has no slug characters', function () {
[$application] = createApplicationWithVolume(['name' => '---']);
Livewire::test(Storage::class, ['resource' => $application])
->assertSet('name', 'volume-data');
});
it('removes existing bind mount source paths from the volume table', function () {
[$application, $volume] = createApplicationWithVolume(volumeAttributes: [
'host_path' => '/srv/storage',