Skip to content

Firefly III: a personal finances manager

Fix missing link to admin.

James Cole1af45aff736c
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 @@
<a class="{{ activeRoutePartial('currencies') }}" href="{{ route('currencies.index') }}"><i class="fa fa-usd fa-fw"></i> {{ 'currencies'|_ }}
</a>
</li>
- {% if Auth.user.hasRole('owner') %}
+ {% if hasRole('owner') %}
<li class="{{ activeRoutePartial('admin') }}">
<a class="{{ activeRoutePartial('admin') }}" href="{{ route('admin.index') }}"><i
class="fa fa-hand-spock-o fa-fw"></i> {{ 'administration'|_ }}</a>