grafana 294 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. commit c75e669204ffd050e3ef23fdab516c425f7fb668
  2. Author: Torkel Ödegaard <torkel.odegaard@gmail.com>
  3. Date: Wed Jan 28 11:33:12 2015 +0100
  4. Hide sidemenu links that the user does not have access to
  5. diff --git a/src/app/controllers/grafanaCtrl.js b/src/app/controllers/grafanaCtrl.js
  6. index d2047cfef..9643328e5 100644
  7. --- a/src/app/controllers/grafanaCtrl.js
  8. +++ b/src/app/controllers/grafanaCtrl.js
  9. @@ -28,6 +28,7 @@ function (angular, config, _, $, store) {
  10. $scope.dashAlerts = alertSrv;
  11. $scope.grafana.style = 'dark';
  12. + $scope.grafana.user = {};
  13. if (window.grafanaBackend) {
  14. $scope.initBackendFeatures();
  15. @@ -36,10 +37,7 @@ function (angular, config, _, $, store) {
  16. $scope.initBackendFeatures = function() {
  17. $scope.grafana.sidemenu = store.getBool('grafana.sidemenu');
  18. -
  19. - if (window.grafanaBootData.user.login) {
  20. - $scope.grafana.user = window.grafanaBootData.user;
  21. - }
  22. + $scope.grafana.user = window.grafanaBootData.user;
  23. $scope.onAppEvent('logged-out', function() {
  24. $scope.grafana.sidemenu = false;
  25. diff --git a/src/app/controllers/sidemenuCtrl.js b/src/app/controllers/sidemenuCtrl.js
  26. index 10b73e245..28e826646 100644
  27. --- a/src/app/controllers/sidemenuCtrl.js
  28. +++ b/src/app/controllers/sidemenuCtrl.js
  29. @@ -15,39 +15,59 @@ function (angular, _, $, config) {
  30. return config.appSubUrl + url;
  31. };
  32. - $scope.menu = [
  33. - {
  34. - text: "Dashbord",
  35. - href: $scope.getUrl("/"),
  36. - startsWith: config.appSubUrl + '/dashboard/',
  37. - icon: "fa fa-th-large",
  38. - links: [
  39. - { text: 'Settings', editview: 'settings', icon: "fa fa-cogs" },
  40. - { text: 'Templating', editview: 'templating', icon: "fa fa-cogs" },
  41. - { text: 'Annotations', editview: 'annotations', icon: "fa fa-bolt" },
  42. - { text: 'Export', href:"", icon: "fa fa-bolt" },
  43. - { text: 'JSON', href:"", icon: "fa fa-bolt" },
  44. - ]
  45. - },
  46. - {
  47. + $scope.menu = [];
  48. + $scope.menu.push({
  49. + text: "Dashbord",
  50. + href: $scope.getUrl("/"),
  51. + startsWith: config.appSubUrl + '/dashboard/',
  52. + icon: "fa fa-th-large",
  53. + links: [
  54. + { text: 'Settings', editview: 'settings'},
  55. + { text: 'Templating', editview: 'templating'},
  56. + { text: 'Annotations', editview: 'annotations'},
  57. + { text: 'Export', href:""},
  58. + { text: 'JSON', href:""},
  59. + ]
  60. + });
  61. +
  62. + if ($scope.grafana.user.accountRole === 'Admin') {
  63. + $scope.menu.push({
  64. text: "Account", href: $scope.getUrl("/account"),
  65. + requireRole: "Admin",
  66. icon: "fa fa-shield",
  67. links: [
  68. - { text: 'Info', href: $scope.getUrl("/account"), icon: "fa fa-sitemap" },
  69. - { text: 'Data sources', href: $scope.getUrl("/account/datasources"), icon: "fa fa-sitemap" },
  70. - { text: 'Users', href: $scope.getUrl("/account/users"), icon: "fa fa-users" },
  71. - { text: 'API Keys', href: $scope.getUrl("/account/apikeys"), icon: "fa fa-key" },
  72. + { text: 'Info', href: $scope.getUrl("/account")},
  73. + { text: 'Data sources', href: $scope.getUrl("/account/datasources")},
  74. + { text: 'Users', href: $scope.getUrl("/account/users")},
  75. + { text: 'API Keys', href: $scope.getUrl("/account/apikeys")},
  76. ]
  77. - },
  78. - {
  79. + });
  80. + }
  81. +
  82. + if ($scope.grafana.user.isSignedIn) {
  83. + $scope.menu.push({
  84. text: "Profile", href: $scope.getUrl("/profile"),
  85. icon: "fa fa-user",
  86. + requireSignedIn: true,
  87. links: [
  88. - { text: 'Info', href: $scope.getUrl("/profile"), icon: "fa fa-sitemap" },
  89. + { text: 'Info', href: $scope.getUrl("/profile"), icon: "fa fa-sitemap" },
  90. { text: 'Password', href:"", icon: "fa fa-lock" },
  91. ]
  92. - }
  93. - ];
  94. + });
  95. + }
  96. +
  97. + if ($scope.grafana.user.isGrafanaAdmin) {
  98. + $scope.menu.push({
  99. + text: "Admin", href: $scope.getUrl("/admin/users"),
  100. + icon: "fa fa-cube",
  101. + requireSignedIn: true,
  102. + links: [
  103. + { text: 'Settings', href: $scope.getUrl("/admin/settings")},
  104. + { text: 'Users', href: $scope.getUrl("/admin/users"), icon: "fa fa-lock" },
  105. + { text: 'Log', href: "", icon: "fa fa-lock" },
  106. + ]
  107. + });
  108. + }
  109. $scope.onAppEvent('$routeUpdate', function() {
  110. $scope.updateState();
  111. diff --git a/src/app/partials/sidemenu.html b/src/app/partials/sidemenu.html
  112. index 0ba9c6426..692518ddf 100644
  113. --- a/src/app/partials/sidemenu.html
  114. +++ b/src/app/partials/sidemenu.html
  115. @@ -1,7 +1,7 @@
  116. <div ng-controller="SideMenuCtrl" ng-init="init()">
  117. <ul class="sidemenu">
  118. - <li class="dropdown">
  119. + <li class="dropdown" ng-if="grafana.user.isSignedIn">
  120. <a class="sidemenu-user pointer" data-toggle="dropdown" title="{{grafana.user.email}}">
  121. <span class="gravatar-missing">f</span>
  122. <img ng-src="{{grafana.user.gravatarUrl}}" width="35">
  123. @@ -11,6 +11,9 @@
  124. <li><a href="{{appSubUrl}}/login?logout">Logout</a></li>
  125. </ul>
  126. </li>
  127. + <li ng-if="!grafana.user.isSignedIn">
  128. + <a href="login" class="sidemenu-item"><i class="fa fa-sign-in"></i>Sign in</a>
  129. + </li>
  130. <li ng-repeat-start="item in menu" ng-class="{'active': item.active}">
  131. <a href="{{item.href}}" class="sidemenu-item"><i class="{{item.icon}}"></i>{{item.text}}</a>
  132. </li>