-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PS-711 databox - add security to workspace list (#482)
* PS-711 databox - add security to workspace list * PS-714 fix asset rendition query * PS-713 fix collection inherited privacy * nofollow for robots * PS-713 databox privacy widget: fix collection inheritance constraint
- Loading branch information
Showing
15 changed files
with
103 additions
and
104 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Api\Extension; | ||
|
||
use Alchemy\AclBundle\Entity\AccessControlEntryRepository; | ||
use Alchemy\AclBundle\Mapping\ObjectMapping; | ||
use Alchemy\AclBundle\Security\PermissionInterface; | ||
use Alchemy\AuthBundle\Security\JwtUser; | ||
use ApiPlatform\Doctrine\Orm\Extension\QueryCollectionExtensionInterface; | ||
use ApiPlatform\Doctrine\Orm\Util\QueryNameGeneratorInterface; | ||
use ApiPlatform\Metadata\Operation; | ||
use App\Entity\Core\Workspace; | ||
use Doctrine\ORM\QueryBuilder; | ||
use Symfony\Bundle\SecurityBundle\Security; | ||
|
||
final readonly class WorkspaceExtension implements QueryCollectionExtensionInterface | ||
{ | ||
public function __construct(private Security $security, private ObjectMapping $objectMapping) | ||
{ | ||
} | ||
|
||
public function applyToCollection( | ||
QueryBuilder $queryBuilder, | ||
QueryNameGeneratorInterface $queryNameGenerator, | ||
string $resourceClass, | ||
?Operation $operation = null, | ||
array $context = [], | ||
): void { | ||
$this->addWhere($queryBuilder, $resourceClass, $context); | ||
} | ||
|
||
private function addWhere(QueryBuilder $queryBuilder, string $resourceClass, array $context): void | ||
{ | ||
if (Workspace::class !== $resourceClass) { | ||
return; | ||
} | ||
|
||
$rootAlias = $queryBuilder->getRootAliases()[0]; | ||
|
||
$user = $this->security->getUser(); | ||
if ($user instanceof JwtUser) { | ||
AccessControlEntryRepository::joinAcl( | ||
$queryBuilder, | ||
$user->getId(), | ||
$user->getGroups(), | ||
$this->objectMapping->getObjectKey(Workspace::class), | ||
$rootAlias, | ||
PermissionInterface::VIEW, | ||
false | ||
); | ||
$queryBuilder->andWhere(sprintf('ace.id IS NOT NULL OR %1$s.ownerId = :uid OR %1$s.public = true', $rootAlias)); | ||
} else { | ||
$queryBuilder->andWhere(sprintf('%1$s.public = true', $rootAlias)); | ||
} | ||
} | ||
} |
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
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
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
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
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
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
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