Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Contexts): enable nav bar display logic #1193

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions lib/Db/ContextMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,17 +168,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
36 changes: 4 additions & 32 deletions lib/Listener/BeforeTemplateRenderedListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
class BeforeTemplateRenderedListener implements IEventListener {
public function __construct(
protected INavigationManager $navigationManager,
protected IURLGenerator $urlGenerator,
protected IUserSession $userSession,
protected ContextService $contextService,
protected IURLGenerator $urlGenerator,
protected IUserSession $userSession,
protected ContextService $contextService,
) {
}

Expand All @@ -41,36 +41,8 @@ public function handle(Event $event): void {
return;
}

// temporarily show all
//$contexts = $this->contextService->findForNavigation($user->getUID());
$contexts = $this->contextService->findAll($user->getUID());
$contexts = $this->contextService->findForNavigation($user->getUID());
foreach ($contexts as $context) {
/* temporarily, show all
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;
} elseif (!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
2 changes: 1 addition & 1 deletion lib/Service/ShareService.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ public function updateDisplayMode(int $shareId, int $displayMode, string $userId
}
}

return $this->contextNavigationMapper->setDisplayModeByShareId($shareId, $displayMode, '');
return $this->contextNavigationMapper->setDisplayModeByShareId($shareId, $displayMode, $userId);
} catch (DoesNotExistException $e) {
$this->logger->error($e->getMessage(), ['exception' => $e]);
throw new NotFoundError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage());
Expand Down
Loading