From: Marcin Haba Date: Wed, 11 Nov 2020 09:18:36 +0000 (+0100) Subject: baculum: Add path parameter to job files API endpoint X-Git-Tag: Release-9.6.7~22 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=77ed7edaea5d1ae9f87a61772587da4e5e5c7cf2;p=thirdparty%2Fbacula.git baculum: Add path parameter to job files API endpoint --- diff --git a/gui/baculum/protected/API/Class/JobManager.php b/gui/baculum/protected/API/Class/JobManager.php index 0bf804a03..274060f66 100644 --- a/gui/baculum/protected/API/Class/JobManager.php +++ b/gui/baculum/protected/API/Class/JobManager.php @@ -259,10 +259,11 @@ WHERE Client.ClientId='$clientid' $wh"; * @param string $clientid client identifier * @param string $filename filename without path * @param boolean $strict_mode if true then it maches exact filename, otherwise with % around filename + * @param string $path path to narrow results to one specific path * @param array $allowed_jobs jobs allowed to show * @return array jobs for specific client and filename */ - public function getJobsByFilename($clientid, $filename, $strict_mode = false, $allowed_jobs = array()) { + public function getJobsByFilename($clientid, $filename, $strict_mode = false, $path = '', $allowed_jobs = array()) { $jobs_criteria = ''; if (count($allowed_jobs) > 0) { $jobs_sql = implode("', '", $allowed_jobs); @@ -273,13 +274,18 @@ WHERE Client.ClientId='$clientid' $wh"; $filename = '%' . $filename . '%'; } + $path_criteria = ''; + if (!empty($path)) { + $path_criteria = ' AND Path.Path = :path '; + } + $fname_col = 'Path.Path || Filename.Name'; $db_params = $this->getModule('api_config')->getConfig('db'); if ($db_params['type'] === Database::MYSQL_TYPE) { $fname_col = 'CONCAT(Path.Path, Filename.Name)'; } - $sql = "SELECT Job.JobId AS JobId, + $sql = "SELECT Job.JobId AS jobid, Job.Name AS name, $fname_col AS file, Job.StartTime AS starttime, @@ -297,13 +303,17 @@ WHERE Client.ClientId='$clientid' $wh"; AND Path.PathId=File.PathId AND Filename.FilenameId=File.FilenameId AND Filename.Name LIKE :filename - $jobs_criteria - ORDER BY starttime DESC"; + $jobs_criteria + $path_criteria + ORDER BY starttime DESC"; $connection = JobRecord::finder()->getDbConnection(); $connection->setActive(true); $pdo = $connection->getPdoInstance(); $sth = $pdo->prepare($sql); $sth->bindParam(':filename', $filename, PDO::PARAM_STR, 200); + if (!empty($path)) { + $sth->bindParam(':path', $path, PDO::PARAM_STR, 400); + } $sth->execute(); return $sth->fetchAll(PDO::FETCH_ASSOC); } diff --git a/gui/baculum/protected/API/Pages/API/JobFiles.php b/gui/baculum/protected/API/Pages/API/JobFiles.php index 7fd5222f8..a9d9ce152 100644 --- a/gui/baculum/protected/API/Pages/API/JobFiles.php +++ b/gui/baculum/protected/API/Pages/API/JobFiles.php @@ -34,6 +34,7 @@ class JobFiles extends BaculumAPIServer { $misc = $this->getModule('misc'); $filename = $this->Request->contains('filename') && $misc->isValidFilename($this->Request['filename']) ? $this->Request['filename'] : null; $strict_mode = ($this->Request->contains('strict') && $misc->isValidBooleanTrue($this->Request['strict'])); + $path = $this->Request->contains('path') && $misc->isValidPath($this->Request['path']) ? $this->Request['path'] : ''; $clientid = null; if ($this->Request->contains('clientid')) { @@ -68,7 +69,7 @@ class JobFiles extends BaculumAPIServer { $this->output = []; $this->error = JobError::ERROR_NO_ERRORS; } else { - $job = $this->getModule('job')->getJobsByFilename($clientid, $filename, $strict_mode, $result->output); + $job = $this->getModule('job')->getJobsByFilename($clientid, $filename, $strict_mode, $path, $result->output); $this->output = $job; $this->error = JobError::ERROR_NO_ERRORS; } diff --git a/gui/baculum/protected/API/openapi_baculum.json b/gui/baculum/protected/API/openapi_baculum.json index 071c72ed7..452273382 100644 --- a/gui/baculum/protected/API/openapi_baculum.json +++ b/gui/baculum/protected/API/openapi_baculum.json @@ -1210,6 +1210,16 @@ "schema": { "type": "boolean" } + }, + { + "name": "path", + "in": "query", + "description": "Path to narrow down the results to files from one specific path. The path must be finished with a slash.", + "required": false, + "schema": { + "type": "string", + "maxLength": 400 + } } ] }