From 866521dbeccc03ebcdfd7c8ed0f1a5cc6442309a Mon Sep 17 00:00:00 2001 From: Marcin Haba Date: Thu, 18 Jan 2024 10:21:41 +0100 Subject: [PATCH] baculum: Add using multiple content values in filesets endpoint --- gui/baculum/protected/API/Modules/Database.php | 8 ++++++++ gui/baculum/protected/API/Pages/API/FileSets.php | 9 +++++++-- gui/baculum/protected/API/openapi_baculum.json | 2 +- gui/baculum/protected/Common/Modules/Miscellaneous.php | 4 ++++ 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/gui/baculum/protected/API/Modules/Database.php b/gui/baculum/protected/API/Modules/Database.php index 3397b9725..1275743fe 100644 --- a/gui/baculum/protected/API/Modules/Database.php +++ b/gui/baculum/protected/API/Modules/Database.php @@ -189,6 +189,14 @@ class Database extends APIModule { } $cond[] = "{$key} {$value[$i]['operator']} (" . implode(',', $tcond) . ')'; $value[$i]['operator'] = ''; + } elseif ($value[$i]['operator'] == 'LIKE') { + $tcond = []; + for ($j = 0; $j < count($value[$i]['vals']); $j++) { + $tcond[] = "{$key} {$value[$i]['operator']} :{$kval}{$i}{$j}"; + $vals[":{$kval}{$i}{$j}"] = $value[$i]['vals'][$j]; + } + $cond[] = implode(' OR ', $tcond); + $value[$i]['operator'] = ''; } else { // other operators for ($j = 0; $j < count($value[$i]['vals']); $j++) { diff --git a/gui/baculum/protected/API/Pages/API/FileSets.php b/gui/baculum/protected/API/Pages/API/FileSets.php index ffe5a3e28..cce2a2550 100644 --- a/gui/baculum/protected/API/Pages/API/FileSets.php +++ b/gui/baculum/protected/API/Pages/API/FileSets.php @@ -34,7 +34,7 @@ class FileSets extends BaculumAPIServer { public function get() { $misc = $this->getModule('misc'); - $content = $this->Request->contains('content') && $misc->isValidName($this->Request['content']) ? $this->Request['content'] : ''; + $content = $this->Request->contains('content') && $misc->isValidNameList($this->Request['content']) ? $this->Request['content'] : ''; $limit = $this->Request->contains('limit') && $misc->isValidInteger($this->Request['limit']) ? (int)$this->Request['limit'] : 0; $offset = $this->Request->contains('offset') && $misc->isValidInteger($this->Request['offset']) ? (int)$this->Request['offset'] : 0; $result = $this->getModule('bconsole')->bconsoleCommand( @@ -58,9 +58,14 @@ class FileSets extends BaculumAPIServer { ]; if (!empty($content)) { + $cnts = explode(',', $content); + $cb = function ($item) { + return ('%' . trim($item) . '%'); + }; + $cnts = array_map($cb, $cnts); $params['FileSet.Content'][] = [ 'operator' => 'LIKE', - 'vals' => '%' . $content . '%' + 'vals' => $cnts ]; } diff --git a/gui/baculum/protected/API/openapi_baculum.json b/gui/baculum/protected/API/openapi_baculum.json index 32a75a718..3b58d33f5 100644 --- a/gui/baculum/protected/API/openapi_baculum.json +++ b/gui/baculum/protected/API/openapi_baculum.json @@ -5594,7 +5594,7 @@ { "name": "content", "in": "query", - "description": "Content property value. There is possible to provide whole content value or only a part", + "description": "Content property value. There is possible to provide whole content value or only a part. Multiple comma separated values are allowed. Example: 'postgresql,file' value searches for filesets with postgresql OR file OR both.", "required": false, "schema": { "type": "string", diff --git a/gui/baculum/protected/Common/Modules/Miscellaneous.php b/gui/baculum/protected/Common/Modules/Miscellaneous.php index 229ad29c3..ce0cd337f 100644 --- a/gui/baculum/protected/Common/Modules/Miscellaneous.php +++ b/gui/baculum/protected/Common/Modules/Miscellaneous.php @@ -300,6 +300,10 @@ class Miscellaneous extends TModule { return (preg_match('/^[\d,]+$/', $list) === 1); } + public function isValidNameList($list) { + return (preg_match('/^[\w:\.\-\s,]+$/', $list) === 1); + } + public function isValidBvfsPath($path) { return (preg_match('/^b2\d+$/', $path) === 1); } -- 2.47.3