]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
baculum: Add job type parameter to objects overview endpoint
authorMarcin Haba <marcin.haba@bacula.pl>
Thu, 7 Dec 2023 15:07:24 +0000 (16:07 +0100)
committerMarcin Haba <marcin.haba@bacula.pl>
Thu, 18 Jan 2024 09:22:37 +0000 (10:22 +0100)
gui/baculum/protected/API/Pages/API/ObjectsOverview.php
gui/baculum/protected/API/openapi_baculum.json
gui/baculum/protected/Common/Modules/Miscellaneous.php

index a24d18f904d04cf38a7eef5993dfdeb2f84e364c..c1759b096af12bc7fb3e70b6117ddd0fe43c1c41 100644 (file)
@@ -37,6 +37,7 @@ class ObjectsOverview extends BaculumAPIServer {
                $misc = $this->getModule('misc');
                $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;
+               $jobtype = $this->Request->contains('type') && $misc->areValidJobTypes($this->Request['type']) ? $this->Request['type'] : null;
                $objecttype = $this->Request->contains('objecttype') && $misc->isValidName($this->Request['objecttype']) ? $this->Request['objecttype'] : null;
                $objectname = $this->Request->contains('objectname') && $misc->isValidNameExt($this->Request['objectname']) ? $this->Request['objectname'] : null;
                $objectcategory = $this->Request->contains('objectcategory') && $misc->isValidName($this->Request['objectcategory']) ? $this->Request['objectcategory'] : null;
@@ -128,6 +129,13 @@ class ObjectsOverview extends BaculumAPIServer {
                                'vals' => $objectstatus
                        ];
                }
+               if (!empty($jobtype)) {
+                       $general_params['Job.Type'] = [];
+                       $general_params['Job.Type'][] = [
+                               'operator' => 'IN',
+                               'vals' => str_split($jobtype),
+                       ];
+               }
                if (!empty($jobname)) {
                        $general_params['Job.Name'] = [];
                        $general_params['Job.Name'][] = [
index 08ed975e68198ec73fe84494d5f8a13adbb43381..cf8946a6df74fec194eff247bc18ecb36afd35d9 100644 (file)
                                                        "type": "string"
                                                }
                                        },
+                                       {
+                                               "name": "type",
+                                               "in": "query",
+                                               "required": false,
+                                               "description": "Job type letter. Possible multiple values like: BCg or Ccg",
+                                               "schema": {
+                                                       "type": "string"
+                                               }
+                                       },
                                        {
                                                "name": "jobids",
                                                "in": "query",
index 39d873fb037bb75771e8dc1b777610ea702229fd..35216c5f12404b8c903808b1062466ae5f4d30ce 100644 (file)
@@ -226,6 +226,24 @@ class Miscellaneous extends TModule {
                return key_exists($job_type, $this->job_types);
        }
 
+       /**
+        * Validate more than one job type.
+        *
+        * @param string $job_types job types ex. 'BCg'
+        * @return true if all provided job types are valid, otherwise false
+        */
+       public function areValidJobTypes($job_types) {
+               $types = str_split($job_types);
+               $valid = true;
+               for ($i = 0; $i < count($types); $i++) {
+                       if (!$this->isValidJobType($types[$i])) {
+                               $valid = false;
+                               break;
+                       }
+               }
+               return $valid;
+       }
+
        public function isValidName($name) {
                return (preg_match('/^[\w:\.\-\s]{1,127}$/', $name) === 1);
        }