|
22 | 22 | use OCA\Forms\Db\SubmissionMapper; |
23 | 23 | use OCA\Forms\Db\UploadedFile; |
24 | 24 | use OCA\Forms\Db\UploadedFileMapper; |
| 25 | +use OCA\Forms\Exception\NoSuchFormException; |
25 | 26 | use OCA\Forms\ResponseDefinitions; |
26 | 27 | use OCA\Forms\Service\ConfigService; |
27 | 28 | use OCA\Forms\Service\FormsService; |
@@ -1155,16 +1156,22 @@ public function reorderOptions(int $formId, int $questionId, array $newOrder) { |
1155 | 1156 | #[ApiRoute(verb: 'GET', url: '/api/v3/forms/{formId}/submissions')] |
1156 | 1157 | public function getSubmissions(int $formId, ?string $query = null, ?int $limit = null, int $offset = 0, ?string $fileFormat = null): DataResponse|DataDownloadResponse { |
1157 | 1158 | $form = $this->formsService->getFormIfAllowed($formId, Constants::PERMISSION_RESULTS); |
| 1159 | + $permissions = $this->formsService->getPermissions($form); |
| 1160 | + $canSeeAllSubmissions = in_array(Constants::PERMISSION_RESULTS, $permissions, true); |
1158 | 1161 |
|
1159 | 1162 | if ($fileFormat !== null) { |
| 1163 | + if (!$canSeeAllSubmissions) { |
| 1164 | + throw new NoSuchFormException('The current user has no permission to get the results for this form', Http::STATUS_FORBIDDEN); |
| 1165 | + } |
| 1166 | + |
1160 | 1167 | $submissionsData = $this->submissionService->getSubmissionsData($form, $fileFormat); |
1161 | 1168 | $fileName = $this->formsService->getFileName($form, $fileFormat); |
1162 | 1169 |
|
1163 | 1170 | return new DataDownloadResponse($submissionsData, $fileName, Constants::SUPPORTED_EXPORT_FORMATS[$fileFormat]); |
1164 | 1171 | } |
1165 | 1172 |
|
1166 | 1173 | // Load submissions and currently active questions |
1167 | | - if (in_array(Constants::PERMISSION_RESULTS, $this->formsService->getPermissions($form))) { |
| 1174 | + if ($canSeeAllSubmissions) { |
1168 | 1175 | $submissions = $this->submissionService->getSubmissions($formId, null, $query, $limit, $offset); |
1169 | 1176 | $filteredSubmissionsCount = $this->submissionMapper->countSubmissions($formId, null, $query); |
1170 | 1177 | } else { |
|
0 commit comments