Skip to content

Commit e9865f8

Browse files
authored
Merge pull request #3271 from nextcloud/backport/3269/stable5.2
[stable5.2] fix: handle submissions correctly when user wants to edit a given response
2 parents ca793f9 + ee3c136 commit e9865f8

3 files changed

Lines changed: 30 additions & 1 deletion

File tree

lib/Controller/ApiController.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,6 +1259,8 @@ public function getSubmissions(int $formId, ?string $query = null, ?int $limit =
12591259
#[ApiRoute(verb: 'GET', url: '/api/v3/forms/{formId}/submissions/{submissionId}')]
12601260
public function getSubmission(int $formId, int $submissionId): DataResponse|DataDownloadResponse {
12611261
$form = $this->formsService->getFormIfAllowed($formId, Constants::PERMISSION_RESULTS);
1262+
$permissions = $this->formsService->getPermissions($form);
1263+
$canSeeAllSubmissions = in_array(Constants::PERMISSION_RESULTS, $permissions, true);
12621264

12631265
$submission = $this->submissionService->getSubmission($submissionId);
12641266
if ($submission === null) {
@@ -1269,6 +1271,10 @@ public function getSubmission(int $formId, int $submissionId): DataResponse|Data
12691271
throw new OCSBadRequestException('Submission doesn\'t belong to given form');
12701272
}
12711273

1274+
if (!$canSeeAllSubmissions && $submission['userId'] !== $this->currentUser->getUID()) {
1275+
throw new OCSForbiddenException('User is not allowed to see submission');
1276+
}
1277+
12721278
// Append Display Names
12731279
if (substr($submission['userId'], 0, 10) === 'anon-user-') {
12741280
// Anonymous User

src/views/Submit.vue

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
</template>
5858
</NcEmptyContent>
5959
<NcEmptyContent
60-
v-else-if="success || !form.canSubmit"
60+
v-else-if="success || (!form.canSubmit && !submissionId)"
6161
class="forms-emptycontent"
6262
:name="
6363
form.submissionMessage
@@ -657,6 +657,14 @@ export default {
657657
`option ${text} could not be mapped to an option for question ${questionId}`,
658658
)
659659
}
660+
} else if (question.type === 'file') {
661+
// File answers cannot be restored when editing a submission —
662+
// the uploaded file has already been moved to permanent storage
663+
// and the temporary uploadedFileId no longer exists.
664+
// The user must re-upload files if needed.
665+
logger.debug(
666+
`Skipping file answer for question ${questionId} — cannot restore uploaded files`,
667+
)
660668
} else {
661669
answers[questionId].push(text)
662670
}

tests/Unit/Controller/ApiControllerTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,6 +1057,11 @@ public function testGetSubmission_success() {
10571057
->with(1, Constants::PERMISSION_RESULTS)
10581058
->willReturn($form);
10591059

1060+
$this->formsService->expects($this->once())
1061+
->method('getPermissions')
1062+
->with($form)
1063+
->willReturn([Constants::PERMISSION_RESULTS]);
1064+
10601065
$this->submissionService->expects($this->once()) // Changed from submissionMapper
10611066
->method('getSubmission')
10621067
->with(42)
@@ -1120,6 +1125,11 @@ public function testGetSubmission_anonymousUser() {
11201125
->with(1, Constants::PERMISSION_RESULTS)
11211126
->willReturn($form);
11221127

1128+
$this->formsService->expects($this->once())
1129+
->method('getPermissions')
1130+
->with($form)
1131+
->willReturn([Constants::PERMISSION_RESULTS]);
1132+
11231133
$this->submissionService->expects($this->once()) // Changed from submissionMapper
11241134
->method('getSubmission')
11251135
->with(42)
@@ -1153,6 +1163,11 @@ public function testGetSubmission_userNotFound() {
11531163
->with(1, Constants::PERMISSION_RESULTS)
11541164
->willReturn($form);
11551165

1166+
$this->formsService->expects($this->once())
1167+
->method('getPermissions')
1168+
->with($form)
1169+
->willReturn([Constants::PERMISSION_RESULTS]);
1170+
11561171
$this->submissionService->expects($this->once()) // Changed from submissionMapper
11571172
->method('getSubmission')
11581173
->with(42)

0 commit comments

Comments
 (0)