diff options
Diffstat (limited to 'modules-available/eventlog/pages/rules.inc.php')
-rw-r--r-- | modules-available/eventlog/pages/rules.inc.php | 38 |
1 files changed, 22 insertions, 16 deletions
diff --git a/modules-available/eventlog/pages/rules.inc.php b/modules-available/eventlog/pages/rules.inc.php index d60dcc07..6d240c73 100644 --- a/modules-available/eventlog/pages/rules.inc.php +++ b/modules-available/eventlog/pages/rules.inc.php @@ -101,6 +101,7 @@ class SubPage LEFT JOIN notification_rule_x_transport sfxb USING (ruleid) GROUP BY ruleid, title ORDER BY title, ruleid'); + Permission::addGlobalTags($data['perms'], null, ['filter.rules.edit']); Render::addTemplate('page-filters-rules', $data); } } @@ -112,8 +113,8 @@ class SubPage { // EDIT User::assertPermission('filter.rules.edit'); - $index = 0; - $existing = []; + $filterIdx = 0; + $knownIdxList = []; if ($id !== 0) { $data = Database::queryFirst('SELECT ruleid, title, type, datafilter, subject, message FROM notification_rule WHERE ruleid = :id', ['id' => $id]); @@ -121,21 +122,25 @@ class SubPage Message::addError('invalid-rule-id', $id); Util::redirect('?do=eventlog&show=rules'); } + if (Request::get('copy', false, 'bool')) { + $data['ruleid'] = 0; + $data['title'] = ''; + } $list = json_decode($data['datafilter'], true); if (!is_array($list['list'])) { $list['list'] = []; } foreach ($list['list'] as $item) { if (isset($item['index'])) { - $existing[] = $item['index']; + $knownIdxList[] = $item['index']; } } foreach ($list['list'] as &$item) { if (!isset($item['index'])) { - while (in_array($index, $existing)) { - $index++; + while (in_array($filterIdx, $knownIdxList)) { + $filterIdx++; } - $item['index'] = $index++; + $item['index'] = $filterIdx++; } $item['operators'] = []; foreach (self::OP_LIST as $op) { @@ -147,18 +152,9 @@ class SubPage } $data['filter'] = $list['list']; } else { + // New entry $data = ['filter' => [], 'ruleid' => 0]; } - // Add a few empty rows at the bottom - for ($i = 0; $i < 8; ++$i) { - while (in_array($index, $existing)) { - $index++; - } - $data['filter'][] = [ - 'index' => $index++, - 'operators' => array_map(function ($item) { return ['name' => $item]; }, self::OP_LIST), - ]; - } // Add suggestions for type $data['types'] = Database::queryColumnArray("SELECT DISTINCT type FROM notification_sample @@ -174,6 +170,16 @@ class SubPage // Filter keys to suggest for events with machineuuid in data $data['machine_keys'] = array_keys(FilterRuleProcessor::HW_QUERIES); } + // Add a few empty rows at the bottom + for ($i = 0; $i < 8; ++$i) { + while (in_array($filterIdx, $knownIdxList)) { + $filterIdx++; + } + $data['filter'][] = [ + 'index' => $filterIdx++, + 'operators' => array_map(function ($item) { return ['name' => $item]; }, self::OP_LIST), + ]; + } Render::addTemplate('page-filters-edit-rule', $data); } |