From 24805685bce6e147af3f5f69d89771441fee7e60 Mon Sep 17 00:00:00 2001 From: Matthew Jacobson Date: Mon, 16 Jun 2025 11:05:27 -0400 Subject: [PATCH] Alerting: Fix contact points tab visibility when user can only create (#106735) Contact points tab was not being displayed for users with only `alert.notifications.receivers:create` and not `alert.notifications.receivers:read` --- .../contact-points/ContactPoints.test.tsx | 14 ++++++++++++++ .../components/contact-points/ContactPoints.tsx | 5 ++++- 2 files changed, 18 insertions(+), 1 deletion(-) 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 e3e4cc49391..1e6f0344865 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 @@ -154,6 +154,20 @@ describe('contact points', () => { expect(await screen.findByText(/create contact point/i)).toBeInTheDocument(); }); + + test('defaults to contact points tab if user has only read permission', async () => { + grantUserPermissions([AccessControlAction.AlertingReceiversRead]); + renderWithProvider(); + + expect(await screen.findByText(/create contact point/i)).toBeInTheDocument(); + }); + + test('defaults to contact points tab if user has only create permission', async () => { + grantUserPermissions([AccessControlAction.AlertingReceiversCreate]); + renderWithProvider(); + + expect(await screen.findByText(/create contact point/i)).toBeInTheDocument(); + }); }); describe('templates tab', () => { 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 0d37e6c9464..a9bbbf29845 100644 --- a/public/app/features/alerting/unified/components/contact-points/ContactPoints.tsx +++ b/public/app/features/alerting/unified/components/contact-points/ContactPoints.tsx @@ -196,9 +196,12 @@ const useTabQueryParam = (defaultTab: ActiveTab) => { export const ContactPointsPageContents = () => { const { selectedAlertmanager } = useAlertmanager(); - const [, showContactPointsTab] = useAlertmanagerAbility(AlertmanagerAction.ViewContactPoint); + const [, canViewContactPoints] = useAlertmanagerAbility(AlertmanagerAction.ViewContactPoint); + const [, canCreateContactPoints] = useAlertmanagerAbility(AlertmanagerAction.CreateContactPoint); const [, showTemplatesTab] = useAlertmanagerAbility(AlertmanagerAction.ViewNotificationTemplate); + const showContactPointsTab = canViewContactPoints || canCreateContactPoints; + // Depending on permissions, user may not have access to all tabs, // but we can default to picking the first one that they definitely _do_ have access to const defaultTab = [