Replies: 1 comment 1 reply
-
You could fetch the user team directly in the panel (https://gapit-htmlgraphics-panel.gapit.io/docs/guides/send-post-requests-through-grafana/#get-requests-through-localhost) fetch("/api/user/teams") I've made a small program that adds the team the user is in at the end of the URL. This could be modified to redirect to a different dashboard or something.
{
"calcsMutation": "standard",
"reduceOptions": {
"calcs": [
"lastNotNull",
"last",
"firstNotNull",
"first",
"min",
"max",
"mean",
"sum",
"count",
"range",
"delta",
"step",
"diff",
"logmin",
"allIsZero",
"allIsNull",
"diffperc"
]
},
"SVGBaseFix": true,
"add100Percentage": true,
"centerAlignContent": true,
"overflow": "visible",
"useGrafanaScrollbar": true,
"rootCSS": "",
"css": "* {\n font-family: Open Sans;\n}\n\n.box {\n border: solid #555 2px;\n border-radius: 10px;\n padding: 10px 20px;\n}\n",
"html": "<div></div>",
"renderOnMount": true,
"onRender": "",
"panelupdateOnMount": true,
"dynamicHtmlGraphics": false,
"dynamicData": false,
"dynamicFieldDisplayValues": false,
"dynamicProps": false,
"onInitOnResize": false,
"onInit": "const elt = htmlNode.querySelector(\"div\");\n\nfunction addTeamNameToUrl(teamName) {\n\n const url = new URL(location.href);\n const currentTeamParam = url.searchParams.get(\"team\");\n\n if (currentTeamParam !== teamName) {\n url.searchParams.set(\"team\", teamName);\n history.pushState({}, \"\", url);\n }\n}\n\nfetch(\"/api/user/teams\")\n .then((res) => {\n return res.json();\n })\n .then((json) => {\n if (json.length > 0) {\n // Use the first team\n const teamName = json[0].name;\n elt.textContent = \"User is part of team: \" + teamName;\n addTeamNameToUrl(teamName);\n } else {\n elt.textContent = \"User is not in any team\";\n }\n })\n .catch((error) => {\n console.error(error);\n });\n\n",
"codeData": "{\n \"text\": \"Random text\"\n}"
} |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
To start with, I apologize, but I read thru the Send POST requests through Grafana documentation, but I could not translate what I am trying to do to the examples (likely due to a gap in my technical knowledge).
We are using Grafana Teams to segregate access to portions of our installation to various groups who need to be restricted to viewing only data pertaining to their area. In order to either properly route a user to a specific landing page for their Team or, for executives over more than one Team, to present them with a "selector" page to take them to the landing page for the Team they are currently interested in, per Grafana, I need to use the User HTTP API
/api/user/teams
(see Teams that the actual User is member of for the API details).This was where my comprehension reading the documentation of how to call the API failed. Can you provide some guidance on at least which section of your documentation I should be looking at and perhaps (if it's not asking too much) what the function structure would be for this specific API? We do have the JSON API plugin installed if it's needed, but do we need to define a data source to call a Grafana API? Or is there a more direct method?
Thank you VERY much!
Beta Was this translation helpful? Give feedback.
All reactions