From efbeaeef564111edfd9984efde87a17581a46719 Mon Sep 17 00:00:00 2001 From: Marcin Haba Date: Thu, 9 Aug 2018 21:56:39 +0200 Subject: [PATCH] baculum: Add type and level filters to jobs endpoint --- gui/baculum/protected/API/Pages/API/Jobs.php | 12 +++++++++++- gui/baculum/protected/Common/Class/Miscellaneous.php | 6 +++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/gui/baculum/protected/API/Pages/API/Jobs.php b/gui/baculum/protected/API/Pages/API/Jobs.php index f5960caea..e49af8194 100644 --- a/gui/baculum/protected/API/Pages/API/Jobs.php +++ b/gui/baculum/protected/API/Pages/API/Jobs.php @@ -22,9 +22,11 @@ class Jobs extends BaculumAPIServer { public function get() { + $misc = $this->getModule('misc'); $limit = $this->Request->contains('limit') ? intval($this->Request['limit']) : 0; $jobstatus = $this->Request->contains('jobstatus') ? $this->Request['jobstatus'] : ''; - $misc = $this->getModule('misc'); + $level = $this->Request->contains('level') && $misc->isValidJobLevel($this->Request['level']) ? $this->Request['level'] : ''; + $type = $this->Request->contains('type') && $misc->isValidJobType($this->Request['type']) ? $this->Request['type'] : ''; $jobname = $this->Request->contains('name') && $misc->isValidName($this->Request['name']) ? $this->Request['name'] : ''; $clientid = $this->Request->contains('clientid') ? $this->Request['clientid'] : ''; if (!empty($clientid) && !$misc->isValidId($clientid)) { @@ -49,6 +51,14 @@ class Jobs extends BaculumAPIServer { $params['jobstatus']['vals'][] = $sts[$i]; } } + if (!empty($level)) { + $params['level']['operator'] = ''; + $params['level']['vals'] = $level; + } + if (!empty($type)) { + $params['type']['operator'] = ''; + $params['type']['vals'] = $type; + } $allowed = array(); $result = $this->getModule('bconsole')->bconsoleCommand($this->director, array('.jobs')); if ($result->exitcode === 0) { diff --git a/gui/baculum/protected/Common/Class/Miscellaneous.php b/gui/baculum/protected/Common/Class/Miscellaneous.php index 0c907c25f..7cfe15b27 100644 --- a/gui/baculum/protected/Common/Class/Miscellaneous.php +++ b/gui/baculum/protected/Common/Class/Miscellaneous.php @@ -183,7 +183,11 @@ class Miscellaneous extends TModule { * @TODO: Move it to separate validation module. */ public function isValidJobLevel($jobLevel) { - return array_key_exists($jobLevel, $this->getJobLevels()); + return key_exists($jobLevel, $this->getJobLevels()); + } + + public function isValidJobType($job_type) { + return key_exists($job_type, $this->job_types); } public function isValidName($name) { -- 2.47.3