DigitalState /
Identities
| 1 | <?php |
||
| 2 | |||
| 3 | namespace App\Service; |
||
| 4 | |||
| 5 | use App\Entity\Role; |
||
| 6 | use Doctrine\ORM\EntityManagerInterface; |
||
|
0 ignored issues
–
show
|
|||
| 7 | use Ds\Component\Api\Api\Api; |
||
|
0 ignored issues
–
show
The type
Ds\Component\Api\Api\Api was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 8 | use Ds\Component\Api\Model\Access; |
||
|
0 ignored issues
–
show
The type
Ds\Component\Api\Model\Access was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 9 | use Ds\Component\Api\Model\Permission; |
||
|
0 ignored issues
–
show
The type
Ds\Component\Api\Model\Permission was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 10 | use Ds\Component\Api\Model\Scope; |
||
|
0 ignored issues
–
show
The type
Ds\Component\Api\Model\Scope was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 11 | use Ds\Component\Api\Query\AccessParameters; |
||
|
0 ignored issues
–
show
The type
Ds\Component\Api\Query\AccessParameters was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 12 | use Ds\Component\Discovery\Repository\ServiceRepository; |
||
|
0 ignored issues
–
show
The type
Ds\Component\Discovery\R...itory\ServiceRepository was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 13 | use Ds\Component\Entity\Service\EntityService; |
||
|
0 ignored issues
–
show
The type
Ds\Component\Entity\Service\EntityService was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 14 | use LogicException; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * Class RoleService |
||
| 18 | */ |
||
| 19 | final class RoleService extends EntityService |
||
| 20 | { |
||
| 21 | /** |
||
| 22 | * @var \Ds\Component\Api\Api\Api |
||
| 23 | */ |
||
| 24 | private $api; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @var \Ds\Component\Discovery\Repository\ServiceRepository |
||
| 28 | */ |
||
| 29 | private $serviceRepository; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @var string |
||
| 33 | */ |
||
| 34 | private $namespace; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Constructor |
||
| 38 | * |
||
| 39 | * @param \Doctrine\ORM\EntityManagerInterface $manager |
||
| 40 | * @param \Ds\Component\Api\Api\Api $api |
||
| 41 | * @param \Ds\Component\Discovery\Repository\ServiceRepository $serviceRepository |
||
| 42 | * @param string $namespace |
||
| 43 | * @param string $entity |
||
| 44 | */ |
||
| 45 | public function __construct(EntityManagerInterface $manager, Api $api, ServiceRepository $serviceRepository, string $namespace = 'ds', string $entity = Role::class) |
||
| 46 | { |
||
| 47 | parent::__construct($manager, $entity); |
||
| 48 | $this->api = $api; |
||
| 49 | $this->serviceRepository = $serviceRepository; |
||
| 50 | $this->namespace = $namespace; |
||
| 51 | } |
||
| 52 | |||
| 53 | /** |
||
| 54 | * Create access across all microservices |
||
| 55 | * |
||
| 56 | * @param \App\Entity\Role $role |
||
| 57 | * @return \App\Service\RoleService |
||
| 58 | * @throws \LogicException |
||
| 59 | */ |
||
| 60 | public function createAccess(Role $role) |
||
| 61 | { |
||
| 62 | if (null === $role->getUuid()) { |
||
| 63 | throw new LogicException('Role does not have a uuid.'); |
||
| 64 | } |
||
| 65 | |||
| 66 | foreach ($role->getPermissions() as $service => $servicePermissions) { |
||
| 67 | if (!$this->serviceRepository->find($this->namespace.'_'.$service.'_api_http')) { |
||
| 68 | continue; |
||
| 69 | } |
||
| 70 | |||
| 71 | $access = new Access; |
||
| 72 | $access |
||
| 73 | ->setOwner($role->getOwner()) |
||
| 74 | ->setOwnerUuid($role->getOwnerUuid()) |
||
| 75 | ->setAssignee('Role') |
||
| 76 | ->setAssigneeUuid($role->getUuid()) |
||
| 77 | ->setVersion(1); |
||
| 78 | |||
| 79 | foreach ($servicePermissions as $servicePermission) { |
||
| 80 | foreach ($servicePermission['permissions'] as $entry) { |
||
| 81 | $permission = new Permission; |
||
| 82 | $scope = new Scope; |
||
| 83 | $scope |
||
| 84 | ->setType($servicePermission['scope']['type']) |
||
| 85 | ->setEntity($servicePermission['scope']['entity']) |
||
| 86 | ->setEntityUuid($servicePermission['scope']['entityUuid']); |
||
| 87 | $permission |
||
| 88 | ->setScope($scope) |
||
| 89 | ->setKey($entry['key']) |
||
| 90 | ->setAttributes($entry['attributes']); |
||
| 91 | $access->addPermission($permission); |
||
| 92 | } |
||
| 93 | } |
||
| 94 | |||
| 95 | $this->api->get($service.'.access')->create($access); |
||
| 96 | } |
||
| 97 | |||
| 98 | return $this; |
||
| 99 | } |
||
| 100 | |||
| 101 | /** |
||
| 102 | * Delete access across all microservices |
||
| 103 | * |
||
| 104 | * @param \App\Entity\Role $role |
||
| 105 | * @return \App\Service\RoleService |
||
| 106 | * @throws \LogicException |
||
| 107 | */ |
||
| 108 | public function deleteAccess(Role $role) |
||
| 109 | { |
||
| 110 | if (null === $role->getUuid()) { |
||
| 111 | throw new LogicException('Role does not have a uuid.'); |
||
| 112 | } |
||
| 113 | |||
| 114 | foreach ($role->getPermissions() as $service => $scopes) { |
||
| 115 | if (!$this->serviceRepository->find($this->namespace.'_'.$service.'_api_http')) { |
||
| 116 | continue; |
||
| 117 | } |
||
| 118 | |||
| 119 | $service = $this->api->get($service.'.access'); |
||
| 120 | $parameters = new AccessParameters; |
||
| 121 | $parameters |
||
| 122 | ->setAssignee('Role') |
||
| 123 | ->setAssigneeUuid($role->getUuid()); |
||
| 124 | $accesses = $service->getList($parameters); |
||
| 125 | |||
| 126 | foreach ($accesses as $access) { |
||
| 127 | $service->delete($access); |
||
| 128 | } |
||
| 129 | } |
||
| 130 | |||
| 131 | return $this; |
||
| 132 | } |
||
| 133 | } |
||
| 134 |
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