|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace ControleOnline\Service; |
|
4
|
|
|
|
|
5
|
|
|
use ControleOnline\Entity\People; |
|
6
|
|
|
use ControleOnline\Entity\PeopleDomain; |
|
7
|
|
|
use ControleOnline\Entity\PeopleLink; |
|
8
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
|
|
|
|
|
|
9
|
|
|
use Symfony\Component\Security\Core\Security; |
|
|
|
|
|
|
10
|
|
|
use App\Service\PeopleService; |
|
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
class PeopleRoleService |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* Entity Manager |
|
16
|
|
|
* |
|
17
|
|
|
* @var EntityManagerInterface |
|
18
|
|
|
*/ |
|
19
|
|
|
private $manager = null; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Security |
|
23
|
|
|
* |
|
24
|
|
|
* @var Security |
|
25
|
|
|
*/ |
|
26
|
|
|
private $security = null; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* People Service |
|
30
|
|
|
* |
|
31
|
|
|
* @var PeopleService |
|
32
|
|
|
*/ |
|
33
|
|
|
private $people = null; |
|
34
|
|
|
|
|
35
|
|
|
public function __construct( |
|
36
|
|
|
EntityManagerInterface $entityManager, |
|
37
|
|
|
Security $security, |
|
38
|
|
|
PeopleService $peopleService |
|
39
|
|
|
) { |
|
40
|
|
|
$this->manager = $entityManager; |
|
41
|
|
|
$this->security = $security; |
|
42
|
|
|
$this->people = $peopleService; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function isFranchisee(People $people): bool |
|
46
|
|
|
{ |
|
47
|
|
|
return in_array('franchisee', $this->getAllRoles($people)); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function isSuperAdmin(People $people): bool |
|
51
|
|
|
{ |
|
52
|
|
|
return in_array('super', $this->getAllRoles($people)); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function isSalesman(People $people): bool |
|
56
|
|
|
{ |
|
57
|
|
|
return in_array('salesman', $this->getAllRoles($people)); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
|
|
61
|
|
|
public function getAllRoles(People $people): array |
|
62
|
|
|
{ |
|
63
|
|
|
$peopleRole = []; |
|
64
|
|
|
$mainCompany = $this->getMainCompany(); |
|
65
|
|
|
|
|
66
|
|
|
$isSuper = $this->manager->getRepository(People::class)->getCompanyPeopleLinks($mainCompany, $people, 'employee', 1); |
|
67
|
|
|
if ($isSuper) |
|
68
|
|
|
$peopleRole[] = 'super'; |
|
69
|
|
|
|
|
70
|
|
|
|
|
71
|
|
|
|
|
72
|
|
|
$isFranchisee = $this->manager->getRepository(People::class)->getCompanyPeopleLinks($mainCompany, $people, 'franchisee', 1); |
|
73
|
|
|
if ($isFranchisee) { |
|
74
|
|
|
$peopleRole[] = 'franchisee'; |
|
75
|
|
|
$peopleRole[] = 'admin'; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
$isClient = $this->manager->getRepository(People::class)->getCompanyPeopleLinks($mainCompany, $people, 'client', 1); |
|
79
|
|
|
if ($isClient) |
|
80
|
|
|
$peopleRole[] = 'client'; |
|
81
|
|
|
|
|
82
|
|
|
|
|
83
|
|
|
$isSalesman = $this->manager->getRepository(People::class)->getCompanyPeopleLinks($mainCompany, $people, 'salesman', 1); |
|
84
|
|
|
if ($isSalesman) |
|
85
|
|
|
$peopleRole[] = 'salesman'; |
|
86
|
|
|
|
|
87
|
|
|
|
|
88
|
|
|
return array_values(array_unique(empty($peopleRole) ? ['guest'] : $peopleRole)); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* Retorna a people da empresa principal segundo o dominio da api |
|
93
|
|
|
* |
|
94
|
|
|
* @return People |
|
95
|
|
|
*/ |
|
96
|
|
|
public function getMainCompany(): People |
|
97
|
|
|
{ |
|
98
|
|
|
$domain = $_SERVER['HTTP_HOST']; |
|
99
|
|
|
$company = $this->manager->getRepository(PeopleDomain::class)->findOneBy(['domain' => $domain]); |
|
100
|
|
|
|
|
101
|
|
|
if ($company === null) |
|
102
|
|
|
throw new \Exception( |
|
103
|
|
|
sprintf('Main company "%s" not found', $domain) |
|
104
|
|
|
); |
|
105
|
|
|
|
|
106
|
|
|
return $company->getPeople(); |
|
107
|
|
|
} |
|
108
|
|
|
} |
|
109
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths