Skip to content

Commit cfa18a2

Browse files
committed
Fixing bugs in teampass:
- can not authentificate with json request - can not create item if it is in root folder - parent_id == 0 - can not create duplicate item if it is enabled and it is not personal folder - bug if creating first item - throwing exception
1 parent 6a580fa commit cfa18a2

File tree

4 files changed

+17
-12
lines changed

4 files changed

+17
-12
lines changed

api/Controller/Api/BaseController.php

+9-4
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,14 @@ public function getUriSegments()
5959
public function getQueryStringParams()
6060
{
6161
$request = symfonyRequest::createFromGlobals();
62-
$queryString = $request->getQueryString();
63-
parse_str(html_entity_decode($queryString), $query);
64-
return $this->sanitizeUrl($query);
62+
$queryString = $request->getQueryString();
63+
if ($request->getContentTypeFormat() != 'application/json') {
64+
parse_str(html_entity_decode($queryString), $query);
65+
return $this->sanitizeUrl($query);
66+
}
67+
68+
return $request->toArray();
69+
6570
}
6671

6772
/**
@@ -103,4 +108,4 @@ protected function sendOutput($data, $httpHeaders=array()): void
103108

104109
echo $data;
105110
}
106-
}
111+
}

api/Controller/Api/ItemController.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ private function checkNewItemData(array $arrQueryStringParams, array $userData):
132132
&& isset($arrQueryStringParams['anyone_can_modify']) === true
133133
) {
134134
//
135-
if (in_array($arrQueryStringParams['folder_id'], $userData['folders_list']) === false) {
135+
if (in_array($arrQueryStringParams['folder_id'], $userData['folders_list']) === false && $userData['user_can_create_root_folder'] === 0) {
136136
return [
137137
'error' => true,
138138
'strErrorDesc' => 'User is not allowed in this folder',
@@ -311,4 +311,4 @@ public function getAction(array $userData): void
311311
}
312312
}
313313
//end getAction()
314-
}
314+
}

api/Model/ItemModel.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,7 @@ private function checkForDuplicates(string $label, array $SETTINGS, array $itemI
342342
);
343343

344344
if (DB::count() > 0 && (
345-
(isset($SETTINGS['duplicate_item']) && (int) $SETTINGS['duplicate_item'] === 0)
346-
|| (int) $itemInfos['personal_folder'] === 0)
345+
(isset($SETTINGS['duplicate_item']) && (int) $SETTINGS['duplicate_item'] === 0))
347346
) {
348347
throw new Exception('Similar item already exists. Duplicates are not allowed.');
349348
}
@@ -495,4 +494,4 @@ private function isPasswordEmptyAllowed($password, $create_item_without_password
495494
}
496495
return false;
497496
}
498-
}
497+
}

sources/folders.class.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ public function createNewFolder(array $params): array
7373
}
7474

7575
if (!$this->isParentFolderAllowed($parent_id, $user_accessible_folders, $user_is_admin)) {
76-
return $this->errorResponse($this->lang->get('error_folder_not_allowed_for_this_user'));
76+
if ($parent_id != 0 && $user_can_create_root_folder == false )
77+
return $this->errorResponse($this->lang->get('error_folder_not_allowed_for_this_user'));
7778
}
7879

7980
if (!$this->checkDuplicateFolderAllowed($title) && $personal_folder == 0) {
@@ -350,7 +351,7 @@ private function updateUserFolderCache($tree, $title, $parent_id, $isPersonal, $
350351
if (empty($cache_tree)) {
351352
DB::insert(prefixTable('cache_tree'), [
352353
'user_id' => $user_id,
353-
'folders' => json_encode($newId),
354+
'folders' => json_encode([$newId,]),
354355
'visible_folders' => json_encode($new_json),
355356
'timestamp' => time(),
356357
'data' => '[{}]',
@@ -463,4 +464,4 @@ private function errorResponse($message, $newIdSuffix = "")
463464
'newId' => '' . $newIdSuffix,
464465
];
465466
}
466-
}
467+
}

0 commit comments

Comments
 (0)