Skip to content

Commit

Permalink
fix: have visibility checks already in SQL instead of later filtering
Browse files Browse the repository at this point in the history
Signed-off-by: Arthur Schiwon <[email protected]>
  • Loading branch information
blizzz authored and enjeck committed Aug 6, 2024
1 parent 8669101 commit ac42f69
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 31 deletions.
24 changes: 17 additions & 7 deletions lib/Db/ContextMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,17 +165,27 @@ public function findAll(?string $userId = null): array {

return $resultEntities;
}

public function findForNavBar(string $userId): array {
$qb = $this->getFindContextBaseQuery($userId);
$qb->andWhere($qb->expr()->andX(
$qb->andWhere($qb->expr()->orX(
// default
$qb->expr()->gt('n.display_mode', $qb->createNamedParameter(Application::NAV_ENTRY_MODE_HIDDEN, IQueryBuilder::PARAM_INT)),
// user override
$qb->expr()->orX(
$qb->expr()->gt('n2.display_mode', $qb->createNamedParameter(Application::NAV_ENTRY_MODE_HIDDEN, IQueryBuilder::PARAM_INT)),
$qb->expr()->andX(
// requires lack of user overwrite, indicated by n2.display_mode
$qb->expr()->isNull('n2.display_mode'),
)
// requires a display mode also depending on the role…
$qb->expr()->orX(
// not an owner: requires RECIPIENT or ALL
$qb->expr()->andX(
// groups are not considered, yet
$qb->expr()->neq('c.owner_id', $qb->createNamedParameter($userId)),
$qb->expr()->gt('n.display_mode', $qb->createNamedParameter(Application::NAV_ENTRY_MODE_HIDDEN, IQueryBuilder::PARAM_INT)),
),
// an owner (no explicit check necessary): requires ALL
$qb->expr()->eq('n.display_mode', $qb->createNamedParameter(Application::NAV_ENTRY_MODE_ALL, IQueryBuilder::PARAM_INT)),
),
),
// user override
$qb->expr()->gt('n2.display_mode', $qb->createNamedParameter(Application::NAV_ENTRY_MODE_HIDDEN, IQueryBuilder::PARAM_INT)),
));

$result = $qb->executeQuery();
Expand Down
24 changes: 0 additions & 24 deletions lib/Listener/BeforeTemplateRenderedListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,30 +38,6 @@ public function handle(Event $event): void {

$contexts = $this->contextService->findForNavigation($user->getUID());
foreach ($contexts as $context) {
if ($context->getOwnerType() === Application::OWNER_TYPE_USER
&& $context->getOwnerId() === $user->getUID()) {

// filter out entries for owners unless it is set to be visible
$skipEntry = true;
foreach ($context->getSharing() as $shareInfo) {
// TODO: integrate into DB query in Mapper
if (isset($shareInfo['display_mode']) && $shareInfo['display_mode'] === Application::NAV_ENTRY_MODE_ALL) {
// a custom override makes it visible
$skipEntry = false;
break;
}

if (!isset($shareInfo['display_mode']) && $shareInfo['display_mode_default'] === Application::NAV_ENTRY_MODE_ALL) {
// no custom override, and visible also for owner by default
$skipEntry = false;
break;
}
}
if ($skipEntry) {
continue;
}
}

$this->navigationManager->add(function () use ($context) {
$iconRelPath = 'material/' . $context->getIcon() . '.svg';
if (file_exists(__DIR__ . '/../../img/' . $iconRelPath)) {
Expand Down

0 comments on commit ac42f69

Please sign in to comment.