From 6c990b461e4650effbfddb1fc9264bb6ad4d726a Mon Sep 17 00:00:00 2001 From: Josh Hunt Date: Fri, 27 Jan 2023 20:04:04 +0000 Subject: [PATCH] SupportBundles: Feature flag + access control navtree item (#62337) * SupportBundles: Feature flag + access control navtree item * remove translation --- pkg/services/navtree/navtreeimpl/navtree.go | 42 +++++++++++++++------ public/app/core/components/NavBar/utils.ts | 25 +----------- public/locales/de-DE/grafana.json | 1 - public/locales/en-US/grafana.json | 3 +- public/locales/es-ES/grafana.json | 1 - public/locales/fr-FR/grafana.json | 1 - public/locales/pseudo-LOCALE/grafana.json | 3 +- public/locales/zh-Hans/grafana.json | 1 - 8 files changed, 34 insertions(+), 43 deletions(-) diff --git a/pkg/services/navtree/navtreeimpl/navtree.go b/pkg/services/navtree/navtreeimpl/navtree.go index 57c6097614c..e81d1c82ade 100644 --- a/pkg/services/navtree/navtreeimpl/navtree.go +++ b/pkg/services/navtree/navtreeimpl/navtree.go @@ -20,6 +20,7 @@ import ( pref "github.com/grafana/grafana/pkg/services/preference" "github.com/grafana/grafana/pkg/services/querylibrary" "github.com/grafana/grafana/pkg/services/star" + "github.com/grafana/grafana/pkg/services/supportbundles/supportbundlesimpl" "github.com/grafana/grafana/pkg/setting" ) @@ -232,6 +233,11 @@ func (s *ServiceImpl) getHomeNode(c *contextmodel.ReqContext, prefs *pref.Prefer return homeNode } +func isSupportBundlesEnabled(s *ServiceImpl) bool { + return s.cfg.SectionWithEnvOverrides("support_bundles").Key("enabled").MustBool(false) && + s.features.IsEnabled(featuremgmt.FlagSupportBundles) +} + func (s *ServiceImpl) addHelpLinks(treeRoot *navtree.NavTreeRoot, c *contextmodel.ReqContext) { if setting.HelpEnabled { helpVersion := fmt.Sprintf(`%s v%s (%s)`, setting.ApplicationName, setting.BuildVersion, setting.BuildCommit) @@ -239,16 +245,7 @@ func (s *ServiceImpl) addHelpLinks(treeRoot *navtree.NavTreeRoot, c *contextmode helpVersion = setting.ApplicationName } - supportBundleNode := &navtree.NavLink{ - Text: "Support bundles", - Id: "support-bundles", - Url: "/support-bundles", - Icon: "wrench", - Section: navtree.NavSectionConfig, - SortWeight: navtree.WeightHelp, - } - - treeRoot.AddSection(&navtree.NavLink{ + helpNode := &navtree.NavLink{ Text: "Help", SubTitle: helpVersion, Id: "help", @@ -256,8 +253,29 @@ func (s *ServiceImpl) addHelpLinks(treeRoot *navtree.NavTreeRoot, c *contextmode Icon: "question-circle", SortWeight: navtree.WeightHelp, Section: navtree.NavSectionConfig, - Children: []*navtree.NavLink{supportBundleNode}, - }) + Children: []*navtree.NavLink{}, + } + + treeRoot.AddSection(helpNode) + + hasAccess := ac.HasAccess(s.accessControl, c) + supportBundleAccess := ac.EvalAny( + ac.EvalPermission(supportbundlesimpl.ActionRead), + ac.EvalPermission(supportbundlesimpl.ActionCreate), + ) + + if isSupportBundlesEnabled(s) && hasAccess(ac.ReqGrafanaAdmin, supportBundleAccess) { + supportBundleNode := &navtree.NavLink{ + Text: "Support bundles", + Id: "support-bundles", + Url: "/support-bundles", + Icon: "wrench", + Section: navtree.NavSectionConfig, + SortWeight: navtree.WeightHelp, + } + + helpNode.Children = append(helpNode.Children, supportBundleNode) + } } } diff --git a/public/app/core/components/NavBar/utils.ts b/public/app/core/components/NavBar/utils.ts index eef4c0cece1..df94b105376 100644 --- a/public/app/core/components/NavBar/utils.ts +++ b/public/app/core/components/NavBar/utils.ts @@ -4,11 +4,10 @@ import { locationUtil, NavModelItem, NavSection } from '@grafana/data'; import { config, reportInteraction } from '@grafana/runtime'; import { t } from 'app/core/internationalization'; import { contextSrv } from 'app/core/services/context_srv'; -import { AccessControlAction } from 'app/types'; import { ShowModalReactEvent } from '../../../types/events'; import appEvents from '../../app_events'; -import { FooterLink, getFooterLinks } from '../Footer/Footer'; +import { getFooterLinks } from '../Footer/Footer'; import { OrgSwitcher } from '../OrgSwitcher'; import { HelpModal } from '../help/HelpModal'; @@ -53,8 +52,8 @@ export const enrichConfigItems = (items: NavModelItem[], location: Location { - const hasAccess = - contextSrv.hasAccess(AccessControlAction.ActionSupportBundlesCreate, contextSrv.isGrafanaAdmin) || - contextSrv.hasAccess(AccessControlAction.ActionSupportBundlesRead, contextSrv.isGrafanaAdmin); - - if (!cfg.supportBundlesEnabled || !hasAccess) { - return []; - } - - return [ - { - target: '_self', - id: 'support-bundle', - text: t('nav.help/support-bundle', 'Support Bundles'), - icon: 'question-circle', - url: '/support-bundles', - }, - ]; -}; - export const enrichWithInteractionTracking = (item: NavModelItem, expandedState: boolean) => { const onClick = item.onClick; item.onClick = () => { diff --git a/public/locales/de-DE/grafana.json b/public/locales/de-DE/grafana.json index 7938d1ed771..03a1590e4e1 100644 --- a/public/locales/de-DE/grafana.json +++ b/public/locales/de-DE/grafana.json @@ -229,7 +229,6 @@ "help/documentation": "Dokumentation", "help/keyboard-shortcuts": "Tastaturbefehle", "help/support": "Support", - "help/support-bundle": "Support Bundles", "home": { "title": "Home" }, diff --git a/public/locales/en-US/grafana.json b/public/locales/en-US/grafana.json index 4450f5977a4..ce504e80bb7 100644 --- a/public/locales/en-US/grafana.json +++ b/public/locales/en-US/grafana.json @@ -13,7 +13,7 @@ "search": "Search" }, "search-box": { - "placeholder": "Search or jump to..." + "placeholder": "Search Grafana" }, "section": { "actions": "Actions", @@ -229,7 +229,6 @@ "help/documentation": "Documentation", "help/keyboard-shortcuts": "Keyboard shortcuts", "help/support": "Support", - "help/support-bundle": "Support Bundles", "home": { "title": "Home" }, diff --git a/public/locales/es-ES/grafana.json b/public/locales/es-ES/grafana.json index a921571d27b..67b51a2fc28 100644 --- a/public/locales/es-ES/grafana.json +++ b/public/locales/es-ES/grafana.json @@ -229,7 +229,6 @@ "help/documentation": "Documentación", "help/keyboard-shortcuts": "Atajos de teclado", "help/support": "Asistencia", - "help/support-bundle": "Paquetes de apoyo", "home": { "title": "Inicio" }, diff --git a/public/locales/fr-FR/grafana.json b/public/locales/fr-FR/grafana.json index 753dcced8d3..579ecc1b245 100644 --- a/public/locales/fr-FR/grafana.json +++ b/public/locales/fr-FR/grafana.json @@ -229,7 +229,6 @@ "help/documentation": "Documentation", "help/keyboard-shortcuts": "Raccourcis clavier", "help/support": "Assistance", - "help/support-bundle": "Packs d’assistance", "home": { "title": "Accueil" }, diff --git a/public/locales/pseudo-LOCALE/grafana.json b/public/locales/pseudo-LOCALE/grafana.json index 9b900ef8d2f..57932f6f053 100644 --- a/public/locales/pseudo-LOCALE/grafana.json +++ b/public/locales/pseudo-LOCALE/grafana.json @@ -13,7 +13,7 @@ "search": "Ŝęäřčĥ" }, "search-box": { - "placeholder": "Ŝęäřčĥ őř ĵūmp ŧő..." + "placeholder": "Ŝęäřčĥ Ğřäƒäʼnä" }, "section": { "actions": "Åčŧįőʼnş", @@ -229,7 +229,6 @@ "help/documentation": "Đőčūmęʼnŧäŧįőʼn", "help/keyboard-shortcuts": "Ķęyþőäřđ şĥőřŧčūŧş", "help/support": "Ŝūppőřŧ", - "help/support-bundle": "Ŝūppőřŧ ßūʼnđľęş", "home": { "title": "Ħőmę" }, diff --git a/public/locales/zh-Hans/grafana.json b/public/locales/zh-Hans/grafana.json index cd6416ae13f..442a0ebc52d 100644 --- a/public/locales/zh-Hans/grafana.json +++ b/public/locales/zh-Hans/grafana.json @@ -229,7 +229,6 @@ "help/documentation": "文档", "help/keyboard-shortcuts": "快捷键", "help/support": "支持", - "help/support-bundle": "", "home": { "title": "首页" },