diff --git a/app/Http/Controllers/PublicationSupplementaryFileController.php b/app/Http/Controllers/PublicationSupplementaryFileController.php index 5fad6b69..d5b5c717 100644 --- a/app/Http/Controllers/PublicationSupplementaryFileController.php +++ b/app/Http/Controllers/PublicationSupplementaryFileController.php @@ -47,13 +47,13 @@ public function store(Request $request, Publication $publication) Gate::authorize('update', $publication); $validated = $request->validate([ - 'pdf' => 'required|file|mimes:pdf|max:50000', + 'file' => 'required|file|mimes:pdf,doc,docx|max:50000', 'supplementary_file_type' => ['required', Rule::enum(SupplementaryFileType::class)], 'description' => 'nullable|string|max:200', ]); $type = SupplementaryFileType::tryFrom($validated['supplementary_file_type']); - $media = $publication->addSupplementaryFile($validated['pdf'], $type, $validated['description'] ?? null); + $media = $publication->addSupplementaryFile($validated['file'], $type, $validated['description'] ?? null); activity() ->performedOn($publication) diff --git a/app/Models/Publication.php b/app/Models/Publication.php index 36f911d2..0204829a 100644 --- a/app/Models/Publication.php +++ b/app/Models/Publication.php @@ -91,7 +91,7 @@ public function registerMediaCollections(): void ->acceptsMimeTypes(['application/pdf']); $this->addMediaCollection(MediaCollection::SUPPLEMENTARY_FILE->value) - ->acceptsMimeTypes(['application/pdf']); + ->acceptsMimeTypes(['application/pdf', 'application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document']); } /** diff --git a/composer.lock b/composer.lock index 3376beb2..b4cf8d19 100644 --- a/composer.lock +++ b/composer.lock @@ -4442,16 +4442,16 @@ }, { "name": "league/csv", - "version": "9.19.0", + "version": "9.20.0", "source": { "type": "git", "url": "https://github.com/thephpleague/csv.git", - "reference": "f81df48a012a9e86d077e74eaff666fd15bfab88" + "reference": "553579df208641ada6ffb450b3a151e2fcfa4f31" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/thephpleague/csv/zipball/f81df48a012a9e86d077e74eaff666fd15bfab88", - "reference": "f81df48a012a9e86d077e74eaff666fd15bfab88", + "url": "https://api.github.com/repos/thephpleague/csv/zipball/553579df208641ada6ffb450b3a151e2fcfa4f31", + "reference": "553579df208641ada6ffb450b3a151e2fcfa4f31", "shasum": "" }, "require": { @@ -4525,7 +4525,7 @@ "type": "github" } ], - "time": "2024-12-08T08:09:35+00:00" + "time": "2024-12-13T15:49:27+00:00" }, { "name": "league/flysystem", diff --git a/resources/src/locales/en.json b/resources/src/locales/en.json index 4b32c812..94b6e252 100644 --- a/resources/src/locales/en.json +++ b/resources/src/locales/en.json @@ -817,5 +817,8 @@ "external-authors-caption": "Authors with an external affiliation", "with-orcid": "With ORCID", "with-orcid-caption": "Authors with an associated ORCID" + }, + "publication-supplementary": { + "upload-hint": "Only PDF or Word files are accepted. Maximum file size is {max}MB." } } diff --git a/resources/src/locales/fr.json b/resources/src/locales/fr.json index 1ecb94ec..6b57c434 100644 --- a/resources/src/locales/fr.json +++ b/resources/src/locales/fr.json @@ -817,5 +817,8 @@ "external-authors-caption": "Auteurs avec une affiliation externe", "with-orcid": "Avec ORCID", "with-orcid-caption": "Auteurs avec un ORCID associé" + }, + "publication-supplementary": { + "upload-hint": "Seuls les fichiers PDF ou Word sont acceptés. \nLa taille maximale du fichier est de {max} Mo." } } diff --git a/resources/src/models/Publication/Publication.ts b/resources/src/models/Publication/Publication.ts index f6e96e4c..064fdb74 100644 --- a/resources/src/models/Publication/Publication.ts +++ b/resources/src/models/Publication/Publication.ts @@ -140,7 +140,7 @@ export class PublicationService { public static async attachSupplementaryFile(file: File, id: number, type: SupplementaryFileType, desc: string | null = null) { const formData = new FormData() - formData.append('pdf', file) + formData.append('file', file) formData.append('supplementary_file_type', type) if (desc) { formData.append('description', desc) diff --git a/resources/src/models/Publication/components/PublicationSupplementaryFileManagementCard.vue b/resources/src/models/Publication/components/PublicationSupplementaryFileManagementCard.vue index 0c35cd0c..5817d627 100644 --- a/resources/src/models/Publication/components/PublicationSupplementaryFileManagementCard.vue +++ b/resources/src/models/Publication/components/PublicationSupplementaryFileManagementCard.vue @@ -159,15 +159,15 @@ const hideMrf = computed(() => { outlined use-chips :label="t('common.select-file')" - :hint="t('mrf.upload-hint', { max: maxFileSizeMB })" - accept="application/pdf" + :hint="t('publication-supplementary.upload-hint', { max: maxFileSizeMB })" + accept="application/pdf,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document" :max-file-size="maxFileSizeMB * 1e6" counter :loading="uploadingFile" @rejected="onFileRejected" > diff --git a/tests/Feature/Models/PublicationTest.php b/tests/Feature/Models/PublicationTest.php index ca8d73d9..ccec07cf 100644 --- a/tests/Feature/Models/PublicationTest.php +++ b/tests/Feature/Models/PublicationTest.php @@ -292,7 +292,7 @@ $response->assertForbidden(); $response = $this->actingAs($user)->postJson('/api/publications/'.$publication->id.'/supplementary-files', [ - 'pdf' => $file, + 'file' => $file, 'supplementary_file_type' => SupplementaryFileType::MANUSCRIPT_RECORD_FORM->value, 'description' => 'Test Description', ]); @@ -315,5 +315,33 @@ // delete the file $response = $this->actingAs($user)->deleteJson("/api/publications/{$publication->id}/supplementary-files/{$uuid}"); $response->assertNoContent(); +}); + +test('a user can upload a word document as a supplementary files', function () { + $publication = Publication::factory()->create(); + $user = $publication->user; + + // upload word document + $file = UploadedFile::fake()->createWithContent('test.docx', file_get_contents(__DIR__.'/support_files/test_doc.docx'))->size(1000); + + $response = $this->actingAs($user)->postJson('/api/publications/'.$publication->id.'/supplementary-files', [ + 'file' => $file, + 'supplementary_file_type' => SupplementaryFileType::MANUSCRIPT_RECORD_FORM->value, + 'description' => 'Test Description', + ]); + + $response->assertCreated(); + $uuid = $response->json('data.uuid'); + + // list the files + $response = $this->actingAs($user)->getJson('/api/publications/'.$publication->id.'/supplementary-files'); + $response->assertOk(); + $response->assertJsonCount(1, 'data'); + + $response2 = $this->actingAs($user)->get("/api/publications/{$publication->id}/supplementary-files/{$uuid}?download=true"); + $response2->assertDownload('test.docx'); + // delete the file + $response = $this->actingAs($user)->deleteJson("/api/publications/{$publication->id}/supplementary-files/{$uuid}"); + $response->assertNoContent(); }); diff --git a/tests/Feature/Models/support_files/test_doc.docx b/tests/Feature/Models/support_files/test_doc.docx new file mode 100644 index 00000000..0c53c7e1 Binary files /dev/null and b/tests/Feature/Models/support_files/test_doc.docx differ