|
|
@@ -1,4 +1,5 @@
|
|
|
<?php
|
|
|
+
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
namespace App\DataProvider\Access;
|
|
|
@@ -6,13 +7,8 @@ namespace App\DataProvider\Access;
|
|
|
use ApiPlatform\Core\DataProvider\ItemDataProviderInterface;
|
|
|
use ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface;
|
|
|
use App\ApiResources\Profile\AccessProfile;
|
|
|
-use App\ApiResources\Profile\OrganizationProfile;
|
|
|
use App\Entity\Access\Access;
|
|
|
-use App\Entity\Organization\Organization;
|
|
|
-use App\Service\Network\Tree;
|
|
|
-use App\Service\Security\Module;
|
|
|
-use Symfony\Component\Security\Core\Role\Role;
|
|
|
-use Symfony\Component\Security\Core\Role\RoleHierarchyInterface;
|
|
|
+use App\Service\Access\AccessProfileCreator;
|
|
|
use Symfony\Component\Security\Core\Security;
|
|
|
|
|
|
/**
|
|
|
@@ -22,21 +18,15 @@ use Symfony\Component\Security\Core\Security;
|
|
|
final class AccessProfileDataProvider implements ItemDataProviderInterface, RestrictedDataProviderInterface
|
|
|
{
|
|
|
private Security $security;
|
|
|
- private RoleHierarchyInterface $roleHierarchy;
|
|
|
- private Module $module;
|
|
|
- private Tree $tree;
|
|
|
+ private AccessProfileCreator $accessProfileCreator;
|
|
|
|
|
|
public function __construct(
|
|
|
Security $security,
|
|
|
- RoleHierarchyInterface $roleHierarchy,
|
|
|
- Module $module,
|
|
|
- Tree $tree
|
|
|
+ AccessProfileCreator $accessProfileCreator
|
|
|
)
|
|
|
{
|
|
|
$this->security = $security;
|
|
|
- $this->roleHierarchy = $roleHierarchy;
|
|
|
- $this->module = $module;
|
|
|
- $this->tree = $tree;
|
|
|
+ $this->accessProfileCreator = $accessProfileCreator;
|
|
|
}
|
|
|
|
|
|
public function supports(string $resourceClass, string $operationName = null, array $context = []): bool
|
|
|
@@ -48,58 +38,6 @@ final class AccessProfileDataProvider implements ItemDataProviderInterface, Rest
|
|
|
{
|
|
|
/** @var Access $access */
|
|
|
$access = $this->security->getUser();
|
|
|
-
|
|
|
- $myProfile = $this->setProfileFromAccess($access);
|
|
|
- $myProfile->setRoles($this->roleHierarchy->getReachableRoleNames($this->security->getToken()->getRoleNames()));
|
|
|
-
|
|
|
- $myProfile->setOrganization($this->setOrganizationProfileFromOrganization($access->getOrganization()));
|
|
|
-
|
|
|
- return $myProfile;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Hydratation du profile de l'access connecté via la resource accessProfile
|
|
|
- * @param Access $access
|
|
|
- * @return AccessProfile
|
|
|
- */
|
|
|
- public function setProfileFromAccess(Access $access): AccessProfile
|
|
|
- {
|
|
|
- $accessProfile = new AccessProfile();
|
|
|
- $accessProfile->setId($access->getId());
|
|
|
- $accessProfile->setIsAdminAccess($access->getAdminAccess());
|
|
|
- $accessProfile->setName($access->getPerson()->getName());
|
|
|
- $accessProfile->setGivenName($access->getPerson()->getGivenName());
|
|
|
- return $accessProfile;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Hydratation du profile des organizations auxquelles l'access connecté est inscrit
|
|
|
- * @param Organization $organization
|
|
|
- * @return OrganizationProfile
|
|
|
- */
|
|
|
- public function setOrganizationProfileFromOrganization(Organization $organization): OrganizationProfile{
|
|
|
- $organizationProfile = new OrganizationProfile();
|
|
|
- $organizationProfile->setId($organization->getId());
|
|
|
- $organizationProfile->setName($organization->getName());
|
|
|
- $organizationProfile->setModules($this->module->getOrganizationModules($organization));
|
|
|
- $organizationProfile->setProduct($organization->getSettings()->getProduct());
|
|
|
- $organizationProfile->setHasChildren($organization->getNetworkOrganizationChildren()->count() > 1);
|
|
|
- $organizationProfile->setSubDomain($organization->getParameters()->getSubDomain());
|
|
|
- $organizationProfile->setWebsite($organization->getParameters()->getWebsite());
|
|
|
-
|
|
|
- foreach ($organization->getNetworkOrganizations() as $networkOrganization){
|
|
|
- $organizationProfile->addNetwork($networkOrganization->getNetwork()->getName());
|
|
|
- }
|
|
|
-
|
|
|
- /** @var Organization $parent */
|
|
|
- foreach ($this->tree->findAllParentsAndSortByType($organization) as $parent){
|
|
|
- $parentProfile = new OrganizationProfile();
|
|
|
- $parentProfile->setId($parent->getId());
|
|
|
- $parentProfile->setName($parent->getName());
|
|
|
- $parentProfile->setSubDomain($parent->getParameters()->getSubDomain());
|
|
|
- $parentProfile->setWebsite($parent->getParameters()->getWebsite());
|
|
|
- $organizationProfile->addParent($parentProfile);
|
|
|
- }
|
|
|
- return $organizationProfile;
|
|
|
+ return $this->accessProfileCreator->getAccessProfile($access);
|
|
|
}
|
|
|
}
|