mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Templating: Add bult in __user {name, id, login, email} variable to templating system (#23378)
* Updated templating code to support the $__user variable to expose the current userid, username, email and login. Fixed the $__org variable as it was returning the user id instead of the ordId. Updated the documentation to match * Updated solution to retrieving $__user variables to pull directly from user record (thereby allowing future access to properties that might not exist in the contextSvr). Replicated this initialisation in the variables feature Corrected typo's in documentation. * Repaired typecheck issues. * Updated patch to pull entirely from contextSrv without API calls. * ... And removed the redundant comments. * Updated documentation.
This commit is contained in:
parent
10158c90e3
commit
f98e176d7b
@ -15,6 +15,8 @@ export class User {
|
||||
timezone: string;
|
||||
helpFlags1: number;
|
||||
lightTheme: boolean;
|
||||
name?: string;
|
||||
email?: string;
|
||||
hasEditPermissionInFolders: boolean;
|
||||
|
||||
constructor() {
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
},
|
||||
},
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user