From 582fd53fac02e5fb73671a5acc6d2257a3062198 Mon Sep 17 00:00:00 2001 From: Gilles De Mey Date: Fri, 1 Mar 2024 18:09:14 +0100 Subject: [PATCH] Alerting: Implement correct RBAC checks for creating new notification templates (#83767) --- .../contact-points/ContactPoints.test.tsx | 10 ++++++++++ .../components/contact-points/ContactPoints.tsx | 16 +++++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/public/app/features/alerting/unified/components/contact-points/ContactPoints.test.tsx b/public/app/features/alerting/unified/components/contact-points/ContactPoints.test.tsx index fde20c0fadc..c6fd8c71ca7 100644 --- a/public/app/features/alerting/unified/components/contact-points/ContactPoints.test.tsx +++ b/public/app/features/alerting/unified/components/contact-points/ContactPoints.test.tsx @@ -127,6 +127,11 @@ describe('contact points', () => { const deleteButton = await screen.queryByRole('menuitem', { name: 'delete' }); expect(deleteButton).toBeDisabled(); } + + // check buttons in Notification Templates + const notificationTemplatesTab = screen.getByRole('tab', { name: 'Tab Notification Templates' }); + await userEvent.click(notificationTemplatesTab); + expect(screen.getByRole('link', { name: 'Add notification template' })).toHaveAttribute('aria-disabled', 'true'); }); it('should call delete when clicked and not disabled', async () => { @@ -326,6 +331,11 @@ describe('contact points', () => { const viewProvisioned = screen.getByRole('link', { name: 'view-action' }); expect(viewProvisioned).toBeInTheDocument(); expect(viewProvisioned).not.toBeDisabled(); + + // check buttons in Notification Templates + const notificationTemplatesTab = screen.getByRole('tab', { name: 'Tab Notification Templates' }); + await userEvent.click(notificationTemplatesTab); + expect(screen.queryByRole('link', { name: 'Add notification template' })).not.toBeInTheDocument(); }); }); }); diff --git a/public/app/features/alerting/unified/components/contact-points/ContactPoints.tsx b/public/app/features/alerting/unified/components/contact-points/ContactPoints.tsx index e8bb3de0935..e9ff52e3f0f 100644 --- a/public/app/features/alerting/unified/components/contact-points/ContactPoints.tsx +++ b/public/app/features/alerting/unified/components/contact-points/ContactPoints.tsx @@ -81,6 +81,9 @@ const ContactPoints = () => { const [exportContactPointsSupported, exportContactPointsAllowed] = useAlertmanagerAbility( AlertmanagerAction.ExportContactPoint ); + const [createTemplateSupported, createTemplateAllowed] = useAlertmanagerAbility( + AlertmanagerAction.CreateNotificationTemplate + ); const [DeleteModal, showDeleteModal] = useDeleteContactPointModal(deleteTrigger, updateAlertmanagerState.isLoading); const [ExportDrawer, showExportDrawer] = useExportContactPoint(); @@ -177,9 +180,16 @@ const ContactPoints = () => { Create notification templates to customize your notifications. - - Add notification template - + {createTemplateSupported && ( + + Add notification template + + )}