Skip to content

Commit

Permalink
redirect CP subnav based on the permission, hide CP nav when no permi…
Browse files Browse the repository at this point in the history
…ssion ist set
  • Loading branch information
kringkaste committed Aug 4, 2021
1 parent ed38e84 commit 3fa97fb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
10 changes: 7 additions & 3 deletions src/Glossary.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,17 @@ private function _cpInit(): void
/**
* @inheritDoc
*/
public function getCpNavItem(): array
public function getCpNavItem(): ?array
{
$currentUser = Craft::$app->getUser()->getIdentity();

if (!$currentUser->can('glossary:glossaryEdit') && !$currentUser->can('glossary:termEdit')) {
return null;
}

$navItem = parent::getCpNavItem();
$subNavs = [];

$currentUser = Craft::$app->getUser()->getIdentity();

if ($currentUser->can('glossary:glossaryEdit')) {
$subNavs['glossaries'] = [
'url' => 'glossary/glossaries',
Expand Down
8 changes: 7 additions & 1 deletion src/templates/index.twig
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
{% redirect 'glossary/glossaries' %}
{% if currentUser.can('glossary:glossaryEdit') %}
{% redirect 'glossary/glossaries' %}
{% elseif currentUser.can('glossary:termEdit') %}
{% redirect 'glossary/terms' %}
{% else %}
{% redirect 'dashboard' %}
{% endif %}

0 comments on commit 3fa97fb

Please sign in to comment.