From dbaf213f8ad7a24b92ee86962b2a4c22f84be497 Mon Sep 17 00:00:00 2001 From: Marcus Andersson Date: Thu, 5 Nov 2020 15:26:08 +0100 Subject: [PATCH] Variables: added __user.email to global variable (#28853) * added email to global variable. * forgot to increase the count. --- .../feature-templating/global-variables-and-interpolation.json | 2 +- docs/sources/variables/variable-types/global-variables.md | 1 + e2e/suite1/specs/dashboard-templating.spec.ts | 3 ++- public/app/core/services/context_srv.ts | 1 + public/app/features/variables/state/actions.ts | 1 + public/app/features/variables/types.ts | 1 + 6 files changed, 7 insertions(+), 2 deletions(-) diff --git a/devenv/dev-dashboards/feature-templating/global-variables-and-interpolation.json b/devenv/dev-dashboards/feature-templating/global-variables-and-interpolation.json index 86aae9c58bf..4f1ab116d58 100644 --- a/devenv/dev-dashboards/feature-templating/global-variables-and-interpolation.json +++ b/devenv/dev-dashboards/feature-templating/global-variables-and-interpolation.json @@ -34,7 +34,7 @@ }, "id": 11, "options": { - "content": "## Global variables\n\n* `__dashboard` = `${__dashboard}`\n* `__dashboard.name` = `${__dashboard.name}`\n* `__dashboard.uid` = `${__dashboard.uid}`\n* `__org.name` = `${__org.name}`\n* `__org.id` = `${__org.id}`\n* `__user.id` = `${__user.id}`\n* `__user.login` = `${__user.login}`\n \n## Formats\n\n* `Server:raw` = `${Server:raw}`\n* `Server:regex` = `${Server:regex}`\n* `Server:lucene` = `${Server:lucene}`\n* `Server:glob` = `${Server:glob}`\n* `Server:pipe` = `${Server:pipe}`\n* `Server:distributed` = `${Server:distributed}`\n* `Server:csv` = `${Server:csv}`\n* `Server:html` = `${Server:html}`\n* `Server:json` = `${Server:json}`\n* `Server:percentencode` = `${Server:percentencode}`\n* `Server:singlequote` = `${Server:singlequote}`\n* `Server:doublequote` = `${Server:doublequote}`\n* `Server:sqlstring` = `${Server:sqlstring}`\n* `Server:date` = `${Server:date}`\n* `Server:text` = `${Server:text}`\n\n", + "content": "## Global variables\n\n* `__dashboard` = `${__dashboard}`\n* `__dashboard.name` = `${__dashboard.name}`\n* `__dashboard.uid` = `${__dashboard.uid}`\n* `__org.name` = `${__org.name}`\n* `__org.id` = `${__org.id}`\n* `__user.id` = `${__user.id}`\n* `__user.login` = `${__user.login}`\n* `__user.email` = `${__user.email}`\n \n## Formats\n\n* `Server:raw` = `${Server:raw}`\n* `Server:regex` = `${Server:regex}`\n* `Server:lucene` = `${Server:lucene}`\n* `Server:glob` = `${Server:glob}`\n* `Server:pipe` = `${Server:pipe}`\n* `Server:distributed` = `${Server:distributed}`\n* `Server:csv` = `${Server:csv}`\n* `Server:html` = `${Server:html}`\n* `Server:json` = `${Server:json}`\n* `Server:percentencode` = `${Server:percentencode}`\n* `Server:singlequote` = `${Server:singlequote}`\n* `Server:doublequote` = `${Server:doublequote}`\n* `Server:sqlstring` = `${Server:sqlstring}`\n* `Server:date` = `${Server:date}`\n* `Server:text` = `${Server:text}`\n\n", "mode": "markdown" }, "pluginVersion": "7.1.0", diff --git a/docs/sources/variables/variable-types/global-variables.md b/docs/sources/variables/variable-types/global-variables.md index 13f2b0aa994..4a43b974837 100644 --- a/docs/sources/variables/variable-types/global-variables.md +++ b/docs/sources/variables/variable-types/global-variables.md @@ -70,6 +70,7 @@ This variable is the ID of the current organization. `${__user.id}` is the ID of the current user. `${__user.login}` is the login handle of the current user. +`${__user.email}` is the email for the current user. ## $__range diff --git a/e2e/suite1/specs/dashboard-templating.spec.ts b/e2e/suite1/specs/dashboard-templating.spec.ts index 87e30ba2677..4d8a6669825 100644 --- a/e2e/suite1/specs/dashboard-templating.spec.ts +++ b/e2e/suite1/specs/dashboard-templating.spec.ts @@ -19,6 +19,7 @@ e2e.scenario({ '__org.id = 1', '__user.id = 1', '__user.login = admin', + '__user.email = admin@localhost', `Server:raw = A'A"A,BB\\B,CCC`, `Server:regex = (A'A"A|BB\\\\B|CCC)`, `Server:lucene = ("A'A\\"A" OR "BB\\\\B" OR "CCC")`, @@ -38,7 +39,7 @@ e2e.scenario({ e2e() .get('.markdown-html li') - .should('have.length', 22) + .should('have.length', 23) .each(element => { items.push(element.text()); }) diff --git a/public/app/core/services/context_srv.ts b/public/app/core/services/context_srv.ts index 16f566ffdd5..c65d763270d 100644 --- a/public/app/core/services/context_srv.ts +++ b/public/app/core/services/context_srv.ts @@ -16,6 +16,7 @@ export class User { helpFlags1: number; lightTheme: boolean; hasEditPermissionInFolders: boolean; + email?: string; constructor() { if (config.bootData.user) { diff --git a/public/app/features/variables/state/actions.ts b/public/app/features/variables/state/actions.ts index a68c4cb595d..caf890cb826 100644 --- a/public/app/features/variables/state/actions.ts +++ b/public/app/features/variables/state/actions.ts @@ -161,6 +161,7 @@ export const addSystemTemplateVariables = (dashboard: DashboardModel): ThunkResu value: { login: contextSrv.user.login, id: contextSrv.user.id, + email: contextSrv.user.email, toString: () => contextSrv.user.id.toString(), }, }, diff --git a/public/app/features/variables/types.ts b/public/app/features/variables/types.ts index 357c283f167..ef5185e2475 100644 --- a/public/app/features/variables/types.ts +++ b/public/app/features/variables/types.ts @@ -110,6 +110,7 @@ export interface OrgVariableModel extends SystemVariable {} export interface UserProps { login: string; id: number; + email?: string; toString: () => string; }