|
4 | 4 |
|
5 | 5 | namespace Icinga\Module\Reporting\Web\Forms;
|
6 | 6 |
|
7 |
| -use Icinga\Authentication\Auth; |
| 7 | +use Icinga\Authentication\Auth as IcingaAuth; |
| 8 | +use Icinga\Module\Reporting\Common\Auth; |
8 | 9 | use Icinga\Module\Reporting\Database;
|
9 | 10 | use Icinga\Module\Reporting\ProvidedReports;
|
10 | 11 | use ipl\Html\Contract\FormSubmitElement;
|
11 | 12 | use ipl\Html\Form;
|
| 13 | +use ipl\Stdlib\Filter; |
12 | 14 | use ipl\Validator\CallbackValidator;
|
13 | 15 | use ipl\Web\Compat\CompatForm;
|
| 16 | +use ipl\Web\Filter\QueryString; |
14 | 17 |
|
15 | 18 | class ReportForm extends CompatForm
|
16 | 19 | {
|
| 20 | + use Auth; |
17 | 21 | use Database;
|
18 | 22 | use ProvidedReports;
|
19 | 23 |
|
@@ -89,6 +93,38 @@ protected function assemble()
|
89 | 93 | return false;
|
90 | 94 | }
|
91 | 95 |
|
| 96 | + $report = (object) [ |
| 97 | + 'report.name' => $value, |
| 98 | + 'report.author' => IcingaAuth::getInstance()->getUser()->getUsername() |
| 99 | + ]; |
| 100 | + |
| 101 | + $onCondition = function (Filter\Condition $condition) use (&$filterNames): void { |
| 102 | + if ($condition->getColumn() == 'report.name') { |
| 103 | + $filterNames[] = QueryString::getRuleSymbol($condition) . $condition->getValue(); |
| 104 | + } |
| 105 | + }; |
| 106 | + |
| 107 | + $restrictions = IcingaAuth::getInstance()->getRestrictions('reporting/reports'); |
| 108 | + $matched = false; |
| 109 | + $filterNames = []; |
| 110 | + foreach ($restrictions as $restriction) { |
| 111 | + $filter = $this->parseRestriction($restriction, 'reporting/reports', $onCondition); |
| 112 | + if (Filter::match($filter, $report)) { |
| 113 | + $matched = true; |
| 114 | + break; |
| 115 | + } |
| 116 | + } |
| 117 | + |
| 118 | + if (! empty($restrictions) && ! $matched) { |
| 119 | + $validator->addMessage(sprintf( |
| 120 | + $this->translate('Please use report names that conform to this restriction: %s%s'), |
| 121 | + 'name', |
| 122 | + implode(',', $filterNames) |
| 123 | + )); |
| 124 | + |
| 125 | + return false; |
| 126 | + } |
| 127 | + |
92 | 128 | return true;
|
93 | 129 | }
|
94 | 130 | ]
|
@@ -171,7 +207,7 @@ public function onSuccess()
|
171 | 207 | if ($this->id === null) {
|
172 | 208 | $db->insert('report', [
|
173 | 209 | 'name' => $values['name'],
|
174 |
| - 'author' => Auth::getInstance()->getUser()->getUsername(), |
| 210 | + 'author' => IcingaAuth::getInstance()->getUser()->getUsername(), |
175 | 211 | 'timeframe_id' => $values['timeframe'],
|
176 | 212 | 'template_id' => $values['template'],
|
177 | 213 | 'ctime' => $now,
|
|
0 commit comments