Skip to content
Merged
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
1 change: 1 addition & 0 deletions docs/API_v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ Returns the requested question and options of the given form (without submission
| _questionId_ | Integer | ID of the question |
- Response: An object of the requested question including options.
Before the opening date (`opens`) of the form, users who can neither edit the form nor see its results get a **Forbidden** response.
A deleted question gets a **Not Found** response.

```
"data": {
Expand Down
3 changes: 2 additions & 1 deletion lib/Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@ public function getQuestions(int $formId): DataResponse {
* @throws OCSBadRequestException Question doesn\'t belong to given Form
* @throws OCSForbiddenException Form is not yet open
* @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
Expand All @@ -507,7 +508,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');
}

Expand Down
20 changes: 20 additions & 0 deletions tests/Unit/Controller/ApiControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1859,6 +1859,26 @@ public function testGetQuestionsAfterOpening(): void {
);
}

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('canSeeQuestions')
->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 testUpdateFormLogsLinkedResultsFile(): void {
$form = $this->createUpdatableForm();
$file = $this->createMock(File::class);
Expand Down
Loading