From 6c4cd8c4dae8605af5b0864c352fab30bfdde581 Mon Sep 17 00:00:00 2001 From: Andy Scherzinger Date: Tue, 17 Nov 2026 20:29:03 +0100 Subject: [PATCH] fix(api): do not return deleted questions Requesting a single question also returned a question the owner had deleted, with its text and options, to everyone who can open the form, while the list of questions leaves it out. A deleted question now gets a Not Found response, like a question that does not exist. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Andy Scherzinger --- docs/API_v3.md | 1 + lib/Controller/ApiController.php | 3 ++- tests/Unit/Controller/ApiControllerTest.php | 17 +++++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/docs/API_v3.md b/docs/API_v3.md index 2b98dcda2..019b2df8c 100644 --- a/docs/API_v3.md +++ b/docs/API_v3.md @@ -399,6 +399,7 @@ Returns the requested question and options of the given form (without submission | _formId_ | Integer | ID of the form | | _questionId_ | Integer | ID of the question | - Response: An object of the requested question including options. + A deleted question gets a **Not Found** response. ``` "data": { diff --git a/lib/Controller/ApiController.php b/lib/Controller/ApiController.php index b5b2d89da..2a77fd351 100644 --- a/lib/Controller/ApiController.php +++ b/lib/Controller/ApiController.php @@ -448,6 +448,7 @@ public function getQuestions(int $formId): DataResponse { * @return DataResponse * @throws OCSBadRequestException Question doesn\'t belong to given Form * @throws OCSForbiddenException User has no permissions to get this form + * @throws OCSNotFoundException Question doesn\'t exist * @throws OCSNotFoundException Could not find form * * 200: the requested question @@ -469,7 +470,7 @@ public function getQuestion(int $formId, int $questionId): DataResponse { } $question = $this->formsService->getQuestion($questionId); - if ($question === null) { + if ($question === null || $question['order'] === 0) { throw new OCSNotFoundException('Question doesn\'t exist'); } diff --git a/tests/Unit/Controller/ApiControllerTest.php b/tests/Unit/Controller/ApiControllerTest.php index d6bb37be5..a06d08112 100644 --- a/tests/Unit/Controller/ApiControllerTest.php +++ b/tests/Unit/Controller/ApiControllerTest.php @@ -1268,6 +1268,23 @@ public function testUpdateFormRejectsInvalidConfirmationEmailQuestionId(string $ $this->apiController->updateForm(1, ['confirmationEmailQuestionId' => 7]); } + public function testGetDeletedQuestion(): void { + $form = new Form(); + $form->setId(1); + $this->formMapper->method('findById') + ->with(1) + ->willReturn($form); + $this->formsService->method('hasUserAccess') + ->with($form) + ->willReturn(true); + $this->formsService->method('getQuestion') + ->with(2) + ->willReturn(['id' => 2, 'formId' => 1, 'order' => 0, 'text' => 'Deleted', 'extraSettings' => []]); + + $this->expectException(OCSNotFoundException::class); + $this->apiController->getQuestion(1, 2); + } + public function testUpdateQuestionRejectsTypeChange(): void { $form = new Form(); $form->setId(1);