Commit c75e6692 by Torkel Ödegaard

Hide sidemenu links that the user does not have access to

parent 1758412a
...@@ -28,6 +28,7 @@ function (angular, config, _, $, store) { ...@@ -28,6 +28,7 @@ function (angular, config, _, $, store) {
$scope.dashAlerts = alertSrv; $scope.dashAlerts = alertSrv;
$scope.grafana.style = 'dark'; $scope.grafana.style = 'dark';
$scope.grafana.user = {};
if (window.grafanaBackend) { if (window.grafanaBackend) {
$scope.initBackendFeatures(); $scope.initBackendFeatures();
...@@ -36,10 +37,7 @@ function (angular, config, _, $, store) { ...@@ -36,10 +37,7 @@ function (angular, config, _, $, store) {
$scope.initBackendFeatures = function() { $scope.initBackendFeatures = function() {
$scope.grafana.sidemenu = store.getBool('grafana.sidemenu'); $scope.grafana.sidemenu = store.getBool('grafana.sidemenu');
$scope.grafana.user = window.grafanaBootData.user;
if (window.grafanaBootData.user.login) {
$scope.grafana.user = window.grafanaBootData.user;
}
$scope.onAppEvent('logged-out', function() { $scope.onAppEvent('logged-out', function() {
$scope.grafana.sidemenu = false; $scope.grafana.sidemenu = false;
......
...@@ -15,39 +15,59 @@ function (angular, _, $, config) { ...@@ -15,39 +15,59 @@ function (angular, _, $, config) {
return config.appSubUrl + url; return config.appSubUrl + url;
}; };
$scope.menu = [ $scope.menu = [];
{ $scope.menu.push({
text: "Dashbord", text: "Dashbord",
href: $scope.getUrl("/"), href: $scope.getUrl("/"),
startsWith: config.appSubUrl + '/dashboard/', startsWith: config.appSubUrl + '/dashboard/',
icon: "fa fa-th-large", icon: "fa fa-th-large",
links: [ links: [
{ text: 'Settings', editview: 'settings', icon: "fa fa-cogs" }, { text: 'Settings', editview: 'settings'},
{ text: 'Templating', editview: 'templating', icon: "fa fa-cogs" }, { text: 'Templating', editview: 'templating'},
{ text: 'Annotations', editview: 'annotations', icon: "fa fa-bolt" }, { text: 'Annotations', editview: 'annotations'},
{ text: 'Export', href:"", icon: "fa fa-bolt" }, { text: 'Export', href:""},
{ text: 'JSON', href:"", icon: "fa fa-bolt" }, { text: 'JSON', href:""},
] ]
}, });
{
if ($scope.grafana.user.accountRole === 'Admin') {
$scope.menu.push({
text: "Account", href: $scope.getUrl("/account"), text: "Account", href: $scope.getUrl("/account"),
requireRole: "Admin",
icon: "fa fa-shield", icon: "fa fa-shield",
links: [ links: [
{ text: 'Info', href: $scope.getUrl("/account"), icon: "fa fa-sitemap" }, { text: 'Info', href: $scope.getUrl("/account")},
{ text: 'Data sources', href: $scope.getUrl("/account/datasources"), icon: "fa fa-sitemap" }, { text: 'Data sources', href: $scope.getUrl("/account/datasources")},
{ text: 'Users', href: $scope.getUrl("/account/users"), icon: "fa fa-users" }, { text: 'Users', href: $scope.getUrl("/account/users")},
{ text: 'API Keys', href: $scope.getUrl("/account/apikeys"), icon: "fa fa-key" }, { text: 'API Keys', href: $scope.getUrl("/account/apikeys")},
] ]
}, });
{ }
if ($scope.grafana.user.isSignedIn) {
$scope.menu.push({
text: "Profile", href: $scope.getUrl("/profile"), text: "Profile", href: $scope.getUrl("/profile"),
icon: "fa fa-user", icon: "fa fa-user",
requireSignedIn: true,
links: [ links: [
{ text: 'Info', href: $scope.getUrl("/profile"), icon: "fa fa-sitemap" }, { text: 'Info', href: $scope.getUrl("/profile"), icon: "fa fa-sitemap" },
{ text: 'Password', href:"", icon: "fa fa-lock" }, { text: 'Password', href:"", icon: "fa fa-lock" },
] ]
} });
]; }
if ($scope.grafana.user.isGrafanaAdmin) {
$scope.menu.push({
text: "Admin", href: $scope.getUrl("/admin/users"),
icon: "fa fa-cube",
requireSignedIn: true,
links: [
{ text: 'Settings', href: $scope.getUrl("/admin/settings")},
{ text: 'Users', href: $scope.getUrl("/admin/users"), icon: "fa fa-lock" },
{ text: 'Log', href: "", icon: "fa fa-lock" },
]
});
}
$scope.onAppEvent('$routeUpdate', function() { $scope.onAppEvent('$routeUpdate', function() {
$scope.updateState(); $scope.updateState();
......
<div ng-controller="SideMenuCtrl" ng-init="init()"> <div ng-controller="SideMenuCtrl" ng-init="init()">
<ul class="sidemenu"> <ul class="sidemenu">
<li class="dropdown"> <li class="dropdown" ng-if="grafana.user.isSignedIn">
<a class="sidemenu-user pointer" data-toggle="dropdown" title="{{grafana.user.email}}"> <a class="sidemenu-user pointer" data-toggle="dropdown" title="{{grafana.user.email}}">
<span class="gravatar-missing">f</span> <span class="gravatar-missing">f</span>
<img ng-src="{{grafana.user.gravatarUrl}}" width="35"> <img ng-src="{{grafana.user.gravatarUrl}}" width="35">
...@@ -11,6 +11,9 @@ ...@@ -11,6 +11,9 @@
<li><a href="{{appSubUrl}}/login?logout">Logout</a></li> <li><a href="{{appSubUrl}}/login?logout">Logout</a></li>
</ul> </ul>
</li> </li>
<li ng-if="!grafana.user.isSignedIn">
<a href="login" class="sidemenu-item"><i class="fa fa-sign-in"></i>Sign in</a>
</li>
<li ng-repeat-start="item in menu" ng-class="{'active': item.active}"> <li ng-repeat-start="item in menu" ng-class="{'active': item.active}">
<a href="{{item.href}}" class="sidemenu-item"><i class="{{item.icon}}"></i>{{item.text}}</a> <a href="{{item.href}}" class="sidemenu-item"><i class="{{item.icon}}"></i>{{item.text}}</a>
</li> </li>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment