Fix tests on ExportManager

This commit is contained in:
2023-07-27 22:51:55 +02:00
parent 9690359dfa
commit da6f8511a8
3 changed files with 242 additions and 283 deletions

View File

@@ -456,11 +456,11 @@ class ExportManager
*
*
*/
public function isGrantedForElement(ExportElementInterface $element, \Chill\MainBundle\Export\DirectExportInterface|\Chill\MainBundle\Export\ExportInterface $export = null, ?array $centers = null): bool
public function isGrantedForElement(ExportInterface|DirectExportInterface|ModifierInterface $element, \Chill\MainBundle\Export\DirectExportInterface|\Chill\MainBundle\Export\ExportInterface $export = null, ?array $centers = null): bool
{
if ($element instanceof ExportInterface || $element instanceof DirectExportInterface) {
$role = $element->requiredRole();
} elseif ($element instanceof ModifierInterface) {
} else {
if (null === $element->addRole()) {
if (null === $export) {
throw new LogicException('The export should not be null: as the '
@@ -471,13 +471,10 @@ class ExportManager
} else {
$role = $element->addRole();
}
} else {
throw new LogicException('The element is not an ModifiersInterface or '
. 'an ExportInterface.');
}
if (null === $centers || [] !== $centers) {
// we want to try if at least one center is reachabler
if (null === $centers || [] === $centers) {
// we want to try if at least one center is reachable
return [] !== $this->authorizationHelper->getReachableCenters(
$this->user,
$role
@@ -542,6 +539,11 @@ class ExportManager
$aggregators = $this->retrieveUsedAggregators($data);
foreach ($aggregators as $alias => $aggregator) {
if ($this->isGrantedForElement($aggregator, $export, $center) === false) {
throw new UnauthorizedHttpException('You are not authorized to '
. 'use the aggregator' . $aggregator->getTitle());
}
$formData = $data[$alias];
$aggregator->alterQuery($qb, $formData['form']);
}