|
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; |
@@ -1161,16 +1162,22 @@ public function reorderOptions(int $formId, int $questionId, array $newOrder, ?s |
1161 | 1162 | #[ApiRoute(verb: 'GET', url: '/api/v3/forms/{formId}/submissions')] |
1162 | 1163 | public function getSubmissions(int $formId, ?string $query = null, ?int $limit = null, int $offset = 0, ?string $fileFormat = null): DataResponse|DataDownloadResponse { |
1163 | 1164 | $form = $this->formsService->getFormIfAllowed($formId, Constants::PERMISSION_RESULTS); |
| 1165 | + $permissions = $this->formsService->getPermissions($form); |
| 1166 | + $canSeeAllSubmissions = in_array(Constants::PERMISSION_RESULTS, $permissions, true); |
1164 | 1167 |
|
1165 | 1168 | if ($fileFormat !== null) { |
| 1169 | + if (!$canSeeAllSubmissions) { |
| 1170 | + throw new NoSuchFormException('The current user has no permission to get the results for this form', Http::STATUS_FORBIDDEN); |
| 1171 | + } |
| 1172 | + |
1166 | 1173 | $submissionsData = $this->submissionService->getSubmissionsData($form, $fileFormat); |
1167 | 1174 | $fileName = $this->formsService->getFileName($form, $fileFormat); |
1168 | 1175 |
|
1169 | 1176 | return new DataDownloadResponse($submissionsData, $fileName, Constants::SUPPORTED_EXPORT_FORMATS[$fileFormat]); |
1170 | 1177 | } |
1171 | 1178 |
|
1172 | 1179 | // Load submissions and currently active questions |
1173 | | - if (in_array(Constants::PERMISSION_RESULTS, $this->formsService->getPermissions($form))) { |
| 1180 | + if ($canSeeAllSubmissions) { |
1174 | 1181 | $submissions = $this->submissionService->getSubmissions($formId, null, $query, $limit, $offset); |
1175 | 1182 | $filteredSubmissionsCount = $this->submissionMapper->countSubmissions($formId, null, $query); |
1176 | 1183 | } else { |
|
0 commit comments