Skip to content

Commit 5a7ccbe

Browse files
committed
fix: do not add result permissions to see own submissions
When a user has submitted a form they should not have result permissions, but instead we should only show their own submissions. Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
1 parent 9079ca4 commit 5a7ccbe

File tree

4 files changed

+19
-4
lines changed

4 files changed

+19
-4
lines changed

lib/Controller/ApiController.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use OCA\Forms\Db\SubmissionMapper;
2323
use OCA\Forms\Db\UploadedFile;
2424
use OCA\Forms\Db\UploadedFileMapper;
25+
use OCA\Forms\Exception\NoSuchFormException;
2526
use OCA\Forms\ResponseDefinitions;
2627
use OCA\Forms\Service\ConfigService;
2728
use OCA\Forms\Service\FormsService;
@@ -1161,16 +1162,22 @@ public function reorderOptions(int $formId, int $questionId, array $newOrder, ?s
11611162
#[ApiRoute(verb: 'GET', url: '/api/v3/forms/{formId}/submissions')]
11621163
public function getSubmissions(int $formId, ?string $query = null, ?int $limit = null, int $offset = 0, ?string $fileFormat = null): DataResponse|DataDownloadResponse {
11631164
$form = $this->formsService->getFormIfAllowed($formId, Constants::PERMISSION_RESULTS);
1165+
$permissions = $this->formsService->getPermissions($form);
1166+
$canSeeAllSubmissions = in_array(Constants::PERMISSION_RESULTS, $permissions, true);
11641167

11651168
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+
11661173
$submissionsData = $this->submissionService->getSubmissionsData($form, $fileFormat);
11671174
$fileName = $this->formsService->getFileName($form, $fileFormat);
11681175

11691176
return new DataDownloadResponse($submissionsData, $fileName, Constants::SUPPORTED_EXPORT_FORMATS[$fileFormat]);
11701177
}
11711178

11721179
// Load submissions and currently active questions
1173-
if (in_array(Constants::PERMISSION_RESULTS, $this->formsService->getPermissions($form))) {
1180+
if ($canSeeAllSubmissions) {
11741181
$submissions = $this->submissionService->getSubmissions($formId, null, $query, $limit, $offset);
11751182
$filteredSubmissionsCount = $this->submissionMapper->countSubmissions($formId, null, $query);
11761183
} else {

lib/Service/FormsService.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,6 @@ public function getForm(Form $form): array {
212212
$userSubmissionCount = $this->submissionMapper->countSubmissions($form->getId(), $this->currentUser->getUID());
213213
if ($userSubmissionCount > 0) {
214214
$result['submissionCount'] = $userSubmissionCount;
215-
// Append `results` permission if user has submitted to the form
216-
$result['permissions'][] = Constants::PERMISSION_RESULTS;
217215
}
218216
}
219217

src/Forms.vue

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,13 @@ export default {
269269
return false
270270
}
271271
272+
if (this.$route.name === 'results') {
273+
return form.permissions.includes(this.$route.name)
274+
|| form.submissionCount > 0
275+
}
276+
272277
// Return whether route is in the permissions-list
273-
return form?.permissions.includes(this.$route.name)
278+
return form.permissions.includes(this.$route.name)
274279
},
275280
276281
selectedForm: {

src/views/Results.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050

5151
<!-- Action menu for cloud export and deletion -->
5252
<NcActions
53+
v-if="canExportSubmissions"
5354
:aria-label="t('forms', 'Options')"
5455
force-name
5556
:inline="isMobile ? 0 : 1"
@@ -449,6 +450,10 @@ export default {
449450
return this.form.state === FormState.FormArchived
450451
},
451452
453+
canExportSubmissions() {
454+
return this.form.permissions.includes(this.PERMISSION_TYPES.PERMISSION_RESULTS)
455+
},
456+
452457
canDeleteSubmissions() {
453458
return (
454459
this.form.permissions.includes(

0 commit comments

Comments
 (0)