context_srv.js 877 B

1234567891011121314151617181920212223242526272829303132333435363738
  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.setSideMenuState = function(state) {
  20. this.sidemenu = state;
  21. };
  22. this.toggleSideMenu = function() {
  23. this.setSideMenuState(!this.sidemenu);
  24. };
  25. this.version = config.buildInfo.version;
  26. this.lightTheme = false;
  27. this.user = new User();
  28. this.isSignedIn = this.user.isSignedIn;
  29. this.isGrafanaAdmin = this.user.isGrafanaAdmin;
  30. this.isEditor = this.hasRole('Editor') || this.hasRole('Admin');
  31. });
  32. });