2017-12-20 05:33:33 -06:00
|
|
|
import config from 'app/core/config';
|
|
|
|
import _ from 'lodash';
|
|
|
|
import coreModule from 'app/core/core_module';
|
2016-04-03 07:27:35 -05:00
|
|
|
|
|
|
|
export class User {
|
2019-03-12 07:46:52 -05:00
|
|
|
id: number;
|
2016-04-03 07:27:35 -05:00
|
|
|
isGrafanaAdmin: any;
|
|
|
|
isSignedIn: any;
|
|
|
|
orgRole: any;
|
2017-08-16 08:37:13 -05:00
|
|
|
orgId: number;
|
2018-09-04 10:24:08 -05:00
|
|
|
orgName: string;
|
2019-12-05 01:30:39 -06:00
|
|
|
login: string;
|
2018-09-04 10:24:08 -05:00
|
|
|
orgCount: number;
|
2016-09-19 04:34:08 -05:00
|
|
|
timezone: string;
|
2016-11-09 03:41:39 -06:00
|
|
|
helpFlags1: number;
|
2017-03-31 10:12:50 -05:00
|
|
|
lightTheme: boolean;
|
2018-04-30 08:38:46 -05:00
|
|
|
hasEditPermissionInFolders: boolean;
|
2016-04-03 07:27:35 -05:00
|
|
|
|
|
|
|
constructor() {
|
|
|
|
if (config.bootData.user) {
|
|
|
|
_.extend(this, config.bootData.user);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class ContextSrv {
|
|
|
|
pinned: any;
|
|
|
|
version: any;
|
|
|
|
user: User;
|
|
|
|
isSignedIn: any;
|
|
|
|
isGrafanaAdmin: any;
|
|
|
|
isEditor: any;
|
2017-12-04 05:37:00 -06:00
|
|
|
sidemenuSmallBreakpoint = false;
|
2018-04-30 08:38:46 -05:00
|
|
|
hasEditPermissionInFolders: boolean;
|
2016-04-03 07:27:35 -05:00
|
|
|
|
|
|
|
constructor() {
|
2016-04-03 09:12:43 -05:00
|
|
|
if (!config.bootData) {
|
2017-12-19 09:06:54 -06:00
|
|
|
config.bootData = { user: {}, settings: {} };
|
2016-04-03 09:12:43 -05:00
|
|
|
}
|
|
|
|
|
2016-04-03 07:27:35 -05:00
|
|
|
this.user = new User();
|
|
|
|
this.isSignedIn = this.user.isSignedIn;
|
|
|
|
this.isGrafanaAdmin = this.user.isGrafanaAdmin;
|
2017-12-20 05:33:33 -06:00
|
|
|
this.isEditor = this.hasRole('Editor') || this.hasRole('Admin');
|
2018-04-30 08:38:46 -05:00
|
|
|
this.hasEditPermissionInFolders = this.user.hasEditPermissionInFolders;
|
2016-04-03 07:27:35 -05:00
|
|
|
}
|
|
|
|
|
2019-04-28 02:58:12 -05:00
|
|
|
hasRole(role: string) {
|
2016-04-03 07:27:35 -05:00
|
|
|
return this.user.orgRole === role;
|
|
|
|
}
|
|
|
|
|
2017-01-11 12:46:34 -06:00
|
|
|
isGrafanaVisible() {
|
2017-12-21 01:39:31 -06:00
|
|
|
return !!(document.visibilityState === undefined || document.visibilityState === 'visible');
|
2017-01-11 12:46:34 -06:00
|
|
|
}
|
|
|
|
|
2019-01-21 03:50:34 -06:00
|
|
|
hasAccessToExplore() {
|
|
|
|
return (this.isEditor || config.viewersCanEdit) && config.exploreEnabled;
|
|
|
|
}
|
2016-04-03 07:27:35 -05:00
|
|
|
}
|
|
|
|
|
2018-08-29 07:26:50 -05:00
|
|
|
const contextSrv = new ContextSrv();
|
2017-12-19 09:06:54 -06:00
|
|
|
export { contextSrv };
|
2016-04-03 07:27:35 -05:00
|
|
|
|
2018-09-04 10:02:32 -05:00
|
|
|
coreModule.factory('contextSrv', () => {
|
2016-04-03 07:27:35 -05:00
|
|
|
return contextSrv;
|
|
|
|
});
|