]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
baculum: Add path parameter to job files API endpoint
authorMarcin Haba <marcin.haba@bacula.pl>
Wed, 11 Nov 2020 09:18:36 +0000 (10:18 +0100)
committerMarcin Haba <marcin.haba@bacula.pl>
Wed, 11 Nov 2020 09:18:36 +0000 (10:18 +0100)
gui/baculum/protected/API/Class/JobManager.php
gui/baculum/protected/API/Pages/API/JobFiles.php
gui/baculum/protected/API/openapi_baculum.json

index 0bf804a03963f4371f01e27c11ffe5c31b04b5cc..274060f66d6eed138092242646f0353d3c883ffd 100644 (file)
@@ -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);
        }
index 7fd5222f8d1d654073c87fe2f2569295663ea908..a9d9ce1529e1fa777bfa99c93ff7cca94d782246 100644 (file)
@@ -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;
                        }
index 071c72ed7622ae7ed685deec9dca802aed2bb46e..4522733826d445b80ec7fb73378af2cf174d6d02 100644 (file)
                                                "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
+                                               }
                                        }
                                ]
                        }