Last active
October 26, 2022 11:41
-
-
Save lorenzulrich/e45abc168133720bfc3037a8c5c30528 to your computer and use it in GitHub Desktop.
A custom privilege matcher to match asset collections whose title starts with a given string. This can be used to conditionally show/hide asset collections in the Media module. Please keep in mind that this does not prevent anyone from knowing the location of a certain file to download it. There are other solutions to ensuring files are only ser…
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
<?php | |
namespace Visol\FoobarCom\Security\Authorization\Privilege\Doctrine; | |
/* | |
* This file is part of the Neos.Media package. | |
* | |
* (c) Contributors of the Neos Project - www.neos.io | |
* | |
* This package is Open Source Software. For the full copyright and license | |
* information, please view the LICENSE file which was distributed with this | |
* source code. | |
*/ | |
use Neos\Flow\Security\Authorization\Privilege\Entity\Doctrine\ConditionGenerator as EntityConditionGenerator; | |
use Neos\Flow\Security\Authorization\Privilege\Entity\Doctrine\PropertyConditionGenerator; | |
use Neos\Flow\Security\Exception\InvalidPrivilegeException; | |
use Neos\Media\Domain\Model\AssetCollection; | |
/** | |
* A SQL condition generator, supporting special SQL constraints for asset collections | |
*/ | |
class AssetCollectionConditionGenerator extends \Neos\Media\Security\Authorization\Privilege\Doctrine\AssetCollectionConditionGenerator | |
{ | |
/** | |
* @param string $collectionTitleStart | |
* @return PropertyConditionGenerator | |
*/ | |
public function titleStartsWith($collectionTitleStart) | |
{ | |
$propertyConditionGenerator = new PropertyConditionGenerator('title'); | |
return $propertyConditionGenerator->like($collectionTitleStart . '%'); | |
} | |
} |
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
privilegeTargets: | |
# Protected BoardMember documents | |
'Visol\FoobarCom\Security\Authorization\Privilege\ReadAssetCollectionPrivilege': | |
'Visol.FoobarCom:BoardArea->boardDocuments': | |
matcher: 'titleStartsWith("Board_")' |
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
<?php | |
namespace Visol\FoobarCom\Security\Authorization\Privilege; | |
/* | |
* This file is part of the Neos.Media package. | |
* | |
* (c) Contributors of the Neos Project - www.neos.io | |
* | |
* This package is Open Source Software. For the full copyright and license | |
* information, please view the LICENSE file which was distributed with this | |
* source code. | |
*/ | |
use Visol\FoobarCom\Security\Authorization\Privilege\Doctrine\AssetCollectionConditionGenerator; | |
/** | |
* Privilege for restricting reading of AssetCollections | |
* | |
* Extended by a titleStartsWith condition | |
*/ | |
class ReadAssetCollectionPrivilege extends \Neos\Media\Security\Authorization\Privilege\ReadAssetCollectionPrivilege | |
{ | |
/** | |
* @return AssetCollectionConditionGenerator | |
*/ | |
protected function getConditionGenerator() | |
{ | |
return new AssetCollectionConditionGenerator(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment