mirror of
https://github.com/grafana/grafana.git
synced 2025-09-28 17:24:11 +08:00

* add FGAC actions for silences table * redirect users without permissions * hide silence button in rules list * add permissions checks to routes * add read action for silences page * add permissions checks to navigation * add additional access checks for rule viewing * create authorize component * add tests for silences * hide alerting nav for users without access * nolint: gocyclo * add permission check to alert details * add check for external instances * remove unecessary new lines * use correct actions for alert details * fix failing tests Co-authored-by: Yuriy Tseretyan <yuriy.tseretyan@grafana.com>
238 lines
8.0 KiB
TypeScript
238 lines
8.0 KiB
TypeScript
import React from 'react';
|
|
import { Redirect } from 'react-router-dom';
|
|
import { SafeDynamicImport } from 'app/core/components/DynamicImports/SafeDynamicImport';
|
|
import { config } from 'app/core/config';
|
|
import { RouteDescriptor } from 'app/core/navigation/types';
|
|
import { uniq } from 'lodash';
|
|
import { contextSrv } from 'app/core/core';
|
|
import { AccessControlAction } from 'app/types';
|
|
|
|
const commonRoutes: RouteDescriptor[] = [
|
|
{
|
|
path: '/alerting',
|
|
// eslint-disable-next-line react/display-name
|
|
component: () => <Redirect to="/alerting/list" />,
|
|
},
|
|
];
|
|
|
|
const legacyRoutes: RouteDescriptor[] = [
|
|
...commonRoutes,
|
|
{
|
|
path: '/alerting/list',
|
|
component: SafeDynamicImport(
|
|
() => import(/* webpackChunkName: "AlertRuleListIndex" */ 'app/features/alerting/AlertRuleList')
|
|
),
|
|
},
|
|
{
|
|
path: '/alerting/ng/list',
|
|
component: SafeDynamicImport(
|
|
() => import(/* webpackChunkName: "AlertRuleList" */ 'app/features/alerting/AlertRuleList')
|
|
),
|
|
},
|
|
{
|
|
path: '/alerting/notifications',
|
|
roles: config.unifiedAlertingEnabled ? () => ['Editor', 'Admin'] : undefined,
|
|
component: SafeDynamicImport(
|
|
() => import(/* webpackChunkName: "NotificationsListPage" */ 'app/features/alerting/NotificationsListPage')
|
|
),
|
|
},
|
|
{
|
|
path: '/alerting/notifications/templates/new',
|
|
roles: () => ['Editor', 'Admin'],
|
|
component: SafeDynamicImport(
|
|
() => import(/* webpackChunkName: "NotificationsListPage" */ 'app/features/alerting/NotificationsListPage')
|
|
),
|
|
},
|
|
{
|
|
path: '/alerting/notifications/templates/:id/edit',
|
|
roles: () => ['Editor', 'Admin'],
|
|
component: SafeDynamicImport(
|
|
() => import(/* webpackChunkName: "NotificationsListPage" */ 'app/features/alerting/NotificationsListPage')
|
|
),
|
|
},
|
|
{
|
|
path: '/alerting/notifications/receivers/new',
|
|
roles: () => ['Editor', 'Admin'],
|
|
component: SafeDynamicImport(
|
|
() => import(/* webpackChunkName: "NotificationsListPage" */ 'app/features/alerting/NotificationsListPage')
|
|
),
|
|
},
|
|
{
|
|
path: '/alerting/notifications/receivers/:id/edit',
|
|
roles: () => ['Editor', 'Admin'],
|
|
component: SafeDynamicImport(
|
|
() => import(/* webpackChunkName: "NotificationsListPage" */ 'app/features/alerting/NotificationsListPage')
|
|
),
|
|
},
|
|
{
|
|
path: '/alerting/notifications/global-config',
|
|
roles: () => ['Admin', 'Editor'],
|
|
component: SafeDynamicImport(
|
|
() => import(/* webpackChunkName: "NotificationsListPage" */ 'app/features/alerting/NotificationsListPage')
|
|
),
|
|
},
|
|
{
|
|
path: '/alerting/notification/new',
|
|
component: SafeDynamicImport(
|
|
() => import(/* webpackChunkName: "NewNotificationChannel" */ 'app/features/alerting/NewNotificationChannelPage')
|
|
),
|
|
},
|
|
{
|
|
path: '/alerting/notification/:id/edit',
|
|
component: SafeDynamicImport(
|
|
() => import(/* webpackChunkName: "EditNotificationChannel"*/ 'app/features/alerting/EditNotificationChannelPage')
|
|
),
|
|
},
|
|
];
|
|
|
|
const unifiedRoutes: RouteDescriptor[] = [
|
|
...commonRoutes,
|
|
{
|
|
path: '/alerting/list',
|
|
component: SafeDynamicImport(
|
|
() => import(/* webpackChunkName: "AlertRuleListIndex" */ 'app/features/alerting/unified/RuleList')
|
|
),
|
|
},
|
|
{
|
|
path: '/alerting/routes',
|
|
roles: () => ['Admin', 'Editor'],
|
|
component: SafeDynamicImport(
|
|
() => import(/* webpackChunkName: "AlertAmRoutes" */ 'app/features/alerting/unified/AmRoutes')
|
|
),
|
|
},
|
|
{
|
|
path: '/alerting/routes/mute-timing/new',
|
|
roles: () => ['Admin', 'Editor'],
|
|
component: SafeDynamicImport(
|
|
() => import(/* webpackChunkName: "MuteTimings" */ 'app/features/alerting/unified/MuteTimings')
|
|
),
|
|
},
|
|
{
|
|
path: '/alerting/routes/mute-timing/edit',
|
|
roles: () => ['Admin', 'Editor'],
|
|
component: SafeDynamicImport(
|
|
() => import(/* webpackChunkName: "MuteTimings" */ 'app/features/alerting/unified/MuteTimings')
|
|
),
|
|
},
|
|
{
|
|
path: '/alerting/silences',
|
|
roles: () => contextSrv.evaluatePermission(() => [], [AccessControlAction.AlertingInstanceRead]),
|
|
component: SafeDynamicImport(
|
|
() => import(/* webpackChunkName: "AlertSilences" */ 'app/features/alerting/unified/Silences')
|
|
),
|
|
},
|
|
{
|
|
path: '/alerting/silence/new',
|
|
roles: () => contextSrv.evaluatePermission(() => ['Editor', 'Admin'], [AccessControlAction.AlertingInstanceCreate]),
|
|
component: SafeDynamicImport(
|
|
() => import(/* webpackChunkName: "AlertSilences" */ 'app/features/alerting/unified/Silences')
|
|
),
|
|
},
|
|
{
|
|
path: '/alerting/silence/:id/edit',
|
|
roles: () => contextSrv.evaluatePermission(() => ['Editor', 'Admin'], [AccessControlAction.AlertingInstanceUpdate]),
|
|
component: SafeDynamicImport(
|
|
() => import(/* webpackChunkName: "AlertSilences" */ 'app/features/alerting/unified/Silences')
|
|
),
|
|
},
|
|
{
|
|
path: '/alerting/notifications',
|
|
roles: config.unifiedAlertingEnabled ? () => ['Editor', 'Admin'] : undefined,
|
|
component: SafeDynamicImport(
|
|
() => import(/* webpackChunkName: "NotificationsListPage" */ 'app/features/alerting/unified/Receivers')
|
|
),
|
|
},
|
|
{
|
|
path: '/alerting/notifications/templates/new',
|
|
roles: () => ['Editor', 'Admin'],
|
|
component: SafeDynamicImport(
|
|
() => import(/* webpackChunkName: "NotificationsListPage" */ 'app/features/alerting/unified/Receivers')
|
|
),
|
|
},
|
|
{
|
|
path: '/alerting/notifications/templates/:id/edit',
|
|
roles: () => ['Editor', 'Admin'],
|
|
component: SafeDynamicImport(
|
|
() => import(/* webpackChunkName: "NotificationsListPage" */ 'app/features/alerting/unified/Receivers')
|
|
),
|
|
},
|
|
{
|
|
path: '/alerting/notifications/receivers/new',
|
|
roles: () => ['Editor', 'Admin'],
|
|
component: SafeDynamicImport(
|
|
() => import(/* webpackChunkName: "NotificationsListPage" */ 'app/features/alerting/unified/Receivers')
|
|
),
|
|
},
|
|
{
|
|
path: '/alerting/notifications/receivers/:id/edit',
|
|
roles: () => ['Editor', 'Admin'],
|
|
component: SafeDynamicImport(
|
|
() => import(/* webpackChunkName: "NotificationsListPage" */ 'app/features/alerting/unified/Receivers')
|
|
),
|
|
},
|
|
{
|
|
path: '/alerting/notifications/global-config',
|
|
roles: () => ['Admin', 'Editor'],
|
|
component: SafeDynamicImport(
|
|
() => import(/* webpackChunkName: "NotificationsListPage" */ 'app/features/alerting/unified/Receivers')
|
|
),
|
|
},
|
|
{
|
|
path: '/alerting/groups/',
|
|
component: SafeDynamicImport(
|
|
() => import(/* webpackChunkName: "AlertGroups" */ 'app/features/alerting/unified/AlertGroups')
|
|
),
|
|
},
|
|
{
|
|
path: '/alerting/new',
|
|
pageClass: 'page-alerting',
|
|
component: SafeDynamicImport(
|
|
() => import(/* webpackChunkName: "AlertingRuleForm"*/ 'app/features/alerting/unified/RuleEditor')
|
|
),
|
|
},
|
|
{
|
|
path: '/alerting/:id/edit',
|
|
pageClass: 'page-alerting',
|
|
component: SafeDynamicImport(
|
|
() => import(/* webpackChunkName: "AlertingRuleForm"*/ 'app/features/alerting/unified/RuleEditor')
|
|
),
|
|
},
|
|
{
|
|
path: '/alerting/:sourceName/:id/view',
|
|
pageClass: 'page-alerting',
|
|
component: SafeDynamicImport(
|
|
() => import(/* webpackChunkName: "AlertingRule"*/ 'app/features/alerting/unified/RuleViewer')
|
|
),
|
|
},
|
|
{
|
|
path: '/alerting/:sourceName/:name/find',
|
|
pageClass: 'page-alerting',
|
|
component: SafeDynamicImport(
|
|
() => import(/* webpackChunkName: "AlertingRedirectToRule"*/ 'app/features/alerting/unified/RedirectToRuleViewer')
|
|
),
|
|
},
|
|
{
|
|
path: '/alerting/admin',
|
|
roles: () => ['Admin'],
|
|
component: SafeDynamicImport(
|
|
() => import(/* webpackChunkName: "AlertingAdmin" */ 'app/features/alerting/unified/Admin')
|
|
),
|
|
},
|
|
];
|
|
|
|
export function getAlertingRoutes(cfg = config): RouteDescriptor[] {
|
|
if (cfg.unifiedAlertingEnabled) {
|
|
return unifiedRoutes;
|
|
} else if (cfg.alertingEnabled) {
|
|
return legacyRoutes;
|
|
}
|
|
|
|
const uniquePaths = uniq([...legacyRoutes, ...unifiedRoutes].map((route) => route.path));
|
|
return uniquePaths.map((path) => ({
|
|
path,
|
|
component: SafeDynamicImport(
|
|
() => import(/* webpackChunkName: "Alerting feature toggle page"*/ 'app/features/alerting/FeatureTogglePage')
|
|
),
|
|
}));
|
|
}
|