-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #80 from pixelant/2.3_dev
New release
- Loading branch information
Showing
37 changed files
with
683 additions
and
82 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
65 changes: 65 additions & 0 deletions
65
Classes/Database/Query/Restriction/BackendGroupRestriction.php
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,65 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Pixelant\PxaSocialFeed\Database\Query\Restriction; | ||
|
||
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication; | ||
use TYPO3\CMS\Core\Database\Query\Expression\CompositeExpression; | ||
use TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder; | ||
use TYPO3\CMS\Core\Database\Query\Restriction\QueryRestrictionInterface; | ||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
|
||
/** | ||
* Restrict access by BE user group | ||
*/ | ||
class BackendGroupRestriction implements QueryRestrictionInterface | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
protected $groupFieldName = 'be_group'; | ||
|
||
/** | ||
* @var BackendUserAuthentication|null | ||
*/ | ||
protected $backendUserAuth = null; | ||
|
||
/** | ||
* Initialize | ||
*/ | ||
public function __construct() | ||
{ | ||
if (isset($GLOBALS['BE_USER'])) { | ||
$this->backendUserAuth = $GLOBALS['BE_USER']; | ||
} | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function buildExpression(array $queriedTables, ExpressionBuilder $expressionBuilder): CompositeExpression | ||
{ | ||
$constraints = []; | ||
if ($this->backendUserAuth !== null && !$this->backendUserAuth->isAdmin()) { | ||
foreach ($queriedTables as $tableAlias => $tableName) { | ||
$fieldName = $tableAlias . '.' . $this->groupFieldName; | ||
// Allow records where no group access has been configured (field values NULL, 0 or empty string) | ||
$constraints = [ | ||
$expressionBuilder->isNull($fieldName), | ||
$expressionBuilder->eq($fieldName, $expressionBuilder->literal('')), | ||
$expressionBuilder->eq($fieldName, $expressionBuilder->literal('0')), | ||
]; | ||
|
||
$backendGroupIds = GeneralUtility::intExplode(',', $this->backendUserAuth->groupList); | ||
foreach ($backendGroupIds as $backendGroupId) { | ||
$constraints[] = $expressionBuilder->inSet( | ||
$fieldName, | ||
$expressionBuilder->literal((string)$backendGroupId) | ||
); | ||
} | ||
} | ||
} | ||
|
||
return $expressionBuilder->orX(...$constraints); | ||
} | ||
} |
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
Oops, something went wrong.
a77e1be
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.