mirror of https://github.com/grafana/grafana
Alerting: Improve alert list panel and alert rules toolbar permissions handling (#83954)
* Improve alert list panel and alert rules toolbar permissions handling * Refactor permission checking, add tests * Remove unneccessary act wrapper * Fix test errorpull/84072/head
parent
1181141b40
commit
a4acd9d204
@ -1,21 +1,29 @@ |
||||
import React from 'react'; |
||||
|
||||
import { config } from '@grafana/runtime'; |
||||
import { contextSrv } from 'app/core/services/context_srv'; |
||||
|
||||
import { addCustomRightAction } from '../../dashboard/components/DashNav/DashNav'; |
||||
|
||||
import { getRulesPermissions } from './utils/access-control'; |
||||
import { GRAFANA_RULES_SOURCE_NAME } from './utils/datasource'; |
||||
|
||||
const AlertRulesToolbarButton = React.lazy( |
||||
() => import(/* webpackChunkName: "alert-rules-toolbar-button" */ './integration/AlertRulesToolbarButton') |
||||
); |
||||
|
||||
export function initAlerting() { |
||||
addCustomRightAction({ |
||||
show: () => config.unifiedAlertingEnabled || (config.featureToggles.alertingPreviewUpgrade ?? false), |
||||
component: ({ dashboard }) => ( |
||||
<React.Suspense fallback={null} key="alert-rules-button"> |
||||
{dashboard && <AlertRulesToolbarButton dashboardUid={dashboard.uid} />} |
||||
</React.Suspense> |
||||
), |
||||
index: -2, |
||||
}); |
||||
const grafanaRulesPermissions = getRulesPermissions(GRAFANA_RULES_SOURCE_NAME); |
||||
|
||||
if (contextSrv.hasPermission(grafanaRulesPermissions.read)) { |
||||
addCustomRightAction({ |
||||
show: () => config.unifiedAlertingEnabled || (config.featureToggles.alertingPreviewUpgrade ?? false), |
||||
component: ({ dashboard }) => ( |
||||
<React.Suspense fallback={null} key="alert-rules-button"> |
||||
{dashboard && <AlertRulesToolbarButton dashboardUid={dashboard.uid} />} |
||||
</React.Suspense> |
||||
), |
||||
index: -2, |
||||
}); |
||||
} |
||||
} |
||||
|
Loading…
Reference in new issue