Skip to content

Commit

Permalink
3.1.9
Browse files Browse the repository at this point in the history
WIP consistency in item quick buttons management
  • Loading branch information
root authored and root committed Dec 6, 2023
1 parent bc385d8 commit 3310968
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 105 deletions.
2 changes: 1 addition & 1 deletion includes/config/include.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
define('TP_VERSION', '3.1.0');
define("UPGRADE_MIN_DATE", "1697990713");
define('TP_VERSION_MINOR', '9');
define('TP_VERSION_MINOR', '10');
define('TP_TOOL_NAME', 'Teampass');
define('TP_ONE_DAY_SECONDS', 86400);
define('TP_ONE_WEEK_SECONDS', 604800);
Expand Down
9 changes: 8 additions & 1 deletion pages/items.js.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
itemStorageInformation = '',
applicationVars,
initialPageLoad = true,
previousSelectedFolder=-1,
previousSelectedFolder = -1,
debugJavascript = false;

// Manage memory
Expand Down Expand Up @@ -2272,6 +2272,9 @@ function(teampassUser) {
'<?php echo $lang->get('please_confirm_deletion'); ?>',
'<?php echo $lang->get('delete'); ?>',
'<?php echo $lang->get('close'); ?>',
false,
false,
false
);

// Launch deletion
Expand All @@ -2286,6 +2289,9 @@ function(teampassUser) {
);
$('#warningModal').modal('hide');
});
$(document).on('click', '#warningModalButtonClose', function() {
requestRunning = false;
});
});
});

Expand Down Expand Up @@ -4418,6 +4424,7 @@ function Details(itemDefinition, actionType, hotlink = false)
}
);
// Finished
requestRunning = false;
return false;
}

Expand Down
60 changes: 60 additions & 0 deletions scripts/background_tasks___functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
* @see https://www.teampass.net
*/

use TeampassClasses\NestedTree\NestedTree;
use TeampassClasses\SuperGlobal\SuperGlobal;

// Load config
require_once __DIR__.'/../includes/config/tp.config.php';
require_once __DIR__.'/../includes/config/include.php';
Expand Down Expand Up @@ -88,4 +91,61 @@ function doLog(string $status, string $job, int $enable_tasks_log = 0, int $id =
function provideLog(string $message, array $SETTINGS)
{
echo '\n' . (string) date($SETTINGS['date_format'] . ' ' . $SETTINGS['time_format'], time()) . ' - '.$message . '\n';
}

function performVisibleFoldersHtmlUpdate (int $user_id)
{
$html = [];

// rebuild tree
$tree = new NestedTree(prefixTable('nested_tree'), 'id', 'parent_id', 'title');
$tree->rebuild();

// get current folders visible for user
$cache_tree = DB::queryFirstRow(
'SELECT increment_id, data FROM ' . prefixTable('cache_tree') . ' WHERE user_id = %i',
$user_id
);
$folders = json_decode($cache_tree['data'], true);//print_r($folders);
foreach ($folders as $folder) {
$idFolder = (int) explode("li_", $folder['id'])[1];

// Get path
$path = '';
$tree_path = $tree->getPath($idFolder, false);
foreach ($tree_path as $fld) {
$path .= empty($path) === true ? $fld->title : '/'.$fld->title;
}

// get folder info
$folder = DB::queryFirstRow(
'SELECT title, parent_id, personal_folder FROM ' . prefixTable('nested_tree') . ' WHERE id = %i',
$idFolder
);

// finalize
array_push(
$html,
[
"path" => $path,
"id" => $idFolder,
"level" => count($tree_path),
"title" => $folder['title'],
"disabled" => 0,
"parent_id" => $folder['parent_id'],
"perso" => $folder['personal_folder'],
"is_visible_active" => 1,
]
);
}

DB::update(
prefixTable('cache_tree'),
array(
'visible_folders' => json_encode($html),
'timestamp' => time(),
),
'increment_id = %i',
(int) $cache_tree['increment_id']
);
}
60 changes: 1 addition & 59 deletions scripts/background_tasks___user_task.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,62 +105,4 @@
}

// log end
doLog('end', '', (isset($SETTINGS['enable_tasks_log']) === true ? (int) $SETTINGS['enable_tasks_log'] : 0), $logID);


