blob: 5ccdf062a59a4d97a7158ca35ddc1b0a45cc0613 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
<?php
namespace Icinga\Module\Businessprocess\Web\Form;
use Icinga\Application\Config;
use Icinga\Application\Icinga;
use Icinga\Authentication\Auth;
use Icinga\Module\Businessprocess\BpConfig;
use Icinga\Module\Businessprocess\Storage\Storage;
use Icinga\Module\Monitoring\Backend\MonitoringBackend;
use Icinga\Web\Session\SessionNamespace;
use ipl\Sql\Connection as IcingaDbConnection;
abstract class BpConfigBaseForm extends QuickForm
{
/** @var Storage */
protected $storage;
/** @var BpConfig */
protected $bp;
/** @var MonitoringBackend|IcingaDbConnection*/
protected $backend;
/** @var SessionNamespace */
protected $session;
protected function listAvailableBackends()
{
$keys = [];
$moduleManager = Icinga::app()->getModuleManager();
if ($moduleManager->hasEnabled('monitoring')) {
$keys = array_keys(Config::module('monitoring', 'backends')->toArray());
$keys = array_combine($keys, $keys);
}
return $keys;
}
/**
* Set the storage to use
*
* @param Storage $storage
*
* @return $this
*/
public function setStorage(Storage $storage): self
{
$this->storage = $storage;
return $this;
}
/**
* Set the config to use
*
* @param BpConfig $config
*
* @return $this
*/
public function setProcess(BpConfig $config): self
{
$this->bp = $config;
$this->setBackend($config->getBackend());
return $this;
}
/**
* Set the backend to use
*
* @param MonitoringBackend|IcingaDbConnection $backend
*
* @return $this
*/
public function setBackend($backend): self
{
$this->backend = $backend;
return $this;
}
/**
* Set the session namespace to use
*
* @param SessionNamespace $session
*
* @return $this
*/
public function setSession(SessionNamespace $session): self
{
$this->session = $session;
return $this;
}
protected function prepareMetadata(BpConfig $config)
{
$meta = $config->getMetadata();
$auth = Auth::getInstance();
$meta->set('Owner', $auth->getUser()->getUsername());
if ($auth->hasPermission('businessprocess/showall')) {
return true;
}
$prefixes = $auth->getRestrictions('businessprocess/prefix');
if (! empty($prefixes) && ! $meta->nameIsPrefixedWithOneOf($prefixes)) {
if (count($prefixes) === 1) {
$this->getElement('name')->addError(sprintf(
$this->translate('Please prefix the name with "%s"'),
current($prefixes)
));
} else {
$this->getElement('name')->addError(sprintf(
$this->translate('Please prefix the name with one of "%s"'),
implode('", "', $prefixes)
));
}
return false;
}
return true;
}
protected function setPreferredDecorators()
{
parent::setPreferredDecorators();
$this->setAttrib('class', $this->getAttrib('class') . ' bp-form');
return $this;
}
}
|