Skip to content
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
8 changes: 8 additions & 0 deletions lib/Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1569,6 +1569,14 @@ public function deleteSubmission(int $formId, int $submissionId): DataResponse {
#[ApiRoute(verb: 'POST', url: '/api/v3/forms/{formId}/submissions/export')]
public function exportSubmissionsToCloud(int $formId, string $path, string $fileFormat = Constants::DEFAULT_FILE_FORMAT) {
$form = $this->formsService->getFormIfAllowed($formId, Constants::PERMISSION_RESULTS);

// canSeeResults() (used by getFormIfAllowed) also accepts submitters;
// exporting every submission needs the strict PERMISSION_RESULTS grant.
$permissions = $this->formsService->getPermissions($form);
if (!in_array(Constants::PERMISSION_RESULTS, $permissions, true)) {
throw new OCSForbiddenException('The current user has no permission to get the results for this form');
}

$file = $this->submissionService->writeFileToCloud($form, $path, $fileFormat);

return new DataResponse($file->getName());
Expand Down
22 changes: 22 additions & 0 deletions tests/Unit/Controller/ApiControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,28 @@ public function testExportSubmissionsToCloud_invalidForm() {
$this->apiController->exportSubmissionsToCloud(1, '');
}

public function testExportSubmissionsToCloud_noExportPermissions() {
$form = new Form();
$form->setId(1);
$form->setOwnerId('someoneElse');

$this->formsService->expects($this->once())
->method('getFormIfAllowed')
->with(1, Constants::PERMISSION_RESULTS)
->willReturn($form);

$this->formsService->expects($this->once())
->method('getPermissions')
->with($form)
->willReturn([Constants::PERMISSION_SUBMIT]);

$this->submissionService->expects($this->never())
->method('writeFileToCloud');

$this->expectException(OCSForbiddenException::class);
$this->apiController->exportSubmissionsToCloud(1, '/', 'csv');
}

public function testCreateNewForm_notAllowed() {
$this->configService->expects($this->once())
->method('canCreateForms')
Expand Down
Loading