function performVisibleFoldersHtmlUpdate (int $user_id)
{
$html = [];

// rebuild tree
$tree = new NestedTree(prefixTable('nested_tree'), 'id', 'parent_id', 'title');
$tree->rebuild();

// get current folders visible for user
$cache_tree = DB::queryFirstRow(
'SELECT increment_id, data FROM ' . prefixTable('cache_tree') . ' WHERE user_id = %i',
$user_id
);
$folders = json_decode($cache_tree['data'], true);//print_r($folders);
foreach ($folders as $folder) {
$idFolder = (int) explode("li_", $folder['id'])[1];

// Get path
$path = '';
$tree_path = $tree->getPath($idFolder, false);
foreach ($tree_path as $fld) {
$path .= empty($path) === true ? $fld->title : '/'.$fld->title;
}

// get folder info
$folder = DB::queryFirstRow(
'SELECT title, parent_id, personal_folder FROM ' . prefixTable('nested_tree') . ' WHERE id = %i',
$idFolder
);

// finalize
array_push(
$html,
[
"path" => $path,
"id" => $idFolder,
"level" => count($tree_path),
"title" => $folder['title'],
"disabled" => 0,
"parent_id" => $folder['parent_id'],
"perso" => $folder['personal_folder'],
"is_visible_active" => 1,
]
);
}

DB::update(
prefixTable('cache_tree'),
array(
'visible_folders' => json_encode($html),
'timestamp' => time(),
),
'increment_id = %i',
(int) $cache_tree['increment_id']
);
}
doLog('end', '', (isset($SETTINGS['enable_tasks_log']) === true ? (int) $SETTINGS['enable_tasks_log'] : 0), $logID);
4 changes: 2 additions & 2 deletions sources/export.queries.php
Original file line number Diff line number Diff line change
Expand Up @@ -612,9 +612,9 @@
<th>Label</th>
<th>Login</th>
<th>Password</th>
<th>URL</th>
<th>Description</th>
<th>Email</th>
<th>URL</th>
</tr>
</thead>
<tbody>';
Expand All @@ -635,9 +635,9 @@
<td>'.$record['label'].'</td>
<td>'.$record['login'].'</td>
<td>'.$record['pw'].'</td>
<td>'.$record['url'].'</td>
<td>'.$record['description'].'</td>
<td>'.$record['email'].'</td>
<td>'.$record['url'].'</td>
</tr>';
}
$html_table .= '
Expand Down
58 changes: 16 additions & 42 deletions sources/items.queries.php
Original file line number Diff line number Diff line change
Expand Up @@ -3270,6 +3270,17 @@
$filters,
$SETTINGS['cpassman_dir']
);

if (empty($inputData['itemId']) === true && (empty($inputData['itemKey']) === true || undefined($inputData['itemKey']) === true)) {
echo (string) prepareExchangedData(
array(
'error' => true,
'message' => $lang->get('nothing_to_do'),
),
'encode'
);
break;
}

// Check that user can access this item
$granted = accessToItemIsGranted($inputData['itemId'], $SETTINGS);
Expand Down Expand Up @@ -6938,7 +6949,7 @@
$inputData['data'],
'decode'
);

// prepare variables
$inputData['userId'] = (int) filter_var($dataReceived['userId'], FILTER_SANITIZE_NUMBER_INT);
$inputData['itemId'] = (int) filter_var($dataReceived['itemId'], FILTER_SANITIZE_NUMBER_INT);
Expand All @@ -6950,10 +6961,9 @@
$inputData['userId']
);
// Check if tree ID is in visible folders.
if (null !== $data['visible_folders']) {
$arr = json_decode($data['visible_folders'], true);
$ids = is_null($arr) === true ? [] : array_column($arr, 'id');
}
$arr = json_decode($data['visible_folders'], true);
$ids = is_null($arr) === true ? [] : array_column($arr, 'id');

// Check rights of this role on this folder
// Is there no edit or no delete defined
$data = DB::queryFirstColumn(
Expand All @@ -6963,43 +6973,7 @@
array_column($superGlobal->get('arr_roles', 'SESSION'), 'id'),
$inputData['treeId'],
);
$edit = $delete = true;
/*
//if ((int) $folder_is_personal === 0) {
$accessLevel = 20;
$arrTmp = [];
foreach ($data as $access) {
if ($access === 'R') {
array_push($arrTmp, 10);
} elseif ($access === 'W') {
array_push($arrTmp, 30);
} elseif (
$access === 'ND'
|| ($forceItemEditPrivilege === true && $access === 'NDNE')
) {
array_push($arrTmp, 20);
} elseif ($access === 'NE') {
array_push($arrTmp, 10);
} elseif ($access === 'NDNE') {
array_push($arrTmp, 15);
} else {
// Ensure to give access Right if allowed folder
if (in_array($inputData['id'], $_SESSION['groupes_visibles']) === true) {
array_push($arrTmp, 30);
} else {
array_push($arrTmp, 0);
}
}
}
// 3.0.0.0 - changed MIN to MAX
$accessLevel = count($arrTmp) > 0 ? max($arrTmp) : $accessLevel;
//} else {
// $accessLevel = 30;
//}
$uniqueLoadData['accessLevel'] = $accessLevel;
*/
//print_r($data);
$edit = $delete = true;
foreach ($data as $access) {
if ($access === 'ND') {
$delete = false;
Expand Down
1 change: 1 addition & 0 deletions sources/main.functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -3417,6 +3417,7 @@ function cacheTreeUserHandler(int $user_id, string $data, array $SETTINGS, strin
);

if (is_null($userCacheId) === true || count($userCacheId) === 0) {
// insert in table
DB::insert(
prefixTable('cache_tree'),
array(
Expand Down
15 changes: 15 additions & 0 deletions sources/tree.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,21 @@
$SETTINGS
);

// Add new process
DB::insert(
prefixTable('processes'),
array(
'created_at' => time(),
'process_type' => 'user_build_cache_tree',
'arguments' => json_encode([
'user_id' => (int) $inputData['userId'],
], JSON_HEX_QUOT | JSON_HEX_TAG),
'updated_at' => '',
'finished_at' => '',
'output' => '',
)
);

// Send back
echo $ret_json;
} else {
Expand Down

0 comments on commit 3310968

Please sign in to comment.