Skip to content
Open
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
6 changes: 6 additions & 0 deletions lib/Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1265,6 +1265,8 @@ public function getSubmissions(int $formId, ?string $query = null, ?int $limit =
#[ApiRoute(verb: 'GET', url: '/api/v3/forms/{formId}/submissions/{submissionId}')]
public function getSubmission(int $formId, int $submissionId): DataResponse|DataDownloadResponse {
$form = $this->formsService->getFormIfAllowed($formId, Constants::PERMISSION_RESULTS);
$permissions = $this->formsService->getPermissions($form);
$canSeeAllSubmissions = in_array(Constants::PERMISSION_RESULTS, $permissions, true);

$submission = $this->submissionService->getSubmission($submissionId);
if ($submission === null) {
Expand All @@ -1275,6 +1277,10 @@ public function getSubmission(int $formId, int $submissionId): DataResponse|Data
throw new OCSBadRequestException('Submission doesn\'t belong to given form');
}

if (!$canSeeAllSubmissions && $submission['userId'] !== $this->currentUser->getUID()) {
throw new OCSForbiddenException('User is not allowed to see submission');
}

// Append Display Names
if (substr($submission['userId'], 0, 10) === 'anon-user-') {
// Anonymous User
Expand Down
7 changes: 5 additions & 2 deletions src/views/Submit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@
</template>
</NcEmptyContent>
<NcEmptyContent
v-else-if="success || (!form.canSubmit && !isMaxSubmissionsReached)"
v-else-if="
success
|| (!form.canSubmit && !isMaxSubmissionsReached && !submissionId)
"
class="forms-emptycontent"
:name="
form.submissionMessage
Expand All @@ -75,7 +78,7 @@
</template>
</NcEmptyContent>
<NcEmptyContent
v-else-if="isMaxSubmissionsReached"
v-else-if="isMaxSubmissionsReached && !submissionId"
class="forms-emptycontent"
:name="t('forms', 'Limit reached')"
:description="
Expand Down
15 changes: 15 additions & 0 deletions tests/Unit/Controller/ApiControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,11 @@ public function testGetSubmission_success() {
->with(1, Constants::PERMISSION_RESULTS)
->willReturn($form);

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

$this->submissionService->expects($this->once()) // Changed from submissionMapper
->method('getSubmission')
->with(42)
Expand Down Expand Up @@ -1121,6 +1126,11 @@ public function testGetSubmission_anonymousUser() {
->with(1, Constants::PERMISSION_RESULTS)
->willReturn($form);

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

$this->submissionService->expects($this->once()) // Changed from submissionMapper
->method('getSubmission')
->with(42)
Expand Down Expand Up @@ -1154,6 +1164,11 @@ public function testGetSubmission_userNotFound() {
->with(1, Constants::PERMISSION_RESULTS)
->willReturn($form);

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

$this->submissionService->expects($this->once()) // Changed from submissionMapper
->method('getSubmission')
->with(42)
Expand Down
Loading