SupportBundles: Feature flag + access control navtree item (#62337)
* SupportBundles: Feature flag + access control navtree item * remove translation
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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<unkn
|
||||
|
||||
if (link.id === 'help') {
|
||||
link.children = [
|
||||
...menuItems,
|
||||
...getFooterLinks(),
|
||||
...getSupportBundleFooterLinks(),
|
||||
{
|
||||
id: 'keyboard-shortcuts',
|
||||
text: t('nav.help/keyboard-shortcuts', 'Keyboard shortcuts'),
|
||||
@@ -79,26 +78,6 @@ export const enrichConfigItems = (items: NavModelItem[], location: Location<unkn
|
||||
return items;
|
||||
};
|
||||
|
||||
export let getSupportBundleFooterLinks = (cfg = config): FooterLink[] => {
|
||||
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 = () => {
|
||||
|
||||
@@ -229,7 +229,6 @@
|
||||
"help/documentation": "Dokumentation",
|
||||
"help/keyboard-shortcuts": "Tastaturbefehle",
|
||||
"help/support": "Support",
|
||||
"help/support-bundle": "Support Bundles",
|
||||
"home": {
|
||||
"title": "Home"
|
||||
},
|
||||
|
||||
@@ -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"
|
||||
},
|
||||
|
||||
@@ -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"
|
||||
},
|
||||
|
||||
@@ -229,7 +229,6 @@
|
||||
"help/documentation": "Documentation",
|
||||
"help/keyboard-shortcuts": "Raccourcis clavier",
|
||||
"help/support": "Assistance",
|
||||
"help/support-bundle": "Packs d’assistance",
|
||||
"home": {
|
||||
"title": "Accueil"
|
||||
},
|
||||
|
||||
@@ -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ę"
|
||||
},
|
||||
|
||||
@@ -229,7 +229,6 @@
|
||||
"help/documentation": "文档",
|
||||
"help/keyboard-shortcuts": "快捷键",
|
||||
"help/support": "支持",
|
||||
"help/support-bundle": "",
|
||||
"home": {
|
||||
"title": "首页"
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user