Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Hartmann <[email protected]>
  • Loading branch information
Chartman123 committed Oct 28, 2024
1 parent cfcde6b commit 39fee3b
Show file tree
Hide file tree
Showing 4 changed files with 184 additions and 69 deletions.
8 changes: 4 additions & 4 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) {
// Set Order. ArrayKey counts from zero, order counts from 1.
$options[$arrayKey]->setOrder($arrayKey + 1);
$options[$arrayKey]->setOrder((int)$arrayKey + 1);
}
}

Expand Down Expand Up @@ -1112,7 +1112,7 @@ public function reorderOptions(int $formId, int $questionId, array $newOrder) {
* - `csv`: Comma-separated value
* - `ods`: OpenDocument Spreadsheet
* - `xlsx`: Excel Open XML Spreadsheet
* @return DataResponse<Http::STATUS_OK, FormsSubmissions, array{}>|DataDownloadResponse<Http::STATUS_OK, 'text/csv'|'application/vnd.oasis.opendocument.spreadsheet'|'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', array{}>
* @return DataResponse<Http::STATUS_OK, list<FormsSubmissions>, array{}>|DataDownloadResponse<Http::STATUS_OK, 'text/csv'|'application/vnd.oasis.opendocument.spreadsheet'|'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', array{}>
* @throws OCSNotFoundException Could not find form
* @throws OCSForbiddenException The current user has no permission to get the results for this form
*
Expand Down Expand Up @@ -1396,7 +1396,7 @@ public function exportSubmissionsToCloud(int $formId, string $path, string $file
* @param int $formId id of the form
* @param int $questionId id of the question
* @param string $shareHash hash of the form share
* @return DataResponse<Http::STATUS_OK, FormsUploadedFile, array{}>
* @return DataResponse<Http::STATUS_OK, list<FormsUploadedFile>, array{}>
* @throws OCSBadRequestException No files provided
* @throws OCSBadRequestException Question doesn't belong to the given form
* @throws OCSBadRequestException Invalid file provided
Expand Down
16 changes: 8 additions & 8 deletions lib/Controller/ShareApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ public function __construct(
* @param int $formId The form to share
* @param int $shareType Nextcloud-ShareType
* @param string $shareWith ID of user/group/... to share with. For Empty shareWith and shareType Link, this will be set as RandomID.
* @param array<string> $permissions the permissions granted on the share, defaults to `submit`
* Possible values:
* - `submit` user can submit
* - `results` user can see the results
* - `results_delete` user can see and delete results
* @return DataResponse<Http::STATUS_CREATED, FormsShare, array{}>
* @param list<string> $permissions the permissions granted on the share, defaults to `submit`
* Possible values:
* - `submit` user can submit
* - `results` user can see the results
* - `results_delete` user can see and delete results
* @return DataResponse<Http::STATUS_CREATED, array<FormsShare>, array{}>
* @throws OCSBadRequestException Invalid shareType
* @throws OCSBadRequestException Invalid permission given
* @throws OCSBadRequestException Invalid user to share with
Expand Down 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');
}
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 {
}
Loading

0 comments on commit 39fee3b

Please sign in to comment.