Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Hartmann <chris-hartmann@gmx.de>
  • Loading branch information
Chartman123 committed Oct 28, 2024
1 parent cfcde6b commit 956342d
Show file tree
Hide file tree
Showing 4 changed files with 163 additions and 57 deletions.
4 changes: 2 additions & 2 deletions lib/Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1081,9 +1081,9 @@ public function reorderOptions(int $formId, int $questionId, array $newOrder) {
$oldOrder = $options[$arrayKey]->getOrder();

// Only set order, if it changed.
if ($oldOrder !== $arrayKey + 1) {
if ($oldOrder !== (int)$arrayKey + 1) {

Check warning on line 1084 in lib/Controller/ApiController.php

View check run for this annotation

Codecov / codecov/patch

lib/Controller/ApiController.php#L1084

Added line #L1084 was not covered by tests
// Set Order. ArrayKey counts from zero, order counts from 1.
$options[$arrayKey]->setOrder($arrayKey + 1);
$options[$arrayKey]->setOrder((int)$arrayKey + 1);

Check warning on line 1086 in lib/Controller/ApiController.php

View check run for this annotation

Codecov / codecov/patch

lib/Controller/ApiController.php#L1086

Added line #L1086 was not covered by tests
}
}

Expand Down
4 changes: 2 additions & 2 deletions lib/Controller/ShareApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public function newShare(int $formId, int $shareType, string $shareWith = '', ar
*
* @param int $formId of the form
* @param int $shareId of the share to update
* @param array{key: string, values: mixed} $keyValuePairs Array of key=>value pairs to update.
* @param array<string, mixed> $keyValuePairs Array of key=>value pairs to update.
* @return DataResponse<Http::STATUS_OK, int, array{}>
* @throws OCSBadRequestException Share doesn't belong to given Form
* @throws OCSBadRequestException Invalid permission given
Expand Down Expand Up @@ -277,7 +277,7 @@ public function updateShare(int $formId, int $shareId, array $keyValuePairs): Da
}

//Don't allow to change other properties than permissions
if (count($keyValuePairs) > 1 || !key_exists('permissions', $keyValuePairs)) {
if (count($keyValuePairs) > 1 || !array_key_exists('permissions', $keyValuePairs)) {
$this->logger->debug('Not allowed to update other properties than permissions');
throw new OCSForbiddenException('Not allowed to update other properties than permissions');

Check warning on line 282 in lib/Controller/ShareApiController.php

View check run for this annotation

Codecov / codecov/patch

lib/Controller/ShareApiController.php#L282

Added line #L282 was not covered by tests
}
Expand Down
81 changes: 51 additions & 30 deletions lib/ResponseDefinitions.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,26 @@
namespace OCA\Forms;

/**
* @psalm-type FormsPartialForm = array{
* id: int,
* hash: string,
* title: string,
* expires: int,
* permissions: string[],
* partial: bool,
* state: int
* }
*
* @psalm-type FormsOption = array{
* id: int,
* questionId: int,
* text: string,
* order: ?int
* }
*
* @psalm-type FormsQuestionExtraSettings = array{
* allowOtherAnswer?: ?bool,
* allowedFileExtensions?: ?list<string>,
* allowedFileTypes?: ?list<string>,
* maxAllowedFilesCount?: ?int,
* maxFileSize?: ?int,
* optionsLimitMax?: ?int,
* optionsLimitMin?: ?int,
* shuffleOptions?: ?bool,
* validationRegex?: ?string,
* validationType?: ?string
* }
*
* @psalm-type FormsQuestion = array{
* id: int,
* formId: int,
Expand All @@ -49,9 +52,10 @@
* isRequired: bool,
* text: string,
* name: string,
* options: array<FormsOption>,
* accept: string[],
* extraSettings: \stdClass
* description: string,
* extraSettings: list<empty>|FormsQuestionExtraSettings,
* options: ?list<FormsOption>,
* accept?: ?list<string>
* }
*
* @psalm-type FormsAnswer = array{
Expand All @@ -66,13 +70,39 @@
* formId: int,
* userId: string,
* timestamp: int,
* answers: array<FormsAnswer>,
* answers: list<FormsAnswer>,
* userDisplayName: string
* }
*
* @psalm-type FormsSubmissions = array{
* submissions: array<FormsSubmission>,
* questions: array<FormsQuestion>
* submissions: list<FormsSubmission>,
* questions: list<FormsQuestion>
* }
*
* @psalm-type FormsAccess = array{
* permitAllUsers: bool,
* showToAllUsers: bool
* }
*
* @psalm-type FormsPermission = "edit"|"results"|"results_delete"|"submit"|"embed"
*
* @psalm-type FormsShare = array{
* id: int,
* formId: int,
* shareType: int,
* shareWith: string,
* permissions: list<FormsPermission>,
* displayName: string
* }
*
* @psalm-type FormsPartialForm = array{
* id: int,
* hash: string,
* title: string,
* expires: int,
* permissions: list<FormsPermission>,
* partial: true,
* state: int
* }
*
* @psalm-type FormsForm = array{
Expand All @@ -82,32 +112,23 @@
* description: string,
* ownerId: string,
* created: int,
* access: \stdClass,
* access: FormsAccess,
* expires: int,
* isAnonymous: bool,
* submitMultiple: bool,
* showExpiration: bool,
* canSubmit: bool,
* permissions: string[],
* questions: array<FormsQuestion>,
* permissions: list<FormsPermission>,
* questions: list<FormsQuestion>,
* state: int,
* shares: string[],
* submissions: array<FormsSubmission>,
* shares: list<string>,
* submissions: list<FormsSubmission>,
* }
*
* @psalm-type FormsUploadedFile = array{
* uploadedFileId: int,
* fileName: string
* }
*
* @psalm-type FormsShare = array{
* id: int,
* formId: int,
* shareType: int,
* shareWith: string,
* permissions: string[],
* displayName: string
* }
*/
class ResponseDefinitions {
}
131 changes: 108 additions & 23 deletions openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,21 @@
}
},
"schemas": {
"Access": {
"type": "object",
"required": [
"permitAllUsers",
"showToAllUsers"
],
"properties": {
"permitAllUsers": {
"type": "boolean"
},
"showToAllUsers": {
"type": "boolean"
}
}
},
"Answer": {
"type": "object",
"required": [
Expand Down Expand Up @@ -115,8 +130,7 @@
"format": "int64"
},
"access": {
"type": "object",
"additionalProperties": true
"$ref": "#/components/schemas/Access"
},
"expires": {
"type": "integer",
Expand All @@ -137,7 +151,7 @@
"permissions": {
"type": "array",
"items": {
"type": "string"
"$ref": "#/components/schemas/Permission"
}
},
"questions": {
Expand Down Expand Up @@ -244,18 +258,31 @@
"permissions": {
"type": "array",
"items": {
"type": "string"
"$ref": "#/components/schemas/Permission"
}
},
"partial": {
"type": "boolean"
"type": "boolean",
"enum": [
true
]
},
"state": {
"type": "integer",
"format": "int64"
}
}
},
"Permission": {
"type": "string",
"enum": [
"edit",
"results",
"results_delete",
"submit",
"embed"
]
},
"Question": {
"type": "object",
"required": [
Expand All @@ -266,9 +293,9 @@
"isRequired",
"text",
"name",
"options",
"accept",
"extraSettings"
"description",
"extraSettings",
"options"
],
"properties": {
"id": {
Expand All @@ -295,21 +322,88 @@
"name": {
"type": "string"
},
"description": {
"type": "string"
},
"extraSettings": {
"anyOf": [
{
"type": "array",
"maxItems": 0
},
{
"$ref": "#/components/schemas/QuestionExtraSettings"
}
]
},
"options": {
"type": "array",
"nullable": true,
"items": {
"$ref": "#/components/schemas/Option"
}
},
"accept": {
"type": "array",
"nullable": true,
"items": {
"type": "string"
}
}
}
},
"QuestionExtraSettings": {
"type": "object",
"properties": {
"allowOtherAnswer": {
"type": "boolean",
"nullable": true
},
"extraSettings": {
"type": "object",
"additionalProperties": true
"allowedFileExtensions": {
"type": "array",
"nullable": true,
"items": {
"type": "string"
}
},
"allowedFileTypes": {
"type": "array",
"nullable": true,
"items": {
"type": "string"
}
},
"maxAllowedFilesCount": {
"type": "integer",
"format": "int64",
"nullable": true
},
"maxFileSize": {
"type": "integer",
"format": "int64",
"nullable": true
},
"optionsLimitMax": {
"type": "integer",
"format": "int64",
"nullable": true
},
"optionsLimitMin": {
"type": "integer",
"format": "int64",
"nullable": true
},
"shuffleOptions": {
"type": "boolean",
"nullable": true
},
"validationRegex": {
"type": "string",
"nullable": true
},
"validationType": {
"type": "string",
"nullable": true
}
}
},
Expand Down Expand Up @@ -342,7 +436,7 @@
"permissions": {
"type": "array",
"items": {
"type": "string"
"$ref": "#/components/schemas/Permission"
}
},
"displayName": {
Expand Down Expand Up @@ -3949,17 +4043,8 @@
"keyValuePairs": {
"type": "object",
"description": "Array of key=>value pairs to update.",
"required": [
"key",
"values"
],
"properties": {
"key": {
"type": "string"
},
"values": {
"type": "object"
}
"additionalProperties": {
"type": "object"
}
}
}
Expand Down

0 comments on commit 956342d

Please sign in to comment.