Skip to content

Commit 1e9dd86

Browse files
committed
fix(api): enforce submission visibility based on user permissions
fix(submit): adjust conditional rendering for submission state Signed-off-by: Christian Hartmann <chris-hartmann@gmx.de>
1 parent b1f6cef commit 1e9dd86

3 files changed

Lines changed: 26 additions & 2 deletions

File tree

lib/Controller/ApiController.php

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

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

1280+
if (!$canSeeAllSubmissions && $submission['userId'] !== $this->currentUser->getUID()) {
1281+
throw new OCSForbiddenException('User is not allowed to see submission');
1282+
}
1283+
12781284
// Append Display Names
12791285
if (substr($submission['userId'], 0, 10) === 'anon-user-') {
12801286
// Anonymous User

src/views/Submit.vue

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@
5858
</template>
5959
</NcEmptyContent>
6060
<NcEmptyContent
61-
v-else-if="success || (!form.canSubmit && !isMaxSubmissionsReached)"
61+
v-else-if="
62+
success
63+
|| (!form.canSubmit && !isMaxSubmissionsReached && !submissionId)
64+
"
6265
class="forms-emptycontent"
6366
:name="
6467
form.submissionMessage
@@ -75,7 +78,7 @@
7578
</template>
7679
</NcEmptyContent>
7780
<NcEmptyContent
78-
v-else-if="isMaxSubmissionsReached"
81+
v-else-if="isMaxSubmissionsReached && !submissionId"
7982
class="forms-emptycontent"
8083
:name="t('forms', 'Limit reached')"
8184
:description="

tests/Unit/Controller/ApiControllerTest.php

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

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

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

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

0 commit comments

Comments
 (0)