|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Fi\CoreBundle\DependencyInjection; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface as Container; |
|
6
|
|
|
use Fi\CoreBundle\Utils\PermessiSingletonUtility; |
|
7
|
|
|
|
|
8
|
|
|
/* |
|
9
|
|
|
* Se c'è l'accoppiata UTENTE + MODULO allora vale quel permesso |
|
10
|
|
|
* Se c'è l'accoppiata RUOLO + MODULO allora vale quel permesso |
|
11
|
|
|
* Altrimenti solo MODULO |
|
12
|
|
|
* Se non trovo informazioni di sorta, il modulo è chiuso |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
class GestionePermessi |
|
16
|
|
|
{ |
|
17
|
|
|
|
|
18
|
|
|
protected $modulo; |
|
19
|
|
|
protected $crud; |
|
20
|
|
|
private $container; |
|
21
|
|
|
|
|
22
|
18 |
|
public function __construct(Container $container) |
|
23
|
|
|
{ |
|
24
|
18 |
|
$this->container = $container; |
|
25
|
18 |
|
} |
|
26
|
|
|
|
|
27
|
16 |
|
private function presente($lettera) |
|
28
|
|
|
{ |
|
29
|
16 |
|
if (stripos($this->crud, $lettera) !== false) { |
|
30
|
15 |
|
return true; |
|
31
|
|
|
} else { |
|
32
|
2 |
|
return false; |
|
33
|
|
|
} |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
17 |
|
public function leggere($parametri = array()) |
|
37
|
|
|
{ |
|
38
|
17 |
|
if (!$this->container->get('security.token_storage')->getToken()) { |
|
39
|
1 |
|
return null; |
|
40
|
|
|
} |
|
41
|
16 |
|
if (isset($parametri['modulo'])) { |
|
42
|
16 |
|
$this->modulo = $parametri['modulo']; |
|
43
|
16 |
|
} |
|
44
|
|
|
|
|
45
|
16 |
|
$this->setCrud(); |
|
46
|
|
|
|
|
47
|
16 |
|
return $this->presente('R') || ($this->isSuperAdmin()); //SuperAdmin |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
16 |
|
public function cancellare($parametri = array()) |
|
51
|
|
|
{ |
|
52
|
16 |
|
if (!$this->container->get('security.token_storage')->getToken()) { |
|
53
|
1 |
|
return null; |
|
54
|
|
|
} |
|
55
|
15 |
|
if (isset($parametri['modulo'])) { |
|
56
|
15 |
|
$this->modulo = $parametri['modulo']; |
|
57
|
15 |
|
} |
|
58
|
15 |
|
$this->setCrud(); |
|
59
|
|
|
|
|
60
|
15 |
|
return $this->presente('D') || ($this->isSuperAdmin()); //SuperAdmin |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
16 |
|
public function creare($parametri = array()) |
|
64
|
|
|
{ |
|
65
|
16 |
|
if (!$this->container->get('security.token_storage')->getToken()) { |
|
66
|
1 |
|
return null; |
|
67
|
|
|
} |
|
68
|
15 |
|
if (isset($parametri['modulo'])) { |
|
69
|
15 |
|
$this->modulo = $parametri['modulo']; |
|
70
|
15 |
|
} |
|
71
|
15 |
|
$this->setCrud(); |
|
72
|
|
|
|
|
73
|
15 |
|
return $this->presente('C') || ($this->isSuperAdmin()); //SuperAdmin |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
16 |
|
public function aggiornare($parametri = array()) |
|
77
|
|
|
{ |
|
78
|
16 |
|
if (!$this->container->get('security.token_storage')->getToken()) { |
|
79
|
1 |
|
return null; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
15 |
|
if (isset($parametri['modulo'])) { |
|
83
|
15 |
|
$this->modulo = $parametri['modulo']; |
|
84
|
15 |
|
} |
|
85
|
15 |
|
$this->setCrud(); |
|
86
|
|
|
|
|
87
|
15 |
|
return $this->presente('U') || ($this->isSuperAdmin()); //SuperAdmin |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
2 |
|
private function isSuperAdmin() |
|
91
|
|
|
{ |
|
92
|
2 |
|
$utente = $this->container->get('security.token_storage')->getToken()->getUser()->getId(); |
|
93
|
2 |
|
$q = $this->container->get('doctrine') |
|
|
|
|
|
|
94
|
2 |
|
->getRepository('FiCoreBundle:Operatori') |
|
95
|
2 |
|
->find($utente); |
|
96
|
|
|
|
|
97
|
2 |
|
$isSuperAdmin = false; |
|
98
|
2 |
|
if ($q) { |
|
99
|
2 |
|
if ($q->getRuoli()) { |
|
100
|
2 |
|
$isSuperAdmin = $q->getRuoli()->isSuperadmin(); |
|
101
|
2 |
|
} |
|
102
|
2 |
|
} |
|
103
|
2 |
|
return $isSuperAdmin; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
public function sulmenu($parametri = array()) |
|
107
|
|
|
{ |
|
108
|
|
|
if (isset($parametri['modulo'])) { |
|
109
|
|
|
$this->modulo = $parametri['modulo']; |
|
110
|
|
|
} |
|
111
|
|
|
$permesso = $this->leggere($parametri) || |
|
112
|
|
|
$this->cancellare($parametri) || |
|
113
|
|
|
$this->creare($parametri) || |
|
114
|
|
|
$this->aggiornare($parametri); |
|
115
|
|
|
|
|
116
|
|
|
if ($permesso) { |
|
117
|
|
|
return true; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
return false; |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
16 |
|
public function setCrud($parametri = array()) |
|
124
|
|
|
{ |
|
125
|
16 |
|
if (isset($parametri['modulo'])) { |
|
126
|
|
|
$this->modulo = $parametri['modulo']; |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
16 |
|
$utentecorrente = $this->utentecorrente(); |
|
130
|
16 |
|
$q = PermessiSingletonUtility::instance( |
|
|
|
|
|
|
131
|
16 |
|
$this->container->get('doctrine'), |
|
132
|
16 |
|
$this->modulo, |
|
133
|
16 |
|
$utentecorrente["id"], |
|
|
|
|
|
|
134
|
16 |
|
$utentecorrente['ruolo_id'] |
|
135
|
16 |
|
)->getPermessi(); |
|
136
|
|
|
|
|
137
|
16 |
|
if ($q) { |
|
138
|
15 |
|
$this->crud = $q->getCrud(); |
|
139
|
15 |
|
return; |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
1 |
|
$this->crud = ''; |
|
143
|
1 |
|
} |
|
144
|
|
|
|
|
145
|
17 |
|
public function utentecorrente() |
|
146
|
|
|
{ |
|
147
|
17 |
|
$utentecorrente = array(); |
|
148
|
|
|
|
|
149
|
17 |
|
if (!$this->container->get('security.token_storage')->getToken()) { |
|
150
|
1 |
|
$utentecorrente['nome'] = 'Utente non registrato'; |
|
|
|
|
|
|
151
|
1 |
|
$utentecorrente['id'] = 0; |
|
|
|
|
|
|
152
|
1 |
|
$utentecorrente['ruolo_id'] = 0; |
|
153
|
|
|
|
|
154
|
1 |
|
return $utentecorrente; |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
16 |
|
$utente = $this->container->get('security.token_storage')->getToken()->getUser()->getId(); |
|
158
|
16 |
|
$q = $this->container->get('doctrine') |
|
|
|
|
|
|
159
|
16 |
|
->getRepository('FiCoreBundle:Operatori') |
|
160
|
16 |
|
->find($utente); |
|
161
|
|
|
|
|
162
|
16 |
|
$utentecorrente['username'] = $utente; |
|
163
|
16 |
|
$utentecorrente['codice'] = $utente; |
|
|
|
|
|
|
164
|
|
|
|
|
165
|
16 |
|
if (!$q) { |
|
166
|
|
|
$utentecorrente['nome'] = 'Utente non registrato'; |
|
|
|
|
|
|
167
|
|
|
$utentecorrente['id'] = 0; |
|
|
|
|
|
|
168
|
|
|
$utentecorrente['ruolo_id'] = 0; |
|
169
|
|
|
|
|
170
|
|
|
return $utentecorrente; |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
16 |
|
$utentecorrente['nome'] = $q->getOperatore(); |
|
|
|
|
|
|
174
|
16 |
|
$utentecorrente['id'] = $q->getId(); |
|
|
|
|
|
|
175
|
16 |
|
$utentecorrente['ruolo_id'] = ($q->getRuoli() ? $q->getRuoli()->getId() : 0); |
|
176
|
|
|
|
|
177
|
16 |
|
return $utentecorrente; |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
16 |
|
public function impostaPermessi($parametri = array()) |
|
181
|
|
|
{ |
|
182
|
16 |
|
$risposta = array(); |
|
183
|
|
|
|
|
184
|
16 |
|
$risposta['permessiedit'] = $this->aggiornare($parametri); |
|
|
|
|
|
|
185
|
16 |
|
$risposta['permessidelete'] = $this->cancellare($parametri); |
|
186
|
16 |
|
$risposta['permessicreate'] = $this->creare($parametri); |
|
187
|
16 |
|
$risposta['permessiread'] = $this->leggere($parametri); |
|
|
|
|
|
|
188
|
|
|
|
|
189
|
16 |
|
return $risposta; |
|
190
|
|
|
} |
|
191
|
|
|
} |
|
192
|
|
|
|
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.