Alerting: Implement correct RBAC checks for creating new notification templates (#83767)

This commit is contained in:
Gilles De Mey
2024-03-01 18:09:14 +01:00
committed by GitHub
parent fc10600ca5
commit 582fd53fac
2 changed files with 23 additions and 3 deletions
@@ -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();
});
});
});
@@ -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.
</Text>
<Spacer />
<LinkButton icon="plus" variant="primary" href="/alerting/notifications/templates/new">
Add notification template
</LinkButton>
{createTemplateSupported && (
<LinkButton
icon="plus"
variant="primary"
href="/alerting/notifications/templates/new"
disabled={!createTemplateAllowed}
>
Add notification template
</LinkButton>
)}
</Stack>
<NotificationTemplates />
</>