1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Oro\Bridge\CrmCall\Migrations\Data\ORM; |
4
|
|
|
|
5
|
|
|
use Doctrine\Common\DataFixtures\AbstractFixture; |
6
|
|
|
use Doctrine\Common\Persistence\ObjectManager; |
7
|
|
|
use Doctrine\Common\DataFixtures\DependentFixtureInterface; |
8
|
|
|
|
9
|
|
|
use Symfony\Component\DependencyInjection\ContainerAwareInterface; |
10
|
|
|
use Symfony\Component\DependencyInjection\ContainerAwareTrait; |
11
|
|
|
use Symfony\Component\Security\Acl\Model\SecurityIdentityInterface; |
12
|
|
|
use Symfony\Component\Yaml\Yaml; |
13
|
|
|
|
14
|
|
|
use Oro\Bundle\UserBundle\Entity\Role; |
15
|
|
|
use Oro\Bundle\SecurityBundle\Acl\Persistence\AclManager; |
16
|
|
|
|
17
|
|
|
class UpdateCallAccessLevels extends AbstractFixture implements DependentFixtureInterface, ContainerAwareInterface |
18
|
|
|
{ |
19
|
|
|
use ContainerAwareTrait; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* {@inheritdoc} |
23
|
|
|
*/ |
24
|
|
|
public function getDependencies() |
25
|
|
|
{ |
26
|
|
|
return [ |
27
|
|
|
'OroCRM\Bundle\DemoDataBundle\Migrations\Data\ORM\LoadRolesData' |
28
|
|
|
]; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Update call access levels |
33
|
|
|
* |
34
|
|
|
* @param ObjectManager $manager |
35
|
|
|
*/ |
36
|
|
|
public function load(ObjectManager $manager) |
37
|
|
|
{ |
38
|
|
|
if ($this->container->hasParameter('installed') && $this->container->getParameter('installed')) { |
39
|
|
|
return; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** @var AclManager $aclManager */ |
43
|
|
|
$aclManager = $this->container->get('oro_security.acl.manager'); |
44
|
|
|
|
45
|
|
|
$fileName = $this->container |
46
|
|
|
->get('kernel') |
47
|
|
|
->locateResource('@OroCRMCallBridgeBundle/Migrations/Data/ORM/CrmRoles/roles.yml'); |
48
|
|
|
|
49
|
|
|
$fileName = str_replace('/', DIRECTORY_SEPARATOR, $fileName); |
50
|
|
|
$rolesData = Yaml::parse(file_get_contents($fileName)); |
51
|
|
|
|
52
|
|
|
foreach ($rolesData as $roleName => $roleConfigData) { |
|
|
|
|
53
|
|
|
if (!array_key_exists('bap_role', $roleConfigData)) { |
54
|
|
|
continue; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
$role = $manager->getRepository('OroUserBundle:Role') |
58
|
|
|
->findOneBy(['role' => $roleConfigData['bap_role']]); |
59
|
|
|
|
60
|
|
View Code Duplication |
if ($aclManager->isAclEnabled()) { |
|
|
|
|
61
|
|
|
$sid = $aclManager->getSid($role); |
62
|
|
|
foreach ($roleConfigData['permissions'] as $permission => $acls) { |
63
|
|
|
$this->processPermission($aclManager, $sid, $permission, $acls); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
$aclManager->flush(); |
69
|
|
|
$manager->flush(); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @param AclManager $aclManager |
74
|
|
|
* @param SecurityIdentityInterface $sid |
75
|
|
|
* @param string $permission |
76
|
|
|
* @param array $acls |
77
|
|
|
*/ |
78
|
|
View Code Duplication |
protected function processPermission( |
|
|
|
|
79
|
|
|
AclManager $aclManager, |
80
|
|
|
SecurityIdentityInterface $sid, |
81
|
|
|
$permission, |
82
|
|
|
array $acls |
83
|
|
|
) { |
84
|
|
|
$oid = $aclManager->getOid(str_replace('|', ':', $permission)); |
85
|
|
|
|
86
|
|
|
$extension = $aclManager->getExtensionSelector()->select($oid); |
87
|
|
|
$maskBuilders = $extension->getAllMaskBuilders(); |
88
|
|
|
|
89
|
|
|
foreach ($maskBuilders as $maskBuilder) { |
90
|
|
|
$mask = $maskBuilder->reset()->get(); |
91
|
|
|
|
92
|
|
|
foreach ($acls as $acl) { |
93
|
|
|
if ($maskBuilder->hasMask('MASK_' . $acl)) { |
94
|
|
|
$mask = $maskBuilder->add($acl)->get(); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
$aclManager->setPermission($sid, $oid, $mask); |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.