From: Marcin Haba Date: Thu, 7 Dec 2023 15:07:24 +0000 (+0100) Subject: baculum: Add job type parameter to objects overview endpoint X-Git-Tag: Beta-15.0.1~81 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c7f81cde12cf9bc5dad91f0a9f1a1250c49b2eed;p=thirdparty%2Fbacula.git baculum: Add job type parameter to objects overview endpoint --- diff --git a/gui/baculum/protected/API/Pages/API/ObjectsOverview.php b/gui/baculum/protected/API/Pages/API/ObjectsOverview.php index a24d18f90..c1759b096 100644 --- a/gui/baculum/protected/API/Pages/API/ObjectsOverview.php +++ b/gui/baculum/protected/API/Pages/API/ObjectsOverview.php @@ -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'][] = [ diff --git a/gui/baculum/protected/API/openapi_baculum.json b/gui/baculum/protected/API/openapi_baculum.json index 08ed975e6..cf8946a6d 100644 --- a/gui/baculum/protected/API/openapi_baculum.json +++ b/gui/baculum/protected/API/openapi_baculum.json @@ -9213,6 +9213,15 @@ "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", diff --git a/gui/baculum/protected/Common/Modules/Miscellaneous.php b/gui/baculum/protected/Common/Modules/Miscellaneous.php index 39d873fb0..35216c5f1 100644 --- a/gui/baculum/protected/Common/Modules/Miscellaneous.php +++ b/gui/baculum/protected/Common/Modules/Miscellaneous.php @@ -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); }