„Dokumente“ heißt jetzt „Downloads“
All checks were successful
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 2m38s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 2m31s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 2m39s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 3m54s
CI / PHP 8.3 / mysql:8.0 (pull_request) Successful in 3m50s
CI / PHP 8.4 / mysql:8.0 (pull_request) Successful in 3m55s
CI / PHP 8.3 / mysql:8.4 (pull_request) Successful in 3m18s
CI / PHP 8.4 / mysql:8.4 (pull_request) Successful in 3m19s
CI / Build-Artefakte aktuell (pull_request) Successful in 55s

Der Name „Dokumente“ bleibt dem kommenden QM-Modul (QM-Dokumente und
-Formulare) vorbehalten.

- Plugin plugins-core/downloads (Inhaus\Plugins\Downloads), Adresse
  /downloads, Rechte downloads.*, Objekttyp download_folder,
  Block downloads.folder, Kachel downloads.favorites
- Migration für bestehende Installationen: Tabellen und Spalten,
  Rechte, Sichtbarkeiten, Menü, Startseiten-Anordnung, Blöcke in
  Seiten und Fassungen, Plugin-Zustand; mit Test
- Alte Links unter /dokumente leiten dauerhaft weiter

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Friederich Loheide 2026-09-26 15:03:32 +00:00
parent c71131d054
commit f78cc96be7
120 changed files with 1091 additions and 866 deletions

View file

