Skip to content

Commit

Permalink
[FEATURE] Respect access rights for newsletter selection in options i…
Browse files Browse the repository at this point in the history
…n new/edit view

Related: #211
  • Loading branch information
einpraegsam committed Mar 1, 2024
1 parent dc4ad95 commit 69d1bfb
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
21 changes: 16 additions & 5 deletions Classes/Domain/Repository/PageRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
declare(strict_types=1);
namespace In2code\Luxletter\Domain\Repository;

use In2code\Luxletter\Domain\Service\PermissionTrait;
use In2code\Luxletter\Exception\MisconfigurationException;
use In2code\Luxletter\Utility\BackendUserUtility;
use In2code\Luxletter\Utility\ConfigurationUtility;
use In2code\Luxletter\Utility\DatabaseUtility;
use PDO;
Expand All @@ -14,6 +16,8 @@

class PageRepository
{
use PermissionTrait;

const TABLE_NAME = 'pages';

/**
Expand All @@ -30,21 +34,28 @@ public function findAllNewsletterPages(): array
$pages = [];
try {
$queryBuilder = DatabaseUtility::getQueryBuilderForTable(self::TABLE_NAME);
$results = $queryBuilder
$rows = $queryBuilder
->select('*')
->from(self::TABLE_NAME)
->where(
'doktype=' . ConfigurationUtility::getMultilanguageNewsletterPageDoktype()
. ' and sys_language_uid=0'
)
->orderBy('title', 'desc')
->orderBy('title', 'asc')
->executeQuery()
->fetchAllAssociative();
foreach ($results as $result) {
$pages[$result['uid']] = $result['title'];
if (BackendUserUtility::isAdministrator() === false) {
foreach ($rows as $key => $row) {
if ($this->isAuthenticated($row) === false) {
unset($rows[$key]);
}
}
}
foreach ($rows as $row) {
$pages[$row['uid']] = $row['title'];
}
} catch (Throwable $exception) {
return $pages;
unset($exception);
}
return $pages;
}
Expand Down
21 changes: 21 additions & 0 deletions Classes/Domain/Service/PermissionTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);
namespace In2code\Luxletter\Domain\Service;

use In2code\Luxletter\Utility\BackendUserUtility;
use TYPO3\CMS\Core\Type\Bitmask\Permission;

trait PermissionTrait
{
private function isAuthenticated(array $pageRecord): bool
{
if (BackendUserUtility::isAdministrator()) {
return true;
}

$beuserAuthentication = BackendUserUtility::getBackendUserAuthentication();
return $beuserAuthentication !== null &&
$beuserAuthentication->doesUserHaveAccess($pageRecord, Permission::PAGE_SHOW);
}
}

0 comments on commit 69d1bfb

Please sign in to comment.