context_srv.js 787 B

12345678910111213141516171819202122232425262728293031323334
  1. define([
  2. 'angular',
  3. 'lodash',
  4. '../core_module',
  5. 'app/core/store',
  6. 'app/core/config',
  7. ],
  8. function (angular, _, coreModule, store, config) {
  9. 'use strict';
  10. coreModule.default.service('contextSrv', function() {
  11. function User() {
  12. if (config.bootData.user) {
  13. _.extend(this, config.bootData.user);
  14. }
  15. }
  16. this.hasRole = function(role) {
  17. return this.user.orgRole === role;
  18. };
  19. this.toggleSideMenu = function() {
  20. this.sidemenu = !this.sidemenu;
  21. };
  22. this.version = config.buildInfo.version;
  23. this.lightTheme = false;
  24. this.user = new User();
  25. this.isSignedIn = this.user.isSignedIn;
  26. this.isGrafanaAdmin = this.user.isGrafanaAdmin;
  27. this.isEditor = this.hasRole('Editor') || this.hasRole('Admin');
  28. });
  29. });