-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[User Management] Add Dependencies to User. (#556)
* Add Dependencies to User. * Add Tests. * Apply php-cs-fixer changes --------- Co-authored-by: martineiber <[email protected]>
- Loading branch information
1 parent
d4c35eb
commit 8bb6c11
Showing
10 changed files
with
324 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* Pimcore | ||
* | ||
* This source file is available under two different licenses: | ||
* - GNU General Public License version 3 (GPLv3) | ||
* - Pimcore Commercial License (PCL) | ||
* Full copyright and license information is available in | ||
* LICENSE.md which is distributed with this source code. | ||
* | ||
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) | ||
* @license http://www.pimcore.org/license GPLv3 and PCL | ||
*/ | ||
|
||
namespace Pimcore\Bundle\StudioBackendBundle\User\Hydrator; | ||
|
||
use Pimcore\Bundle\StudioBackendBundle\User\Schema\Dependency; | ||
use Pimcore\Model\DataObject\Concrete; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class DependencyHydrator implements DependencyHydratorInterface | ||
{ | ||
public function hydrate(Concrete $concrete): Dependency | ||
{ | ||
return new Dependency( | ||
id: $concrete->getId(), | ||
path: $concrete->getRealFullPath(), | ||
subtype: $concrete->getClass()->getName(), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* Pimcore | ||
* | ||
* This source file is available under two different licenses: | ||
* - GNU General Public License version 3 (GPLv3) | ||
* - Pimcore Commercial License (PCL) | ||
* Full copyright and license information is available in | ||
* LICENSE.md which is distributed with this source code. | ||
* | ||
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) | ||
* @license http://www.pimcore.org/license GPLv3 and PCL | ||
*/ | ||
|
||
namespace Pimcore\Bundle\StudioBackendBundle\User\Hydrator; | ||
|
||
use Pimcore\Bundle\StudioBackendBundle\User\Schema\Dependency; | ||
use Pimcore\Model\DataObject\Concrete; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
interface DependencyHydratorInterface | ||
{ | ||
public function hydrate(Concrete $concrete): Dependency; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* Pimcore | ||
* | ||
* This source file is available under two different licenses: | ||
* - GNU General Public License version 3 (GPLv3) | ||
* - Pimcore Commercial License (PCL) | ||
* Full copyright and license information is available in | ||
* LICENSE.md which is distributed with this source code. | ||
* | ||
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) | ||
* @license http://www.pimcore.org/license GPLv3 and PCL | ||
*/ | ||
|
||
namespace Pimcore\Bundle\StudioBackendBundle\User\Schema; | ||
|
||
use OpenApi\Attributes\Property; | ||
use OpenApi\Attributes\Schema; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
#[Schema( | ||
schema: 'UserDependency', | ||
title: 'Dependency to an Object', | ||
description: 'Dependency to an Object', | ||
required: ['id', 'path', 'subtype'], | ||
type: 'object' | ||
)] | ||
final readonly class Dependency | ||
{ | ||
public function __construct( | ||
#[Property(description: 'ID of the object', type: 'integer', example: 42)] | ||
private int $id, | ||
#[Property(description: 'Path to the object', type: 'string', example: '/path/to/object')] | ||
private string $path, | ||
#[Property(description: 'Subtype of the object', type: 'string', example: 'Car')] | ||
private string $subtype, | ||
) { | ||
} | ||
|
||
public function getId(): int | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public function getPath(): string | ||
{ | ||
return $this->path; | ||
} | ||
|
||
public function getSubtype(): string | ||
{ | ||
return $this->subtype; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* Pimcore | ||
* | ||
* This source file is available under two different licenses: | ||
* - GNU General Public License version 3 (GPLv3) | ||
* - Pimcore Commercial License (PCL) | ||
* Full copyright and license information is available in | ||
* LICENSE.md which is distributed with this source code. | ||
* | ||
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) | ||
* @license http://www.pimcore.org/license GPLv3 and PCL | ||
*/ | ||
|
||
namespace Pimcore\Bundle\StudioBackendBundle\User\Schema; | ||
|
||
use OpenApi\Attributes\Items; | ||
use OpenApi\Attributes\Property; | ||
use OpenApi\Attributes\Schema; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
#[Schema( | ||
title: 'User Object Dependencies', | ||
description: 'User Object Dependencies', | ||
required: ['hasHidden', 'dependencies'], | ||
type: 'object', | ||
)] | ||
final readonly class ObjectDependencies | ||
{ | ||
public function __construct( | ||
#[Property(description: 'Dependencies to objects', type: 'array', items: new Items(ref: Dependency::class))] | ||
private array $dependencies, | ||
#[Property(description: 'If is has hidden dependencies', type: 'boolean', example: true)] | ||
private bool $hasHidden | ||
) { | ||
} | ||
|
||
public function getDependencies(): array | ||
{ | ||
return $this->dependencies; | ||
} | ||
|
||
public function isHasHidden(): bool | ||
{ | ||
return $this->hasHidden; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* Pimcore | ||
* | ||
* This source file is available under two different licenses: | ||
* - GNU General Public License version 3 (GPLv3) | ||
* - Pimcore Commercial License (PCL) | ||
* Full copyright and license information is available in | ||
* LICENSE.md which is distributed with this source code. | ||
* | ||
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) | ||
* @license http://www.pimcore.org/license GPLv3 and PCL | ||
*/ | ||
|
||
namespace Pimcore\Bundle\StudioBackendBundle\User\Service; | ||
|
||
use Pimcore\Bundle\StaticResolverBundle\Models\DataObject\DataObjectServiceResolverInterface; | ||
use Pimcore\Bundle\StudioBackendBundle\User\Hydrator\DependencyHydratorInterface; | ||
use Pimcore\Bundle\StudioBackendBundle\User\Schema\ObjectDependencies; | ||
use Pimcore\Model\UserInterface; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final readonly class ObjectDependenciesService implements ObjectDependenciesServiceInterface | ||
{ | ||
public function __construct( | ||
private DataObjectServiceResolverInterface $dataObjectServiceResolver, | ||
private DependencyHydratorInterface $dependencyHydrator | ||
) { | ||
} | ||
|
||
public function getDependenciesForUser(UserInterface $user): ObjectDependencies | ||
{ | ||
$dependencies = []; | ||
$hasHidden = false; | ||
|
||
$objects = $this->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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* Pimcore | ||
* | ||
* This source file is available under two different licenses: | ||
* - GNU General Public License version 3 (GPLv3) | ||
* - Pimcore Commercial License (PCL) | ||
* Full copyright and license information is available in | ||
* LICENSE.md which is distributed with this source code. | ||
* | ||
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) | ||
* @license http://www.pimcore.org/license GPLv3 and PCL | ||
*/ | ||
|
||
namespace Pimcore\Bundle\StudioBackendBundle\User\Service; | ||
|
||
use Pimcore\Bundle\StudioBackendBundle\User\Schema\ObjectDependencies; | ||
use Pimcore\Model\UserInterface; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
interface ObjectDependenciesServiceInterface | ||
{ | ||
public function getDependenciesForUser(UserInterface $user): ObjectDependencies; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* Pimcore | ||
* | ||
* This source file is available under two different licenses: | ||
* - GNU General Public License version 3 (GPLv3) | ||
* - Pimcore Commercial License (PCL) | ||
* Full copyright and license information is available in | ||
* LICENSE.md which is distributed with this source code. | ||
* | ||
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) | ||
* @license http://www.pimcore.org/license GPLv3 and PCL | ||
*/ | ||
|
||
namespace Pimcore\Bundle\StudioBackendBundle\Tests\Unit\User\Service; | ||
|
||
use Codeception\Test\Unit; | ||
use Pimcore\Bundle\StaticResolverBundle\Models\DataObject\DataObjectServiceResolverInterface; | ||
use Pimcore\Bundle\StudioBackendBundle\User\Hydrator\DependencyHydratorInterface; | ||
use Pimcore\Bundle\StudioBackendBundle\User\Service\ObjectDependenciesService; | ||
use Pimcore\Model\DataObject\Concrete; | ||
use Pimcore\Model\UserInterface; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class ObjectDependenciesServiceTest extends Unit | ||
{ | ||
public function testIfHiddenIsSet(): void | ||
{ | ||
$demoObject = $this->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()); | ||
} | ||
} |