From c8987a040c15547521e073d16cd7ed2e89d3016f Mon Sep 17 00:00:00 2001 From: "Grot (@grafanabot)" <43478413+grafanabot@users.noreply.github.com> Date: Fri, 15 Apr 2022 04:43:55 -0500 Subject: [PATCH] Navigation: Add shortcut to add new alert rule to alerting section behind feature toggle (#47713) (#47814) * Add new alert rule to alerting section * Check access control for ability to create (cherry picked from commit 7905957ee836e4aed96256189583a2037f311557) Co-authored-by: Ashley Harrison --- pkg/api/index.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/pkg/api/index.go b/pkg/api/index.go index 6f1bf97ee54..ab2c2270e7e 100644 --- a/pkg/api/index.go +++ b/pkg/api/index.go @@ -233,7 +233,7 @@ func (hs *HTTPServer) getNavTree(c *models.ReqContext, hasEditPerm bool) ([]*dto uaVisibleForOrg := hs.Cfg.UnifiedAlerting.IsEnabled() && !uaIsDisabledForOrg if setting.AlertingEnabled != nil && *setting.AlertingEnabled || uaVisibleForOrg { - navTree = append(navTree, hs.buildAlertNavLinks(c, uaVisibleForOrg)...) + navTree = append(navTree, hs.buildAlertNavLinks(c, uaVisibleForOrg, hasEditPerm)...) } appLinks, err := hs.getAppLinks(c) @@ -479,7 +479,7 @@ func (hs *HTTPServer) buildDashboardNavLinks(c *models.ReqContext, hasEditPerm b return dashboardChildNavs } -func (hs *HTTPServer) buildAlertNavLinks(c *models.ReqContext, uaVisibleForOrg bool) []*dtos.NavLink { +func (hs *HTTPServer) buildAlertNavLinks(c *models.ReqContext, uaVisibleForOrg bool, hasEditPerm bool) []*dtos.NavLink { hasAccess := ac.HasAccess(hs.AccessControl, c) var alertChildNavs []*dtos.NavLink @@ -516,6 +516,19 @@ func (hs *HTTPServer) buildAlertNavLinks(c *models.ReqContext, uaVisibleForOrg b }) } + if hs.Features.IsEnabled(featuremgmt.FlagNewNavigation) { + if uaVisibleForOrg && hasEditPerm && hasAccess(ac.ReqSignedIn, ac.EvalPermission(ac.ActionAlertingRuleCreate)) { + alertChildNavs = append(alertChildNavs, &dtos.NavLink{ + Text: "Divider", Divider: true, Id: "divider", HideFromTabs: true, + }) + + alertChildNavs = append(alertChildNavs, &dtos.NavLink{ + Text: "Alert rule", SubTitle: "Create an alert rule", Id: "alert", + Icon: "plus", Url: hs.Cfg.AppSubURL + "/alerting/new", HideFromTabs: true, ShowIconInNavbar: true, + }) + } + } + if len(alertChildNavs) > 0 { return []*dtos.NavLink{ {