routes.tsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. import { uniq } from 'lodash';
  2. import React from 'react';
  3. import { Redirect } from 'react-router-dom';
  4. import { OrgRole } from '@grafana/data';
  5. import { SafeDynamicImport } from 'app/core/components/DynamicImports/SafeDynamicImport';
  6. import { config } from 'app/core/config';
  7. import { RouteDescriptor } from 'app/core/navigation/types';
  8. import { AccessControlAction } from 'app/types';
  9. import { evaluateAccess } from './unified/utils/access-control';
  10. const commonRoutes: RouteDescriptor[] = [
  11. {
  12. path: '/alerting',
  13. // eslint-disable-next-line react/display-name
  14. component: () => <Redirect to="/alerting/list" />,
  15. },
  16. ];
  17. const legacyRoutes: RouteDescriptor[] = [
  18. ...commonRoutes,
  19. {
  20. path: '/alerting/list',
  21. component: SafeDynamicImport(
  22. () => import(/* webpackChunkName: "AlertRuleListIndex" */ 'app/features/alerting/AlertRuleList')
  23. ),
  24. },
  25. {
  26. path: '/alerting/ng/list',
  27. component: SafeDynamicImport(
  28. () => import(/* webpackChunkName: "AlertRuleList" */ 'app/features/alerting/AlertRuleList')
  29. ),
  30. },
  31. {
  32. path: '/alerting/notifications',
  33. roles: config.unifiedAlertingEnabled ? () => ['Editor', 'Admin'] : undefined,
  34. component: SafeDynamicImport(
  35. () => import(/* webpackChunkName: "NotificationsListPage" */ 'app/features/alerting/NotificationsListPage')
  36. ),
  37. },
  38. {
  39. path: '/alerting/notifications/templates/new',
  40. roles: () => ['Editor', 'Admin'],
  41. component: SafeDynamicImport(
  42. () => import(/* webpackChunkName: "NotificationsListPage" */ 'app/features/alerting/NotificationsListPage')
  43. ),
  44. },
  45. {
  46. path: '/alerting/notifications/templates/:id/edit',
  47. roles: () => ['Editor', 'Admin'],
  48. component: SafeDynamicImport(
  49. () => import(/* webpackChunkName: "NotificationsListPage" */ 'app/features/alerting/NotificationsListPage')
  50. ),
  51. },
  52. {
  53. path: '/alerting/notifications/receivers/new',
  54. roles: () => ['Editor', 'Admin'],
  55. component: SafeDynamicImport(
  56. () => import(/* webpackChunkName: "NotificationsListPage" */ 'app/features/alerting/NotificationsListPage')
  57. ),
  58. },
  59. {
  60. path: '/alerting/notifications/receivers/:id/edit',
  61. roles: () => ['Editor', 'Admin'],
  62. component: SafeDynamicImport(
  63. () => import(/* webpackChunkName: "NotificationsListPage" */ 'app/features/alerting/NotificationsListPage')
  64. ),
  65. },
  66. {
  67. path: '/alerting/notifications/global-config',
  68. roles: () => ['Admin', 'Editor'],
  69. component: SafeDynamicImport(
  70. () => import(/* webpackChunkName: "NotificationsListPage" */ 'app/features/alerting/NotificationsListPage')
  71. ),
  72. },
  73. {
  74. path: '/alerting/notification/new',
  75. component: SafeDynamicImport(
  76. () => import(/* webpackChunkName: "NewNotificationChannel" */ 'app/features/alerting/NewNotificationChannelPage')
  77. ),
  78. },
  79. {
  80. path: '/alerting/notification/:id/edit',
  81. component: SafeDynamicImport(
  82. () => import(/* webpackChunkName: "EditNotificationChannel"*/ 'app/features/alerting/EditNotificationChannelPage')
  83. ),
  84. },
  85. ];
  86. const unifiedRoutes: RouteDescriptor[] = [
  87. ...commonRoutes,
  88. {
  89. path: '/alerting/list',
  90. roles: evaluateAccess(
  91. [AccessControlAction.AlertingRuleRead, AccessControlAction.AlertingRuleExternalRead],
  92. [OrgRole.Viewer, OrgRole.Editor, OrgRole.Admin]
  93. ),
  94. component: SafeDynamicImport(
  95. () => import(/* webpackChunkName: "AlertRuleListIndex" */ 'app/features/alerting/unified/RuleList')
  96. ),
  97. },
  98. {
  99. path: '/alerting/routes',
  100. roles: evaluateAccess(
  101. [AccessControlAction.AlertingNotificationsRead, AccessControlAction.AlertingNotificationsExternalRead],
  102. [OrgRole.Editor, OrgRole.Admin]
  103. ),
  104. component: SafeDynamicImport(
  105. () => import(/* webpackChunkName: "AlertAmRoutes" */ 'app/features/alerting/unified/AmRoutes')
  106. ),
  107. },
  108. {
  109. path: '/alerting/routes/mute-timing/new',
  110. roles: evaluateAccess(
  111. [AccessControlAction.AlertingNotificationsWrite, AccessControlAction.AlertingNotificationsExternalWrite],
  112. ['Editor', 'Admin']
  113. ),
  114. component: SafeDynamicImport(
  115. () => import(/* webpackChunkName: "MuteTimings" */ 'app/features/alerting/unified/MuteTimings')
  116. ),
  117. },
  118. {
  119. path: '/alerting/routes/mute-timing/edit',
  120. roles: evaluateAccess(
  121. [AccessControlAction.AlertingNotificationsWrite, AccessControlAction.AlertingNotificationsExternalWrite],
  122. ['Editor', 'Admin']
  123. ),
  124. component: SafeDynamicImport(
  125. () => import(/* webpackChunkName: "MuteTimings" */ 'app/features/alerting/unified/MuteTimings')
  126. ),
  127. },
  128. {
  129. path: '/alerting/silences',
  130. roles: evaluateAccess(
  131. [AccessControlAction.AlertingInstanceRead, AccessControlAction.AlertingInstancesExternalRead],
  132. ['Viewer', 'Editor', 'Admin']
  133. ),
  134. component: SafeDynamicImport(
  135. () => import(/* webpackChunkName: "AlertSilences" */ 'app/features/alerting/unified/Silences')
  136. ),
  137. },
  138. {
  139. path: '/alerting/silence/new',
  140. roles: evaluateAccess(
  141. [AccessControlAction.AlertingInstanceCreate, AccessControlAction.AlertingInstancesExternalWrite],
  142. ['Editor', 'Admin']
  143. ),
  144. component: SafeDynamicImport(
  145. () => import(/* webpackChunkName: "AlertSilences" */ 'app/features/alerting/unified/Silences')
  146. ),
  147. },
  148. {
  149. path: '/alerting/silence/:id/edit',
  150. roles: evaluateAccess(
  151. [AccessControlAction.AlertingInstanceUpdate, AccessControlAction.AlertingInstancesExternalWrite],
  152. ['Editor', 'Admin']
  153. ),
  154. component: SafeDynamicImport(
  155. () => import(/* webpackChunkName: "AlertSilences" */ 'app/features/alerting/unified/Silences')
  156. ),
  157. },
  158. {
  159. path: '/alerting/notifications',
  160. roles: evaluateAccess(
  161. [AccessControlAction.AlertingNotificationsRead, AccessControlAction.AlertingNotificationsExternalRead],
  162. ['Editor', 'Admin']
  163. ),
  164. component: SafeDynamicImport(
  165. () => import(/* webpackChunkName: "NotificationsListPage" */ 'app/features/alerting/unified/Receivers')
  166. ),
  167. },
  168. {
  169. path: '/alerting/notifications/templates/new',
  170. roles: evaluateAccess(
  171. [AccessControlAction.AlertingNotificationsWrite, AccessControlAction.AlertingNotificationsExternalWrite],
  172. ['Editor', 'Admin']
  173. ),
  174. component: SafeDynamicImport(
  175. () => import(/* webpackChunkName: "NotificationsListPage" */ 'app/features/alerting/unified/Receivers')
  176. ),
  177. },
  178. {
  179. path: '/alerting/notifications/templates/:id/edit',
  180. roles: evaluateAccess(
  181. [AccessControlAction.AlertingNotificationsWrite, AccessControlAction.AlertingNotificationsExternalWrite],
  182. ['Editor', 'Admin']
  183. ),
  184. component: SafeDynamicImport(
  185. () => import(/* webpackChunkName: "NotificationsListPage" */ 'app/features/alerting/unified/Receivers')
  186. ),
  187. },
  188. {
  189. path: '/alerting/notifications/receivers/new',
  190. roles: evaluateAccess(
  191. [AccessControlAction.AlertingNotificationsWrite, AccessControlAction.AlertingNotificationsExternalWrite],
  192. ['Editor', 'Admin']
  193. ),
  194. component: SafeDynamicImport(
  195. () => import(/* webpackChunkName: "NotificationsListPage" */ 'app/features/alerting/unified/Receivers')
  196. ),
  197. },
  198. {
  199. path: '/alerting/notifications/receivers/:id/edit',
  200. roles: evaluateAccess(
  201. [AccessControlAction.AlertingNotificationsWrite, AccessControlAction.AlertingNotificationsExternalWrite],
  202. ['Editor', 'Admin']
  203. ),
  204. component: SafeDynamicImport(
  205. () => import(/* webpackChunkName: "NotificationsListPage" */ 'app/features/alerting/unified/Receivers')
  206. ),
  207. },
  208. {
  209. path: '/alerting/notifications/global-config',
  210. roles: evaluateAccess(
  211. [AccessControlAction.AlertingNotificationsWrite, AccessControlAction.AlertingNotificationsExternalWrite],
  212. ['Editor', 'Admin']
  213. ),
  214. component: SafeDynamicImport(
  215. () => import(/* webpackChunkName: "NotificationsListPage" */ 'app/features/alerting/unified/Receivers')
  216. ),
  217. },
  218. {
  219. path: '/alerting/groups/',
  220. roles: evaluateAccess(
  221. [AccessControlAction.AlertingInstanceRead, AccessControlAction.AlertingInstancesExternalRead],
  222. [OrgRole.Viewer, OrgRole.Editor, OrgRole.Admin]
  223. ),
  224. component: SafeDynamicImport(
  225. () => import(/* webpackChunkName: "AlertGroups" */ 'app/features/alerting/unified/AlertGroups')
  226. ),
  227. },
  228. {
  229. path: '/alerting/new',
  230. pageClass: 'page-alerting',
  231. roles: evaluateAccess(
  232. [AccessControlAction.AlertingRuleCreate, AccessControlAction.AlertingRuleExternalWrite],
  233. [OrgRole.Viewer, OrgRole.Editor, OrgRole.Admin] // Needs to include viewer because there may be Viewers with Edit permissions in folders
  234. ),
  235. component: SafeDynamicImport(
  236. () => import(/* webpackChunkName: "AlertingRuleForm"*/ 'app/features/alerting/unified/RuleEditor')
  237. ),
  238. },
  239. {
  240. path: '/alerting/:id/edit',
  241. pageClass: 'page-alerting',
  242. roles: evaluateAccess(
  243. [AccessControlAction.AlertingRuleUpdate, AccessControlAction.AlertingRuleExternalWrite],
  244. [OrgRole.Viewer, OrgRole.Editor, OrgRole.Admin] // Needs to include viewer because there may be Viewers with Edit permissions in folders
  245. ),
  246. component: SafeDynamicImport(
  247. () => import(/* webpackChunkName: "AlertingRuleForm"*/ 'app/features/alerting/unified/RuleEditor')
  248. ),
  249. },
  250. {
  251. path: '/alerting/:sourceName/:id/view',
  252. pageClass: 'page-alerting',
  253. roles: evaluateAccess(
  254. [AccessControlAction.AlertingRuleRead, AccessControlAction.AlertingRuleExternalRead],
  255. [OrgRole.Viewer, OrgRole.Editor, OrgRole.Admin]
  256. ),
  257. component: SafeDynamicImport(
  258. () => import(/* webpackChunkName: "AlertingRule"*/ 'app/features/alerting/unified/RuleViewer')
  259. ),
  260. },
  261. {
  262. path: '/alerting/:sourceName/:name/find',
  263. pageClass: 'page-alerting',
  264. roles: evaluateAccess(
  265. [AccessControlAction.AlertingRuleRead, AccessControlAction.AlertingRuleExternalRead],
  266. [OrgRole.Viewer, OrgRole.Editor, OrgRole.Admin]
  267. ),
  268. component: SafeDynamicImport(
  269. () => import(/* webpackChunkName: "AlertingRedirectToRule"*/ 'app/features/alerting/unified/RedirectToRuleViewer')
  270. ),
  271. },
  272. {
  273. path: '/alerting/admin',
  274. roles: () => ['Admin'],
  275. component: SafeDynamicImport(
  276. () => import(/* webpackChunkName: "AlertingAdmin" */ 'app/features/alerting/unified/Admin')
  277. ),
  278. },
  279. ];
  280. export function getAlertingRoutes(cfg = config): RouteDescriptor[] {
  281. if (cfg.unifiedAlertingEnabled) {
  282. return unifiedRoutes;
  283. } else if (cfg.alertingEnabled) {
  284. return legacyRoutes;
  285. }
  286. const uniquePaths = uniq([...legacyRoutes, ...unifiedRoutes].map((route) => route.path));
  287. return uniquePaths.map((path) => ({
  288. path,
  289. component: SafeDynamicImport(
  290. () => import(/* webpackChunkName: "AlertingFeatureTogglePage"*/ 'app/features/alerting/FeatureTogglePage')
  291. ),
  292. }));
  293. }