|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace ControleOnline\Controller; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\Security\Core\Security; |
|
|
|
|
|
|
6
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse; |
|
|
|
|
|
|
7
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
|
|
|
|
|
8
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
|
|
|
|
|
|
9
|
|
|
|
|
10
|
|
|
use ControleOnline\Entity\Config; |
|
|
|
|
|
|
11
|
|
|
use ControleOnline\Entity\People; |
|
12
|
|
|
use ControleOnline\Entity\PeopleDomain; |
|
13
|
|
|
use ControleOnline\Service\DomainService; |
|
|
|
|
|
|
14
|
|
|
use ControleOnline\Service\PeopleRoleService; |
|
15
|
|
|
|
|
16
|
|
|
class GetDefaultCompanyAction |
|
17
|
|
|
{ |
|
18
|
|
|
/* |
|
19
|
|
|
* @var Security |
|
20
|
|
|
*/ |
|
21
|
|
|
private $security; |
|
22
|
|
|
private $em = null; |
|
23
|
|
|
private $roles; |
|
24
|
|
|
private $domain; |
|
25
|
|
|
private $company; |
|
26
|
|
|
|
|
27
|
|
|
public function __construct( |
|
28
|
|
|
Security $security, |
|
29
|
|
|
EntityManagerInterface $entityManager, |
|
30
|
|
|
PeopleRoleService $roles, |
|
31
|
|
|
private DomainService $domainService |
|
32
|
|
|
) { |
|
33
|
|
|
$this->security = $security; |
|
34
|
|
|
$this->em = $entityManager; |
|
35
|
|
|
$this->roles = $roles; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function __invoke( |
|
39
|
|
|
Request $request |
|
40
|
|
|
): JsonResponse { |
|
41
|
|
|
|
|
42
|
|
|
try { |
|
43
|
|
|
|
|
44
|
|
|
$this->domain = $this->domainService->getDomain(); |
|
45
|
|
|
$this->getCompany(); |
|
46
|
|
|
|
|
47
|
|
|
$defaultCompany = []; |
|
48
|
|
|
$configs = []; |
|
49
|
|
|
$allConfigs = []; |
|
|
|
|
|
|
50
|
|
|
$user = $this->security->getUser(); |
|
51
|
|
|
|
|
52
|
|
|
$permissions = $user ? $this->roles->getAllRoles($user->getPeople()) : ['guest']; |
|
53
|
|
|
|
|
54
|
|
|
if ($this->company) { |
|
55
|
|
|
$allConfigs = $this->em->getRepository(Config::class)->findBy([ |
|
56
|
|
|
'people' => $this->company->getPeople()->getId(), |
|
57
|
|
|
'visibility' => 'public' |
|
58
|
|
|
]); |
|
59
|
|
|
|
|
60
|
|
|
foreach ($allConfigs as $config) { |
|
61
|
|
|
$configs[$config->getConfigKey()] = $config->getConfigValue(); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
$defaultCompany = [ |
|
65
|
|
|
'id' => $this->company->getPeople()->getId(), |
|
66
|
|
|
'alias' => $this->company->getPeople()->getAlias(), |
|
67
|
|
|
'configs' => $configs, |
|
68
|
|
|
'domainType' => $this->company->getDomainType(), |
|
69
|
|
|
'permissions' => $permissions, |
|
70
|
|
|
'theme' => $this->getTheme(), |
|
71
|
|
|
'logo' => $this->company->getPeople()->getFile() ? [ |
|
72
|
|
|
'id' => $this->company->getPeople()->getFile()->getId(), |
|
73
|
|
|
'domain' => $this->domainService->getMainDomain(), |
|
74
|
|
|
'url' => '/files/download/' . $this->company->getPeople()->getFile()->getId() |
|
75
|
|
|
] : null, |
|
76
|
|
|
]; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
return new JsonResponse([ |
|
80
|
|
|
'response' => [ |
|
81
|
|
|
'data' => $defaultCompany, |
|
82
|
|
|
'count' => 1, |
|
83
|
|
|
'error' => '', |
|
84
|
|
|
'success' => true |
|
85
|
|
|
], |
|
86
|
|
|
]); |
|
87
|
|
|
} catch (\Exception $e) { |
|
88
|
|
|
|
|
89
|
|
|
return new JsonResponse([ |
|
90
|
|
|
'response' => [ |
|
91
|
|
|
'data' => [], |
|
92
|
|
|
'count' => 0, |
|
93
|
|
|
'error' => $e->getMessage(), |
|
94
|
|
|
'success' => false, |
|
95
|
|
|
], |
|
96
|
|
|
]); |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
private function getCompany() |
|
100
|
|
|
{ |
|
101
|
|
|
$this->company = $this->em->getRepository(PeopleDomain::class)->findOneBy(['domain' => $this->domain]); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
private function getTheme() |
|
105
|
|
|
{ |
|
106
|
|
|
return [ |
|
107
|
|
|
'theme' => $this->company->getTheme()->getTheme(), |
|
108
|
|
|
'colors' => $this->company->getTheme()->getColors(), |
|
109
|
|
|
'background' => $this->company->getTheme()->getBackground() ? [ |
|
110
|
|
|
'id' => $this->company->getTheme()->getBackground(), |
|
111
|
|
|
'domain' => $this->domainService->getMainDomain(), |
|
112
|
|
|
'url' => '/files/download/' . $this->company->getTheme()->getBackground() |
|
113
|
|
|
] : null, |
|
114
|
|
|
]; |
|
115
|
|
|
} |
|
116
|
|
|
} |
|
117
|
|
|
|
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