Skip to content

Commit e85946c

Browse files
Merge pull request #4469 from nilsteampassnet/code_review
Code review
2 parents fa2d565 + 33c9f7b commit e85946c

20 files changed

+1052
-621
lines changed

api/Model/ItemModel.php

-1
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,6 @@ private function handlePostInsertTasks(
443443
storeUsersShareKey(
444444
prefixTable('sharekeys_items'),
445445
(int) $itemInfos['personal_folder'],
446-
(int) $folderId,
447446
(int) $newID,
448447
$passwordKey,
449448
true,

composer.json

+1
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@
149149
"teampassclasses/oauth2controller": "dev-master",
150150
"teampassclasses/configmanager": "dev-master",
151151
"teampassclasses/emailservice": "dev-master",
152+
"teampassclasses/FolderServices": "dev-master",
152153
"illuminate/contracts": "^10.32",
153154
"illuminate/collections": "^10.48",
154155
"nesbot/carbon": "^2.71",

includes/config/include.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
define('TP_VERSION', '3.1.2');
3030
define("UPGRADE_MIN_DATE", "1731422875");
31-
define('TP_VERSION_MINOR', '157');
31+
define('TP_VERSION_MINOR', '166');
3232
define('TP_TOOL_NAME', 'Teampass');
3333
define('TP_ONE_DAY_SECONDS', 86400);
3434
define('TP_ONE_WEEK_SECONDS', 604800);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "teampassclasses/folderservices",
3+
"description": "Handle the folder management.",
4+
"type": "library",
5+
"license": "GPL-3.0-only",
6+
"keywords": [
7+
"folder"
8+
],
9+
"authors": [
10+
{
11+
"name": "Nils Laumaillé"
12+
}
13+
],
14+
"require": {
15+
"php": "^8.1"
16+
},
17+
"autoload": {
18+
"psr-4": {
19+
"TeampassClasses\\FolderServices\\": "src/"
20+
}
21+
}
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
namespace TeampassClasses\FolderServices;
3+
4+
/**
5+
* Teampass - a collaborative passwords manager.
6+
* ---
7+
* This file is part of the TeamPass project.
8+
*
9+
* TeamPass is free software: you can redistribute it and/or modify it
10+
* under the terms of the GNU General Public License as published by
11+
* the Free Software Foundation, version 3 of the License.
12+
*
13+
* TeamPass is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU General Public License
19+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
20+
*
21+
* Certain components of this file may be under different licenses. For
22+
* details, see the `licenses` directory or individual file headers.
23+
* ---
24+
* @file FolderCacheUpdater.php
25+
* @author Nils Laumaillé (nils@teampass.net)
26+
* @copyright 2009-2024 Teampass.net
27+
* @license GPL-3.0
28+
* @see https://www.teampass.net
29+
*/
30+
31+
class FolderCacheUpdater
32+
{
33+
public function updateCacheForFolder(int $folderId, array $params)
34+
{
35+
// Logic to update the folder cache goes here
36+
}
37+
38+
public function refreshUserCache(int $userId)
39+
{
40+
// Logic to refresh cache for a specific user
41+
}
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
namespace TeampassClasses\FolderServices;
3+
4+
/**
5+
* Teampass - a collaborative passwords manager.
6+
* ---
7+
* This file is part of the TeamPass project.
8+
*
9+
* TeamPass is free software: you can redistribute it and/or modify it
10+
* under the terms of the GNU General Public License as published by
11+
* the Free Software Foundation, version 3 of the License.
12+
*
13+
* TeamPass is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU General Public License
19+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
20+
*
21+
* Certain components of this file may be under different licenses. For
22+
* details, see the `licenses` directory or individual file headers.
23+
* ---
24+
* @file FolderComplexityService.php
25+
* @author Nils Laumaillé (nils@teampass.net)
26+
* @copyright 2009-2024 Teampass.net
27+
* @license GPL-3.0
28+
* @see https://www.teampass.net
29+
*/
30+
31+
use DB;
32+
33+
class FolderComplexityService
34+
{
35+
public function checkComplexityLevel(int $folderId, int $complexity): bool
36+
{
37+
$parentComplexity = DB::queryFirstField('SELECT valeur FROM complexity_levels WHERE folder_id = %i', $folderId);
38+
return $complexity >= $parentComplexity;
39+
}
40+
41+
public function addComplexity(int $folderId, int $complexity)
42+
{
43+
DB::insert(prefixTable('misc'), [
44+
'type' => 'complex',
45+
'intitule' => $folderId,
46+
'valeur' => $complexity,
47+
'created_at' => time(),
48+
]);
49+
}
50+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
namespace TeampassClasses\FolderServices;
3+
4+
/**
5+
* Teampass - a collaborative passwords manager.
6+
* ---
7+
* This file is part of the TeamPass project.
8+
*
9+
* TeamPass is free software: you can redistribute it and/or modify it
10+
* under the terms of the GNU General Public License as published by
11+
* the Free Software Foundation, version 3 of the License.
12+
*
13+
* TeamPass is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU General Public License
19+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
20+
*
21+
* Certain components of this file may be under different licenses. For
22+
* details, see the `licenses` directory or individual file headers.
23+
* ---
24+
* @file FolderCreationService.php
25+
* @author Nils Laumaillé (nils@teampass.net)
26+
* @copyright 2009-2024 Teampass.net
27+
* @license GPL-3.0
28+
* @see https://www.teampass.net
29+
*/
30+
31+
use DB;
32+
33+
class FolderCreationService
34+
{
35+
private $lang;
36+
private $settings;
37+
38+
public function __construct($lang, $settings)
39+
{
40+
$this->lang = $lang;
41+
$this->settings = $settings;
42+
}
43+
44+
public function validateFolderParameters(array $params): array
45+
{
46+
if (is_numeric($params['title'])) {
47+
return ['error' => true, 'message' => $this->lang->get('error_only_numbers_in_folder_name')];
48+
}
49+
return ['error' => false];
50+
}
51+
52+
public function createFolder(array $params): int
53+
{
54+
DB::insert(prefixTable('nested_tree'), [
55+
'parent_id' => $params['parent_id'],
56+
'title' => $params['title'],
57+
'personal_folder' => $params['personal_folder'] ?? 0,
58+
]);
59+
return DB::insertId();
60+
}
61+
62+
public function finalizeCreation(int $newId, array $params)
63+
{
64+
// Add any additional steps needed to finalize the folder creation
65+
}
66+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
namespace TeampassClasses\FolderServices;
3+
4+
/**
5+
* Teampass - a collaborative passwords manager.
6+
* ---
7+
* This file is part of the TeamPass project.
8+
*
9+
* TeamPass is free software: you can redistribute it and/or modify it
10+
* under the terms of the GNU General Public License as published by
11+
* the Free Software Foundation, version 3 of the License.
12+
*
13+
* TeamPass is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU General Public License
19+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
20+
*
21+
* Certain components of this file may be under different licenses. For
22+
* details, see the `licenses` directory or individual file headers.
23+
* ---
24+
* @file FolderPermissionChecker.php
25+
* @author Nils Laumaillé (nils@teampass.net)
26+
* @copyright 2009-2024 Teampass.net
27+
* @license GPL-3.0
28+
* @see https://www.teampass.net
29+
*/
30+
31+
32+
use DB;
33+
34+
class FolderPermissionChecker
35+
{
36+
public function isUserAllowedToCreate(int $userId, int $parentId, bool $isAdmin): bool
37+
{
38+
if ($isAdmin) {
39+
return true;
40+
}
41+
$accessibleFolders = $this->getUserAccessibleFolders($userId);
42+
return in_array($parentId, $accessibleFolders);
43+
}
44+
45+
private function getUserAccessibleFolders(int $userId): array
46+
{
47+
return DB::queryFirstColumn('SELECT folder_id FROM accessible_folders WHERE user_id = %i', $userId);
48+
}
49+
}

0 commit comments

Comments
 (0)