Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: upload of word files for supplementary files #869

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion app/Models/Publication.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}

/**
Expand Down
10 changes: 5 additions & 5 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions resources/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
}
3 changes: 3 additions & 0 deletions resources/src/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
}
2 changes: 1 addition & 1 deletion resources/src/models/Publication/Publication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
>
<template #prepend>
<q-icon name="mdi-file-pdf-box" />
<q-icon name="mdi-file-document-outline" />
</template>
</q-file>
</div>
Expand Down
30 changes: 29 additions & 1 deletion tests/Feature/Models/PublicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
]);
Expand All @@ -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();
});
Binary file added tests/Feature/Models/support_files/test_doc.docx
Binary file not shown.
Loading