@ -1,6 +1,6 @@
<?php
namespace Tests\Feature\Documents;
namespace Tests\Feature\Downloads;
use App\Models\Role;
use App\Models\User;
@ -10,18 +10,18 @@ use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage;
use Inertia\Testing\AssertableInertia as Assert;
use Inhaus\Plugins\Documents\FolderTree;
use Inhaus\Plugins\Documents\Models\Document;
use Inhaus\Plugins\Documents\Models\DocumentFolder;
use Inhaus\Plugins\Downloads\FolderTree;
use Inhaus\Plugins\Downloads\Models\Download;
use Inhaus\Plugins\Downloads\Models\DownloadFolder;
use Tests\TestCase;
class DocumentsTest extends TestCase
class DownloadsTest extends TestCase
{
use RefreshDatabase;
private DocumentFolder $personal;
private DownloadFolder $personal;
private DocumentFolder $vertraege;
private DownloadFolder $vertraege;
private User $hr;
@ -30,35 +30,35 @@ class DocumentsTest extends TestCase
parent::setUp();
Storage::fake('local');
$this->personal = DocumentFolder::query()->create(['name' => 'Personal']);
$this->vertraege = DocumentFolder::query()->create(['name' => 'Verträge', 'parent_id' => $this->personal->id]);
$this->personal = DownloadFolder::query()->create(['name' => 'Personal']);
$this->vertraege = DownloadFolder::query()->create(['name' => 'Verträge', 'parent_id' => $this->personal->id]);
$role = Role::query()->create(['name' => 'Personalabteilung']);
$role->grants()->create(['ability' => 'documents.edit', 'resource_type' => 'document_folder', 'resource_id' => $this->personal->id, 'include_children' => true]);
$role->grants()->create(['ability' => 'downloads.edit', 'resource_type' => 'download_folder', 'resource_id' => $this->personal->id, 'include_children' => true]);
$this->hr = User::factory()->withRoles([$role])->create();
}
private function uploadTo(DocumentFolder $folder, array $files)
private function uploadTo(DownloadFolder $folder, array $files)
{
return $this->actingAs($this->hr)->post("/dokumente/ordner/{$folder->id}/dateien", ['files' => $files]);
return $this->actingAs($this->hr)->post("/downloads/ordner/{$folder->id}/dateien", ['files' => $files]);
}
public function test_editors_upload_documents_with_versions(): void
public function test_editors_upload_downloads_with_versions(): void
{
$this->uploadTo($this->vertraege, [
UploadedFile::fake()->create('Arbeitsvertrag Vorlage.docx', 40),
UploadedFile::fake()->create('Dienstanweisung.pdf', 120, 'application/pdf'),
])->assertSessionHas('status', '2 Dokumente hochgeladen.');
])->assertSessionHas('status', '2 Dateien hochgeladen.');
$doc = Document::query()->where('title', 'Dienstanweisung')->sole();
$doc = Download::query()->where('title', 'Dienstanweisung')->sole();
$this->assertSame(1, $doc->currentVersion->version);
Storage::disk('local')->assertExists($doc->currentVersion->path);
$this->post("/dokumente/{$doc->id}/versionen", ['file' => UploadedFile::fake()->create('Dienstanweisung 2027.pdf', 130, 'application/pdf'), 'note' => 'Neue Pausenregelung'])->assertSessionHasNoErrors();
$this->post("/downloads/{$doc->id}/versionen", ['file' => UploadedFile::fake()->create('Dienstanweisung 2027.pdf', 130, 'application/pdf'), 'note' => 'Neue Pausenregelung'])->assertSessionHasNoErrors();
$doc->refresh();
$this->assertSame(2, $doc->currentVersion->version);
$versions = $this->getJson("/dokumente/{$doc->id}/versionen")->assertOk()->json('versions');
$versions = $this->getJson("/downloads/{$doc->id}/versionen")->assertOk()->json('versions');
$this->assertSame([2, 1], array_column($versions, 'version'));
$this->assertSame('Neue Pausenregelung', $versions[0]['note']);
@ -70,42 +70,42 @@ class DocumentsTest extends TestCase
{
$this->uploadTo($this->personal, [UploadedFile::fake()->create('ok.pdf', 10), UploadedFile::fake()->create('boese.php', 1)])
->assertSessionHasErrors('files.1');
$this->assertSame(0, Document::query()->count(), 'Nichts wird halb hochgeladen.');
$this->assertSame(0, Download::query()->count(), 'Nichts wird halb hochgeladen.');
}
public function test_rights_apply_per_folder_including_subfolders(): void
{
$other = DocumentFolder::query()->create(['name' => 'Technik']);
$other = DownloadFolder::query()->create(['name' => 'Technik']);
$employee = User::factory()->create();
$this->uploadTo($other, [UploadedFile::fake()->create('x.pdf', 1)])->assertForbidden();
$this->uploadTo($this->vertraege, [UploadedFile::fake()->create('x.pdf', 1)])->assertSessionHasNoErrors();
$this->actingAs($employee)->post("/dokumente/ordner/{$this->personal->id}/dateien", ['files' => [UploadedFile::fake()->create('y.pdf', 1)]])->assertForbidden();
$this->actingAs($employee)->get("/dokumente/ordner/{$this->vertraege->id}")->assertOk()->assertInertia(fn (Assert $p) => $p
$this->actingAs($employee)->post("/downloads/ordner/{$this->personal->id}/dateien", ['files' => [UploadedFile::fake()->create('y.pdf', 1)]])->assertForbidden();
$this->actingAs($employee)->get("/downloads/ordner/{$this->vertraege->id}")->assertOk()->assertInertia(fn (Assert $p) => $p
->where('folder.can_edit', false)
->where('folder.editors', ['Personalabteilung'])
->has('documents', 1));
->has('downloads', 1));
// Unterordner anlegen darf die Personalabteilung, oberste Ebene nicht.
$this->actingAs($this->hr)->post('/dokumente/ordner', ['name' => 'Richtlinien', 'parent_id' => $this->personal->id])->assertRedirect();
$this->post('/dokumente/ordner', ['name' => 'Neu oben'])->assertForbidden();
$this->actingAs($this->hr)->post('/downloads/ordner', ['name' => 'Richtlinien', 'parent_id' => $this->personal->id])->assertRedirect();
$this->post('/downloads/ordner', ['name' => 'Neu oben'])->assertForbidden();
// Neuer Unterordner ist sofort mit abgedeckt.
$new = DocumentFolder::query()->where('name', 'Richtlinien')->sole();
$new = DownloadFolder::query()->where('name', 'Richtlinien')->sole();
$this->uploadTo($new, [UploadedFile::fake()->create('z.pdf', 1)])->assertSessionHasNoErrors();
// Verschieben nur in Ordner, in denen man pflegen darf.
$doc = Document::query()->where('folder_id', $new->id)->sole();
$this->put("/dokumente/{$doc->id}", ['title' => 'Z', 'folder_id' => $other->id])->assertForbidden();
$this->put("/dokumente/{$doc->id}", ['title' => 'Z', 'folder_id' => $this->personal->id])->assertSessionHasNoErrors();
$doc = Download::query()->where('folder_id', $new->id)->sole();
$this->put("/downloads/{$doc->id}", ['title' => 'Z', 'folder_id' => $other->id])->assertForbidden();
$this->put("/downloads/{$doc->id}", ['title' => 'Z', 'folder_id' => $this->personal->id])->assertSessionHasNoErrors();
}
public function test_visibility_is_inherited_and_protects_downloads(): void
{
$this->uploadTo($this->vertraege, [UploadedFile::fake()->create('Gehaltstabelle.xlsx', 5)]);
$doc = Document::query()->sole();
Audiences::sync('document_folder', $this->personal->id, ['department' => ['Personal']]);
$doc = Download::query()->sole();
Audiences::sync('download_folder', $this->personal->id, ['department' => ['Personal']]);
FolderTree::flush();
$clerk = User::factory()->create(['department' => 'Personal']);
@ -113,55 +113,55 @@ class DocumentsTest extends TestCase
$this->actingAs($clerk)->get($doc->downloadUrl())->assertOk();
$this->actingAs($nurse)->get($doc->downloadUrl())->assertNotFound();
$this->actingAs($nurse)->get("/dokumente/ordner/{$this->vertraege->id}")->assertNotFound();
$this->actingAs($nurse)->get('/dokumente?q=Gehalt')->assertInertia(fn (Assert $p) => $p->where('documents', []));
$this->actingAs($clerk)->get('/dokumente?q=Gehalt')->assertInertia(fn (Assert $p) => $p->where('documents.0.title', 'Gehaltstabelle'));
$this->actingAs($nurse)->get("/downloads/ordner/{$this->vertraege->id}")->assertNotFound();
$this->actingAs($nurse)->get('/downloads?q=Gehalt')->assertInertia(fn (Assert $p) => $p->where('downloads', []));
$this->actingAs($clerk)->get('/downloads?q=Gehalt')->assertInertia(fn (Assert $p) => $p->where('downloads.0.title', 'Gehaltstabelle'));
}
public function test_search_finds_titles_descriptions_and_file_names(): void
{
$this->uploadTo($this->personal, [UploadedFile::fake()->create('Formular-U12.pdf', 5)]);
Document::query()->sole()->update(['title' => 'Urlaubsantrag', 'description' => 'Für Erholungsurlaub']);
Download::query()->sole()->update(['title' => 'Urlaubsantrag', 'description' => 'Für Erholungsurlaub']);
foreach (['Urlaub', 'Erholung', 'U12'] as $term) {
$this->get('/dokumente?q='.$term)->assertInertia(fn (Assert $p) => $p->has('documents', 1));
$this->get('/downloads?q='.$term)->assertInertia(fn (Assert $p) => $p->has('downloads', 1));
}
}
public function test_overview_lists_areas_and_recent_documents(): void
public function test_overview_lists_areas_and_recent_downloads(): void
{
$this->personal->update(['description' => 'Alles rund ums Personal']);
$this->uploadTo($this->vertraege, [UploadedFile::fake()->create('Vertrag.pdf', 5)]);
$this->get('/dokumente')->assertInertia(fn (Assert $p) => $p
$this->get('/downloads')->assertInertia(fn (Assert $p) => $p
->where('children.0.description', 'Alles rund ums Personal')
->where('children.0.folders', 1)
->where('children.0.documents', 0)
->where('children.0.downloads', 0)
->where('recent.0.title', 'Vertrag')
->where('recent.0.folder_name', 'Verträge')
->where('recent.0.updated_by', $this->hr->name));
$this->get("/dokumente/ordner/{$this->vertraege->id}")->assertInertia(fn (Assert $p) => $p->where('recent', [])->where('documents.0.folder_name', null));
$this->get("/downloads/ordner/{$this->vertraege->id}")->assertInertia(fn (Assert $p) => $p->where('recent', [])->where('downloads.0.folder_name', null));
}
public function test_favorites_downloads_and_popular_documents(): void
public function test_favorites_downloads_and_popular_downloads(): void
{
$this->uploadTo($this->personal, [UploadedFile::fake()->create('Urlaubsantrag.pdf', 5, 'application/pdf'), UploadedFile::fake()->create('Reisekosten.xlsx', 5)]);
[$antrag, $reise] = [Document::query()->where('title', 'Urlaubsantrag')->sole(), Document::query()->where('title', 'Reisekosten')->sole()];
[$antrag, $reise] = [Download::query()->where('title', 'Urlaubsantrag')->sole(), Download::query()->where('title', 'Reisekosten')->sole()];
$employee = User::factory()->create(['department' => 'Pflege']);
$this->actingAs($employee)->post("/dokumente/{$antrag->id}/favorit")->assertRedirect();
$this->post("/dokumente/{$antrag->id}/favorit"); // doppelt schadet nicht
$this->actingAs($employee)->post("/downloads/{$antrag->id}/favorit")->assertRedirect();
$this->post("/downloads/{$antrag->id}/favorit"); // doppelt schadet nicht
$this->get($reise->downloadUrl())->assertOk();
$this->get($reise->downloadUrl())->assertOk();
$before = $reise->fresh()->updated_at;
$this->get($antrag->downloadUrl().'?vorschau=1')->assertOk()->assertHeader('Content-Security-Policy');
$this->assertSame(2, $reise->fresh()->downloads);
$this->assertSame(0, $antrag->fresh()->downloads, 'Vorschaubilder zählen nicht');
$this->assertSame(2, $reise->fresh()->download_count);
$this->assertSame(0, $antrag->fresh()->download_count, 'Vorschaubilder zählen nicht');
$this->assertEquals($before, $reise->fresh()->updated_at, 'Downloads sind keine Änderung');
$this->get('/dokumente')->assertInertia(fn (Assert $p) => $p
$this->get('/downloads')->assertInertia(fn (Assert $p) => $p
->where('favorites.0.title', 'Urlaubsantrag')
->where('favorites.0.favorite', true)
->where('favorites.0.preview_kind', 'pdf')
@ -170,51 +170,51 @@ class DocumentsTest extends TestCase
$this->get('/')->assertInertia(fn (Assert $p) => $p->where(
'widgets',
fn ($widgets) => collect($widgets)->firstWhere('key', 'documents.favorites')['props']['favorites'][0]['title'] === 'Urlaubsantrag'
fn ($widgets) => collect($widgets)->firstWhere('key', 'downloads.favorites')['props']['favorites'][0]['title'] === 'Urlaubsantrag'
));
$this->delete("/dokumente/{$antrag->id}/favorit");
$this->get('/dokumente')->assertInertia(fn (Assert $p) => $p->where('favorites', []));
$this->delete("/downloads/{$antrag->id}/favorit");
$this->get('/downloads')->assertInertia(fn (Assert $p) => $p->where('favorites', []));
// Ohne Sichtrecht kein Favorit.
Audiences::sync('document_folder', $this->personal->id, ['department' => ['Personal']]);
Audiences::sync('download_folder', $this->personal->id, ['department' => ['Personal']]);
FolderTree::flush();
$this->post("/dokumente/{$antrag->id}/favorit")->assertNotFound();
$this->post("/downloads/{$antrag->id}/favorit")->assertNotFound();
}
public function test_previews_are_only_served_for_safe_types(): void
{
$this->uploadTo($this->personal, [UploadedFile::fake()->create('notiz.txt', 1, 'text/plain')]);
$this->get(Document::query()->sole()->downloadUrl().'?vorschau=1')->assertNotFound();
$this->get(Download::query()->sole()->downloadUrl().'?vorschau=1')->assertNotFound();
}
public function test_folders_can_only_be_deleted_when_empty(): void
{
$this->actingAs($this->hr)->delete("/dokumente/ordner/{$this->vertraege->id}")->assertRedirect(route('documents.folder', $this->personal));
$this->assertNull(DocumentFolder::query()->find($this->vertraege->id));
$this->actingAs($this->hr)->delete("/downloads/ordner/{$this->vertraege->id}")->assertRedirect(route('downloads.folder', $this->personal));
$this->assertNull(DownloadFolder::query()->find($this->vertraege->id));
$this->uploadTo($this->personal, [UploadedFile::fake()->create('a.pdf', 1)]);
$this->actingAs(User::factory()->admin()->create())->delete("/dokumente/ordner/{$this->personal->id}")->assertSessionHasErrors('folder');
$this->actingAs(User::factory()->admin()->create())->delete("/downloads/ordner/{$this->personal->id}")->assertSessionHasErrors('folder');
}
public function test_folder_block_in_pages(): void
{
$this->uploadTo($this->personal, [UploadedFile::fake()->create('Checkliste.pdf', 5)]);
$content = app(Content::class);
$rendered = $content->render($content->sanitize(['blocks' => [['type' => 'documents.folder', 'data' => ['folder' => (string) $this->personal->id]]]]), User::factory()->create());
$rendered = $content->render($content->sanitize(['blocks' => [['type' => 'downloads.folder', 'data' => ['folder' => (string) $this->personal->id]]]]), User::factory()->create());
$this->assertSame('Checkliste', $rendered['blocks'][0]['props']['documents'][0]['title']);
$this->assertSame('Checkliste', $rendered['blocks'][0]['props']['downloads'][0]['title']);
}
public function test_deleting_a_document_removes_all_files(): void
public function test_deleting_a_download_removes_all_files(): void
{
$this->uploadTo($this->personal, [UploadedFile::fake()->create('a.pdf', 1)]);
$doc = Document::query()->sole();
$this->post("/dokumente/{$doc->id}/versionen", ['file' => UploadedFile::fake()->create('a2.pdf', 1)]);
$doc = Download::query()->sole();
$this->post("/downloads/{$doc->id}/versionen", ['file' => UploadedFile::fake()->create('a2.pdf', 1)]);
$paths = $doc->versions()->pluck('path');
$this->delete("/dokumente/{$doc->id}")->assertSessionHasNoErrors();
$this->delete("/downloads/{$doc->id}")->assertSessionHasNoErrors();
foreach ($paths as $path) {
Storage::disk('local')->assertMissing($path);
}

View file

@ -0,0 +1,101 @@
<?php
namespace Tests\Feature\Downloads;
use App\Models\Role;
use App\Models\User;
use App\Support\Navigation;
use App\Support\Settings;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use Tests\TestCase;
/**
* Upgrade älterer Installationen: aus „Dokumente“ wird „Downloads“.
*/
class RenameMigrationTest extends TestCase
{
use RefreshDatabase;
public function test_old_installations_are_renamed_with_all_data(): void
{
// Stand vor der Umbenennung nachbauen.
foreach (['download_favorites', 'download_versions', 'downloads', 'download_folders'] as $table) {
Schema::drop($table);
}
Schema::create('document_folders', function (Blueprint $t) {
$t->id();
$t->foreignId('parent_id')->nullable()->constrained('document_folders');
$t->string('name');
$t->string('description', 500)->nullable();
$t->unsignedInteger('sort')->default(0);
$t->foreignId('created_by')->nullable();
$t->timestamps();
});
Schema::create('documents', function (Blueprint $t) {
$t->id();
$t->foreignId('folder_id')->constrained('document_folders');
$t->string('title');
$t->text('description')->nullable();
$t->unsignedBigInteger('current_version_id')->nullable();
$t->foreignId('created_by')->nullable();
$t->foreignId('updated_by')->nullable();
$t->unsignedInteger('downloads')->default(0);
$t->timestamps();
});
Schema::create('document_versions', function (Blueprint $t) {
$t->id();
$t->foreignId('document_id')->constrained('documents')->cascadeOnDelete();
$t->unsignedInteger('version');
$t->string('name');
$t->string('path');
$t->string('mime')->nullable();
$t->unsignedBigInteger('size')->default(0);
$t->string('note', 500)->nullable();
$t->foreignId('uploaded_by')->nullable();
$t->timestamp('created_at')->nullable();
});
Schema::create('document_favorites', function (Blueprint $t) {
$t->foreignId('user_id')->constrained()->cascadeOnDelete();
$t->foreignId('document_id')->constrained()->cascadeOnDelete();
$t->timestamp('created_at')->nullable();
$t->primary(['user_id', 'document_id']);
});
$user = User::factory()->create();
$role = Role::query()->create(['name' => 'Personal']);
$folder = DB::table('document_folders')->insertGetId(['name' => 'Personal']);
$doc = DB::table('documents')->insertGetId(['folder_id' => $folder, 'title' => 'Urlaubsantrag', 'downloads' => 42]);
DB::table('document_versions')->insert(['document_id' => $doc, 'version' => 1, 'name' => 'a.pdf', 'path' => 'documents/1/a.pdf']);
DB::table('document_favorites')->insert(['user_id' => $user->id, 'document_id' => $doc]);
DB::table('grants')->insert(['role_id' => $role->id, 'ability' => 'documents.edit', 'resource_type' => 'document_folder', 'resource_id' => $folder, 'include_children' => true]);
DB::table('audiences')->insert(['resource_type' => 'document_folder', 'resource_id' => $folder, 'rule_type' => 'department', 'rule_value' => 'Personal']);
app(Settings::class)->set(Navigation::MENU_SETTING, [['id' => 'a', 'type' => 'group', 'label' => 'Service', 'children' => [['id' => 'b', 'type' => 'module', 'module' => 'documents']]]]);
app(Settings::class)->set('dashboard.layout', ['documents.favorites' => ['sort' => 5, 'visible' => false]]);
DB::table('pages')->insert(['title' => 'Seite', 'slug' => 'seite', 'path' => 'seite', 'content' => json_encode(['blocks' => [['id' => 'x', 'type' => 'documents.folder', 'data' => ['folder' => (string) $folder]]]])]);
(require base_path('plugins-core/downloads/database/migrations/2026_09_29_000002_rename_documents_to_downloads.php'))->up();
$this->assertFalse(Schema::hasTable('documents'));
$this->assertSame(42, (int) DB::table('downloads')->where('id', $doc)->value('download_count'));
$this->assertSame($doc, (int) DB::table('download_versions')->value('download_id'));
$this->assertSame($doc, (int) DB::table('download_favorites')->value('download_id'));
$this->assertSame(['downloads.edit', 'download_folder'], array_values((array) DB::table('grants')->where('role_id', $role->id)->first(['ability', 'resource_type'])));
$this->assertSame('download_folder', DB::table('audiences')->value('resource_type'));
$this->assertSame('downloads', app(Settings::class)->get(Navigation::MENU_SETTING)[0]['children'][0]['module']);
$this->assertSame(['downloads.favorites'], array_keys(app(Settings::class)->get('dashboard.layout')));
$this->assertStringContainsString('"downloads.folder"', DB::table('pages')->value('content'));
// Zweiter Lauf ändert nichts.
(require base_path('plugins-core/downloads/database/migrations/2026_09_29_000002_rename_documents_to_downloads.php'))->up();
$this->assertSame(42, (int) DB::table('downloads')->where('id', $doc)->value('download_count'));
}
public function test_old_links_redirect(): void
{
$this->get('/dokumente/ordner/5?q=urlaub')->assertRedirect('/downloads/ordner/5?q=urlaub')->assertStatus(301);
$this->get('/dokumente')->assertRedirect('/downloads');
}
}

View file

@ -22,7 +22,7 @@ class CorePluginToggleTest extends TestCase
$file = storage_path('app/plugins.json');
$this->previousState = is_file($file) ? file_get_contents($file) : null;
file_put_contents($file, json_encode(['news' => ['enabled' => false], 'events' => ['enabled' => false], 'pages' => ['enabled' => false], 'forms' => ['enabled' => false], 'wordpress-import' => ['enabled' => false], 'documents' => ['enabled' => false]]));
file_put_contents($file, json_encode(['news' => ['enabled' => false], 'events' => ['enabled' => false], 'pages' => ['enabled' => false], 'forms' => ['enabled' => false], 'wordpress-import' => ['enabled' => false], 'downloads' => ['enabled' => false]]));
// Plugins werden beim Start der Anwendung geladen – also neu starten.
$this->refreshApplication();