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`
This commit is contained in:
Matthew Jacobson
2025-06-16 11:05:27 -04:00
committed by GitHub
parent 8d27f12428
commit 24805685bc
2 changed files with 18 additions and 1 deletions
@@ -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(<ContactPointsPageContents />);
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(<ContactPointsPageContents />);
expect(await screen.findByText(/create contact point/i)).toBeInTheDocument();
});
});
describe('templates tab', () => {
@@ -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 = [