diff --git a/public/app/core/services/context_srv.ts b/public/app/core/services/context_srv.ts index b6a3c8f08cc..e3edac66205 100644 --- a/public/app/core/services/context_srv.ts +++ b/public/app/core/services/context_srv.ts @@ -15,6 +15,8 @@ export class User { timezone: string; helpFlags1: number; lightTheme: boolean; + name?: string; + email?: string; hasEditPermissionInFolders: boolean; constructor() { diff --git a/public/app/features/templating/variable_srv.ts b/public/app/features/templating/variable_srv.ts index 33b399e634c..10cbd2dcb17 100644 --- a/public/app/features/templating/variable_srv.ts +++ b/public/app/features/templating/variable_srv.ts @@ -8,6 +8,7 @@ import { Graph } from 'app/core/utils/dag'; import { TemplateSrv } from 'app/features/templating/template_srv'; import { TimeSrv } from 'app/features/dashboard/services/TimeSrv'; import { DashboardModel } from 'app/features/dashboard/state/DashboardModel'; + // Types import { AppEvents, TimeRange, UrlQueryMap } from '@grafana/data'; import { CoreEvents } from 'app/types'; @@ -64,6 +65,17 @@ export class VariableSrv { this.templateSrv.setGlobalVariable('__org', { value: { name: contextSrv.user.orgName, + id: contextSrv.user.orgId, + toString: function() { + return this.id; + }, + }, + }); + this.templateSrv.setGlobalVariable('__user', { + value: { + name: contextSrv.user.name, + login: contextSrv.user.login, + email: contextSrv.user.email, id: contextSrv.user.id, toString: function() { return this.id; diff --git a/public/app/features/variables/state/actions.ts b/public/app/features/variables/state/actions.ts index 89abbf91a01..f00fc37efbb 100644 --- a/public/app/features/variables/state/actions.ts +++ b/public/app/features/variables/state/actions.ts @@ -102,6 +102,17 @@ export const completeDashboardTemplating = (dashboard: DashboardModel): ThunkRes }, }, }); + templateSrv.setGlobalVariable('__user', { + value: { + name: contextSrv.user.name, + login: contextSrv.user.login, + email: contextSrv.user.email, + id: contextSrv.user.id, + toString: function() { + return this.id; + }, + }, + }); }; };