From 1af45aff736c101e8f40c1908d64306369885095 Mon Sep 17 00:00:00 2001 From: James Cole Date: Tue, 31 Jul 2018 19:28:56 +0200 Subject: [PATCH] Fix missing link to admin. --- app/Support/Twig/General.php | 23 +++++++++++++++++++++- resources/views/partials/menu-sidebar.twig | 2 +- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/app/Support/Twig/General.php b/app/Support/Twig/General.php index 633de8f1c3..a92de4be5c 100644 --- a/app/Support/Twig/General.php +++ b/app/Support/Twig/General.php @@ -24,6 +24,7 @@ namespace FireflyIII\Support\Twig; use Carbon\Carbon; use FireflyIII\Models\Account; +use FireflyIII\Repositories\User\UserRepositoryInterface; use FireflyIII\Support\Twig\Extension\Account as AccountExtension; use League\CommonMark\CommonMarkConverter; use Route; @@ -45,7 +46,7 @@ class General extends Twig_Extension $this->balance(), $this->formatFilesize(), $this->mimeIcon(), - $this->markdown(), + $this->markdown() ]; } @@ -64,6 +65,7 @@ class General extends Twig_Extension $this->activeRoutePartialWhat(), $this->formatDate(), new Twig_SimpleFunction('accountGetMetaField', [AccountExtension::class, 'getMetaField']), + $this->hasRole(), ]; } @@ -235,6 +237,25 @@ class General extends Twig_Extension ); } + /** + * Will return true if the user is of role X. + * + * @return Twig_SimpleFunction + */ + protected function hasRole(): Twig_SimpleFunction + { + return new Twig_SimpleFunction( + 'hasRole', + function (string $role): bool { + $repository = app(UserRepositoryInterface::class); + if ($repository->hasRole(auth()->user(), $role)) { + return true; + } + return false; + } + ); + } + /** * @return Twig_SimpleFilter */ diff --git a/resources/views/partials/menu-sidebar.twig b/resources/views/partials/menu-sidebar.twig index 7dde1e8bcc..8d959b7807 100644 --- a/resources/views/partials/menu-sidebar.twig +++ b/resources/views/partials/menu-sidebar.twig @@ -149,7 +149,7 @@ {{ 'currencies'|_ }} - {% if Auth.user.hasRole('owner') %} + {% if hasRole('owner') %}
  • {{ 'administration'|_ }}