diff --git a/config/users.yaml b/config/users.yaml index cb11348e..0c2e16bc 100644 --- a/config/users.yaml +++ b/config/users.yaml @@ -41,6 +41,10 @@ services: Pimcore\Bundle\StudioBackendBundle\User\Service\UserInformationServiceInterface: class: Pimcore\Bundle\StudioBackendBundle\User\Service\UserInformationService + Pimcore\Bundle\StudioBackendBundle\User\Service\ObjectDependenciesServiceInterface: + class: Pimcore\Bundle\StudioBackendBundle\User\Service\ObjectDependenciesService + + Pimcore\Bundle\StudioBackendBundle\User\Service\MailServiceInterface: class: Pimcore\Bundle\StudioBackendBundle\User\Service\MailService arguments: [ '@Pimcore\Bundle\StudioBackendBundle\Setting\Provider\SystemSettingsProvider' ] @@ -66,6 +70,9 @@ services: Pimcore\Bundle\StudioBackendBundle\User\Hydrator\SimpleUserHydratorInterface: class: Pimcore\Bundle\StudioBackendBundle\User\Hydrator\SimpleUserHydrator + Pimcore\Bundle\StudioBackendBundle\User\Hydrator\DependencyHydratorInterface: + class: Pimcore\Bundle\StudioBackendBundle\User\Hydrator\DependencyHydrator + # # Repositories diff --git a/src/User/Hydrator/DependencyHydrator.php b/src/User/Hydrator/DependencyHydrator.php new file mode 100644 index 00000000..a28baba0 --- /dev/null +++ b/src/User/Hydrator/DependencyHydrator.php @@ -0,0 +1,35 @@ +getId(), + path: $concrete->getRealFullPath(), + subtype: $concrete->getClass()->getName(), + ); + } +} diff --git a/src/User/Hydrator/DependencyHydratorInterface.php b/src/User/Hydrator/DependencyHydratorInterface.php new file mode 100644 index 00000000..a2eb65c2 --- /dev/null +++ b/src/User/Hydrator/DependencyHydratorInterface.php @@ -0,0 +1,28 @@ +getClasses(), assetWorkspaces: $this->workspaceHydrator->hydrateAssetWorkspace($user), dataObjectWorkspaces: $this->workspaceHydrator->hydrateDataObjectWorkspace($user), documentWorkspaces: $this->workspaceHydrator->hydrateDocumentWorkspace($user), + objectDependencies: $this->objectDependenciesService->getDependenciesForUser($user), ); } diff --git a/src/User/Schema/Dependency.php b/src/User/Schema/Dependency.php new file mode 100644 index 00000000..f5b539d3 --- /dev/null +++ b/src/User/Schema/Dependency.php @@ -0,0 +1,58 @@ +id; + } + + public function getPath(): string + { + return $this->path; + } + + public function getSubtype(): string + { + return $this->subtype; + } +} diff --git a/src/User/Schema/ObjectDependencies.php b/src/User/Schema/ObjectDependencies.php new file mode 100644 index 00000000..da473107 --- /dev/null +++ b/src/User/Schema/ObjectDependencies.php @@ -0,0 +1,51 @@ +dependencies; + } + + public function isHasHidden(): bool + { + return $this->hasHidden; + } +} diff --git a/src/User/Schema/User.php b/src/User/Schema/User.php index 143e7e09..4f2271d4 100644 --- a/src/User/Schema/User.php +++ b/src/User/Schema/User.php @@ -29,7 +29,7 @@ 'id', 'active', 'admin', 'classes', 'closeWarning', 'allowDirtyClose', 'contentLanguages', 'hasImage', 'keyBindings', 'language', 'memorizeTabs', 'parentId', 'permissions', 'roles', 'twoFactorAuthenticationEnabled', 'websiteTranslationLanguagesEdit', 'websiteTranslationLanguagesView', - 'welcomeScreen', 'assetWorkspaces', 'dataObjectWorkspaces', 'documentWorkspaces', + 'welcomeScreen', 'assetWorkspaces', 'dataObjectWorkspaces', 'documentWorkspaces', 'objectDependencies', ], type: 'object' )] @@ -94,6 +94,8 @@ public function __construct( private readonly array $dataObjectWorkspaces, #[Property(description: 'Document Workspace', type: 'array', items: new Items(ref: UserWorkspace::class))] private readonly array $documentWorkspaces, + #[Property(ref: ObjectDependencies::class, description: 'Object Dependencies', type: 'object')] + private readonly ObjectDependencies $objectDependencies, ) { } @@ -238,4 +240,9 @@ public function getDocumentWorkspaces(): array { return $this->documentWorkspaces; } + + public function getObjectDependencies(): ObjectDependencies + { + return $this->objectDependencies; + } } diff --git a/src/User/Service/ObjectDependenciesService.php b/src/User/Service/ObjectDependenciesService.php new file mode 100644 index 00000000..f534ec33 --- /dev/null +++ b/src/User/Service/ObjectDependenciesService.php @@ -0,0 +1,54 @@ +dataObjectServiceResolver->getObjectsReferencingUser($user->getId()); + + foreach ($objects as $object) { + if ($object->isAllowed('list')) { + $dependencies[] = $this->dependencyHydrator->hydrate($object); + + continue; + } + + $hasHidden = true; + } + + return new ObjectDependencies($dependencies, $hasHidden); + } +} diff --git a/src/User/Service/ObjectDependenciesServiceInterface.php b/src/User/Service/ObjectDependenciesServiceInterface.php new file mode 100644 index 00000000..4a485ca6 --- /dev/null +++ b/src/User/Service/ObjectDependenciesServiceInterface.php @@ -0,0 +1,28 @@ +makeEmpty(Concrete::class, [ + 'isAllowed' => false, + ]); + + $dataObjectServiceResolver = $this->makeEmpty(DataObjectServiceResolverInterface::class, [ + 'getObjectsReferencingUser' => [$demoObject], + ]); + $dependencyHydrator = $this->makeEmpty(DependencyHydratorInterface::class); + + $objectDependenciesService = new ObjectDependenciesService($dataObjectServiceResolver, $dependencyHydrator); + + $user = $this->makeEmpty(UserInterface::class, [ + 'getId' => 1, + ]); + + $objectDependencies = $objectDependenciesService->getDependenciesForUser($user); + + $this->assertTrue($objectDependencies->isHasHidden()); + } +}